1
0

AzureKinectDriver.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using com.rfilkov.kinect;
  4. using UnityEngine;
  5. public class AzureKinectDriver : MonoBehaviour, GestureListenerInterface
  6. {
  7. public static AzureKinectDriver Instance;
  8. public int playerIndex = 0;
  9. public List<GestureType> detectGestures = new List<GestureType>();
  10. // ==================================================
  11. private void Awake() => Instance = this;
  12. private void Start() => Init();
  13. // ==================================================
  14. private void Init()
  15. {
  16. // StartCoroutine(nameof(KinectAwakeLoop));
  17. return;
  18. }
  19. private IEnumerator KinectAwakeLoop()
  20. {
  21. while (true)
  22. {
  23. yield return new WaitForSeconds(60f);
  24. KinectManager.Instance.StartDepthSensors();
  25. }
  26. }
  27. // ==================================================
  28. /// <summary>
  29. /// 检测到用户
  30. /// </summary>
  31. /// <param name="userID"></param>
  32. /// <param name="userIndex"></param>
  33. public void UserDetected(ulong userID, int userIndex)
  34. {
  35. if (userIndex == playerIndex)
  36. {
  37. Debug.Log($"[AKD] Target user {playerIndex} Detected.");
  38. KinectGestureManager gestureManager = KinectManager.Instance.gestureManager;
  39. foreach (GestureType gesture in detectGestures)
  40. {
  41. gestureManager.DetectGesture(userID, gesture); // 添加监听的动作
  42. }
  43. }
  44. else
  45. {
  46. Debug.Log($"[AKD] Non-target user {userID} Detected.");
  47. }
  48. // gestureManager.DetectGesture(userID, GestureType.SwipeLeft);
  49. // gestureManager.DetectGesture(userID, GestureType.SwipeRight);
  50. // gestureManager.DetectGesture(userID, GestureType.RaiseRightHand);
  51. // gestureManager.DetectGesture(userID, GestureType.RaiseLeftHand);
  52. return;
  53. }
  54. /// <summary>
  55. /// 用户丢失
  56. /// </summary>
  57. /// <param name="userID"></param>
  58. /// <param name="userIndex"></param>
  59. public void UserLost(ulong userID, int userIndex)
  60. {
  61. if (userIndex != playerIndex)
  62. {
  63. return;
  64. }
  65. Debug.Log($"[AKD] User {userID} lost.");
  66. return;
  67. }
  68. public void GestureInProgress(ulong userId, int userIndex, GestureType gesture, float progress, KinectInterop.JointType joint, Vector3 screenPos)
  69. {
  70. return;
  71. }
  72. public bool GestureCompleted(ulong userId, int userIndex, GestureType gesture, KinectInterop.JointType joint, Vector3 screenPos)
  73. {
  74. if (userIndex != playerIndex) // 检测到非指定用户
  75. {
  76. return false;
  77. }
  78. Debug.Log($"[AKD] Gesture <color=white>{gesture}</color> detected.");
  79. switch (gesture)
  80. {
  81. default: break;
  82. case GestureType.None:
  83. break;
  84. // case GestureType.SwipeUp:
  85. // break;
  86. case GestureType.SwipeLeft:
  87. break;
  88. case GestureType.SwipeRight:
  89. break;
  90. }
  91. return true;
  92. }
  93. public bool GestureCancelled(ulong userId, int userIndex, GestureType gesture, KinectInterop.JointType joint)
  94. {
  95. return true;
  96. }
  97. }