HandSelector.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using UnityEngine;
  3. using Rokid.UXR.Utility;
  4. namespace Rokid.UXR.Interaction
  5. {
  6. /// <summary>
  7. /// Hand Selector
  8. /// </summary>
  9. public class HandSelector : MonoBehaviour, ISelector
  10. {
  11. [SerializeField]
  12. private HandType handType;
  13. public event Action WhenSelected;
  14. public event Action WhenUnselected;
  15. private bool dragging = false;
  16. private void Start()
  17. {
  18. InteractorStateChange.OnHandDragStatusChanged += OnHandDragStatusChanged;
  19. }
  20. private void OnDestroy()
  21. {
  22. InteractorStateChange.OnHandDragStatusChanged -= OnHandDragStatusChanged;
  23. }
  24. private void OnHandDragStatusChanged(HandType hand, bool dragging)
  25. {
  26. if (hand == handType)
  27. {
  28. if (dragging)
  29. this.dragging = true;
  30. }
  31. }
  32. void Update()
  33. {
  34. if (dragging)
  35. {
  36. if (HandUtils.CanReleseHandDrag(handType))
  37. {
  38. WhenUnselected?.Invoke();
  39. dragging = false;
  40. }
  41. }
  42. else
  43. {
  44. if (GesEventInput.Instance.GetHandDown(handType, true) || GesEventInput.Instance.GetHandDown(handType, false))
  45. {
  46. WhenSelected?.Invoke();
  47. }
  48. if (GesEventInput.Instance.GetHandUp(handType, true) || GesEventInput.Instance.GetHandUp(handType, false))
  49. {
  50. WhenUnselected?.Invoke();
  51. }
  52. }
  53. }
  54. }
  55. }