GesGripRayCaster.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Rokid.UXR.Utility;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. namespace Rokid.UXR.Interaction
  5. {
  6. public class GesGripRayCaster : BaseRayCaster
  7. {
  8. [SerializeField]
  9. private HandType hand;
  10. private Vector3 oriHandPos;
  11. private GestureGripInput physicalInput;
  12. protected override void Init()
  13. {
  14. base.Init();
  15. if (inputOverride == null)
  16. {
  17. inputOverride = GetComponent<GestureGripInput>();
  18. if (inputOverride == null)
  19. {
  20. inputOverride = gameObject.AddComponent<GestureGripInput>();
  21. }
  22. }
  23. physicalInput = GetComponent<GestureGripInput>();
  24. physicalInput.SetHandType(hand);
  25. pointerEnter = "OnGesGripPointerEnter";
  26. pointerExit = "OnGesGripPointerExit";
  27. pointerHover = "OnGesGripPointerHover";
  28. pointerClick = "OnGesGripPointerClick";
  29. dragBegin = "OnGesGripBeginDrag";
  30. drag = "OnGesGripDrag";
  31. dragEnd = "OnGesGripEndDrag";
  32. }
  33. protected override bool ProcessDrag(Ray ray)
  34. {
  35. var delta = GesEventInput.Instance.GetHandDeltaPos(hand);
  36. m_SelectedObj.SendMessageUpwards(drag, delta, SendMessageOptions.DontRequireReceiver);
  37. return true;
  38. }
  39. protected override Vector3 CalDragDelta()
  40. {
  41. return oriHandPos - physicalInput.GetGesPosition();
  42. }
  43. protected override void OnFirstSelect()
  44. {
  45. oriHandPos = physicalInput.GetGesPosition();
  46. }
  47. protected override Camera GetEventCamera()
  48. {
  49. return MainCameraCache.mainCamera.GetComponent<Camera>();
  50. }
  51. protected override void ProcessNothingDownEvent(PointerEventData eventData)
  52. {
  53. // base.ProcessNothingDownEvent(eventData);
  54. }
  55. protected override void ProcessNothingUpEvent(PointerEventData eventData)
  56. {
  57. // base.ProcessNothingUpEvent(eventData);
  58. }
  59. }
  60. }