using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIFollow : MonoBehaviour { public ScenesManager.SceneType type; public float dis; public float angle; public Vector3 pos; private bool state = true; private void OnEnable() { state = true; } void Start() { // pos = new Vector3(OpenXRCamera.Instance.transform.position.x, 1.5f,OpenXRCamera.Instance.head.transform.position.z + (OpenXRCamera.Instance.transform.forward * 1.5f).z); //pos = HeadBtnManager.Instance.transform.position; //Show(pos); } private void Awake() { HeadBtnManager.Instance.uiFollow = this; } // Update is called once per frame void Update() { if(state) { dis = Vector3.Distance(new Vector3(OpenXRCamera.Instance.head.transform.position.x, 0, OpenXRCamera.Instance.head.transform.position.z), new Vector3(transform.position.x, 0, transform.position.z)); angle = Vector3.Angle(OpenXRCamera.Instance.head.GetComponent().transform.forward, transform.position - OpenXRCamera.Instance.head.transform.position); // Debug.Log("UIFollow DIS " + dis + " OpenXRCamera "+OpenXRCamera.Instance.transform.position+" This "+transform.position); if (dis > 3 || (dis > 2.5f && angle > 100)) { Hide(); // } } } // 隐藏 public void Hide() { state = false; // gameObject.SetActive(false); transform.position = new Vector3(0,0,10000); HeadBtnManager.Instance.ShowResetBtn(type, this); } // 显示 public void Show( Vector3 pos ) { if (type == ScenesManager.SceneType.ShowRTCHistory) pos -= new Vector3(0, 0.5f, 0); transform.position = pos; transform.eulerAngles = new Vector3(0,OpenXRCamera.Instance.head.transform.eulerAngles.y, 0); // gameObject.SetActive(true); if (type == ScenesManager.SceneType.ShowRTC) ShowRoom.Instance.ResetPosition(); state = true; } }