GesRayCaster.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using UnityEngine;
  2. using Rokid.UXR.Utility;
  3. using Rokid.UXR.Interaction.ThirdParty;
  4. namespace Rokid.UXR.Interaction
  5. {
  6. public class GesRayCaster : BaseRayCaster
  7. {
  8. [SerializeField]
  9. private HandType hand;
  10. private GestureInput gesInput;
  11. private ManipulationMoveLogic moveLogic;
  12. private string dragToTarget = "OnGesDragToTarget";
  13. protected override void Start()
  14. {
  15. base.Start();
  16. if (base.rayInteractor == null)
  17. base.rayInteractor = GetComponent<RayInteractor>();
  18. moveLogic = new ManipulationMoveLogic();
  19. }
  20. protected override void Init()
  21. {
  22. base.Init();
  23. if (inputOverride == null)
  24. {
  25. inputOverride = GetComponent<GestureInput>();
  26. if (inputOverride == null)
  27. {
  28. inputOverride = gameObject.AddComponent<GestureInput>();
  29. }
  30. }
  31. gesInput = GetComponent<GestureInput>();
  32. gesInput.SetHandType(hand);
  33. pointerEnter = "OnGesPointerEnter";
  34. pointerExit = "OnGesPointerExit";
  35. pointerHover = "OnGesPointerHover";
  36. pointerClick = "OnGesPointerClick";
  37. dragBegin = "OnGesBeginDrag";
  38. drag = "OnGesDrag";
  39. dragEnd = "OnGesEndDrag";
  40. }
  41. protected override bool CanDrag(Vector3 delta)
  42. {
  43. return !dragging && (m_SelectedObj.GetComponent<IGesBeginDrag>() != null || m_SelectedObj.GetComponentInParent<IGesBeginDrag>() != null) && Vector3.SqrMagnitude(delta) >= m_DragThreshold * m_DragThreshold;
  44. }
  45. protected override void OnBeginDrag()
  46. {
  47. base.OnBeginDrag();
  48. moveLogic.Setup(transform.GetPose(), oriHitPoint, m_SelectedObj.transform.GetPose(), result.gameObject.transform.localScale);
  49. }
  50. protected override bool ProcessDrag(Ray ray)
  51. {
  52. var targetHitPosition = moveLogic.UpdateTransform(transform.GetPose(), m_SelectedObj.transform, true, false);
  53. var delta = targetHitPosition - oriHitPoint;
  54. m_SelectedObj.SendMessageUpwards(drag, delta, SendMessageOptions.DontRequireReceiver);
  55. m_SelectedObj.SendMessageUpwards(dragToTarget, targetHitPosition, SendMessageOptions.DontRequireReceiver);
  56. oriHitPoint = targetHitPosition;
  57. return true;
  58. }
  59. protected override bool DragRelease()
  60. {
  61. return HandUtils.CanReleseHandDrag(hand);
  62. }
  63. }
  64. }