SettingRegionTrigger.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. namespace NRKernal.Experimental.StreammingCast
  4. {
  5. [RequireComponent(typeof(Collider))]
  6. public class SettingRegionTrigger : MonoBehaviour
  7. {
  8. public UnityEvent onPointerEnter;
  9. public UnityEvent onPointerOut;
  10. private Collider m_TriggerRegion;
  11. private Collider m_CurrentHover;
  12. private Collider currentHover
  13. {
  14. get
  15. {
  16. return m_CurrentHover;
  17. }
  18. set
  19. {
  20. if (m_CurrentHover != value)
  21. {
  22. if (value == m_TriggerRegion)
  23. {
  24. OnPointerEnter();
  25. }
  26. else
  27. {
  28. OnPointerExit();
  29. }
  30. }
  31. m_CurrentHover = value;
  32. }
  33. }
  34. private Transform laserAnchor
  35. {
  36. get
  37. {
  38. return NRInput.AnchorsHelper.GetAnchor(NRInput.RaycastMode == RaycastModeEnum.Gaze ?
  39. ControllerAnchorEnum.GazePoseTrackerAnchor : ControllerAnchorEnum.RightLaserAnchor);
  40. }
  41. }
  42. void Start()
  43. {
  44. m_TriggerRegion = gameObject.GetComponent<Collider>();
  45. }
  46. void Update()
  47. {
  48. RaycastHit hitResult;
  49. Physics.Raycast(new Ray(laserAnchor.position, laserAnchor.forward), out hitResult, 10);
  50. currentHover = hitResult.collider;
  51. }
  52. public void OnPointerEnter()
  53. {
  54. onPointerEnter?.Invoke();
  55. }
  56. public void OnPointerExit()
  57. {
  58. onPointerOut?.Invoke();
  59. }
  60. }
  61. }