1
This commit is contained in:
37
Unity/Scripts/Components/WorldToScreenPoint.cs
Normal file
37
Unity/Scripts/Components/WorldToScreenPoint.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit
|
||||
{
|
||||
public class WorldToScreenPoint : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] Transform root;
|
||||
[SerializeField] Vector3 offset;
|
||||
[SerializeField] float activeDistance;
|
||||
[Header(Constant.Header.Events)]
|
||||
[SerializeField] private UnityEvent<bool> setHeaderEnabled;
|
||||
[SerializeField] private UnityEvent<Vector3> setHeaderPosition;
|
||||
Transform cameraTrans;
|
||||
void Start()
|
||||
{
|
||||
if (Camera.main != null) cameraTrans = Camera.main.transform;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
var position = root.position + root.rotation * offset;
|
||||
|
||||
setHeaderPosition.Invoke(position);
|
||||
|
||||
if (activeDistance is not (0 or -1))
|
||||
{
|
||||
var distance = Vector3.Distance(position, cameraTrans.position);
|
||||
var _enabled = distance < activeDistance;
|
||||
setHeaderEnabled.Invoke(_enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user