ObjectsInteractionState.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Ximmerse.XR.InputSystems.GazeAndGestureInteraction
  6. {
  7. /// <summary>
  8. /// Gaze and hand interaction system manages how XR user interacts world objects withe eye reticle and hand gesture.
  9. /// </summary>
  10. public partial class GazeAndHandInteractionSystem
  11. {
  12. /// <summary>
  13. /// UI objects interaction state.
  14. /// </summary>
  15. internal class ObjectsInteractionState : I_InteractionState
  16. {
  17. public bool IsEnabled
  18. {
  19. get; private set;
  20. }
  21. Transform mainCam;
  22. GameObject palm;
  23. LockedGameObjectInfo lockInfo = new LockedGameObjectInfo();
  24. public void OnEnable()
  25. {
  26. }
  27. public void OnDisable()
  28. {
  29. }
  30. public void OnReticleEnter()
  31. {
  32. }
  33. public void Tick()
  34. {
  35. if (!mainCam)
  36. {
  37. mainCam = Camera.main.transform;
  38. }
  39. if (palm==null)
  40. {
  41. VirtualHandRenderer hand = FindObjectOfType<VirtualHandRenderer>();
  42. palm = hand.palm;
  43. }
  44. if (HandTracking.HandTrackingInfo.IsTracking == false)
  45. {
  46. //Clear lock info:
  47. if (lockInfo.lockType != LockedGameObjectInfo.LockType.None && (Time.realtimeSinceStartup - lockInfo.lockTime) >= 0.333f)
  48. {
  49. lockInfo.lockType = LockedGameObjectInfo.LockType.None;
  50. lockInfo.lockedReference = null;
  51. Debug.Log("Slider UI : Clear 1 : " + HandTracking.HandTrackingInfo.IsTracking);
  52. }
  53. return;
  54. }
  55. var isHoveringUI = GazeAndHandInteractionSystem.instance.eyeReticle.CurrentInteractingTarget.isUI;
  56. bool isclosepinch = HandTracking.HandTrackingInfo.NativeGestureType == (int)TouchlessA3D.GestureType.CLOSED_PINCH;
  57. bool isclosehand = HandTracking.HandTrackingInfo.gestureFistOpenHand == GestureType_Fist_OpenHand.Fist;
  58. bool isPinchGesture = false;
  59. if (isclosepinch || isclosehand)
  60. {
  61. isPinchGesture = true;
  62. }
  63. else
  64. {
  65. isPinchGesture = false;
  66. }
  67. //Debug.Log("miao0" + GazeAndHandInteractionSystem.instance.eyeReticle.CurrentInteractingTarget.target.name);
  68. //var isPinchGesture = HandTracking.HandTrackingInfo.NativeGestureType == (byte)(TouchlessA3D.GestureType.CLOSED_PINCH);
  69. //设置 lock target : slider UI:
  70. if (isPinchGesture)
  71. {
  72. }
  73. }
  74. private void MoveSliderUI(GameObject target)
  75. {
  76. //Debug.Log("miao:" + target.name);
  77. target.transform.parent = palm.transform;
  78. //Debug.Log("miao:target " + target.transform.position);
  79. }
  80. public void OnReticleExit()
  81. {
  82. }
  83. }
  84. }
  85. }