UIFollow.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UIFollow : MonoBehaviour
  5. {
  6. public ScenesManager.SceneType type;
  7. public float dis;
  8. public float angle;
  9. public Vector3 pos;
  10. private bool state = true;
  11. private void OnEnable()
  12. {
  13. state = true;
  14. }
  15. void Start()
  16. {
  17. // pos = new Vector3(OpenXRCamera.Instance.transform.position.x, 1.5f,OpenXRCamera.Instance.head.transform.position.z + (OpenXRCamera.Instance.transform.forward * 1.5f).z);
  18. //pos = HeadBtnManager.Instance.transform.position;
  19. //Show(pos);
  20. }
  21. private void Awake()
  22. {
  23. HeadBtnManager.Instance.uiFollow = this;
  24. }
  25. // Update is called once per frame
  26. void Update()
  27. {
  28. if(state)
  29. {
  30. 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));
  31. angle = Vector3.Angle(OpenXRCamera.Instance.head.GetComponent<Camera>().transform.forward, transform.position - OpenXRCamera.Instance.head.transform.position);
  32. // Debug.Log("UIFollow DIS " + dis + " OpenXRCamera "+OpenXRCamera.Instance.transform.position+" This "+transform.position);
  33. if (dis > 3 || (dis > 2.5f && angle > 100))
  34. {
  35. Hide();
  36. //
  37. }
  38. }
  39. }
  40. // 隐藏
  41. public void Hide()
  42. {
  43. state = false;
  44. // gameObject.SetActive(false);
  45. transform.position = new Vector3(0,0,10000);
  46. HeadBtnManager.Instance.ShowResetBtn(type, this);
  47. }
  48. // 显示
  49. public void Show( Vector3 pos )
  50. {
  51. if (type == ScenesManager.SceneType.ShowRTCHistory)
  52. pos -= new Vector3(0, 0.5f, 0);
  53. transform.position = pos;
  54. transform.eulerAngles = new Vector3(0,OpenXRCamera.Instance.head.transform.eulerAngles.y, 0);
  55. // gameObject.SetActive(true);
  56. if (type == ScenesManager.SceneType.ShowRTC)
  57. ShowRoom.Instance.ResetPosition();
  58. state = true;
  59. }
  60. }