NxrUIPointer.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. namespace Nxr.Internal
  4. {
  5. public class NxrUIPointer : MonoBehaviour
  6. {
  7. [HideInInspector]
  8. public PointerEventData pointerEventData;
  9. protected EventSystem cachedEventSystem;
  10. protected GazeInputModule cachedVRInputModule;
  11. protected virtual void OnEnable()
  12. {
  13. ConfigureEventSystem();
  14. }
  15. protected virtual void OnDisable()
  16. {
  17. GazeInputModule.RemovePoint(this);
  18. }
  19. public bool IsShow()
  20. {
  21. NxrReticle mNxrReticle = gameObject.GetComponent<NxrReticle>();
  22. if(mNxrReticle != null)
  23. {
  24. return mNxrReticle.IsShowing();
  25. }
  26. return true;
  27. }
  28. protected virtual void ConfigureEventSystem()
  29. {
  30. if (!cachedEventSystem)
  31. {
  32. cachedEventSystem = FindObjectOfType<EventSystem>();
  33. }
  34. if (!cachedVRInputModule)
  35. {
  36. cachedVRInputModule = cachedEventSystem.GetComponent<GazeInputModule>();
  37. }
  38. if (cachedEventSystem && cachedVRInputModule)
  39. {
  40. if (pointerEventData == null)
  41. {
  42. pointerEventData = new PointerEventData(cachedEventSystem);
  43. }
  44. }
  45. GazeInputModule.AddPoint(this);
  46. }
  47. }
  48. }