在Unity的AssetStore官方商店下载Kinect v2 Examples案例包,参考KinectDemos/GestureDemo这个文件夹下的例子。
自定义一个类,实现KinectGestures.GestureListenerInterface接口。参考案例中的CubeGestureListener中的用法。下面演示监听SwipeLeft向左划,SwipeRight向右划,SwipeUp向上划的手势Gesture。其中包含了一些修改界面UI显示当前手势状态等功能,如不需要可以去掉(主要是用来调试)。
using UnityEngine; using System.Collections; using System; //using Windows.Kinect; public class PeopleGestureListener : MonoBehaviour, KinectGestures.GestureListenerInterface { [Tooltip("Index of the player, tracked by this component. 0 means the 1st player, 1 - the 2nd one, 2 - the 3rd one, etc.")] public int playerIndex = 0; [Tooltip("GUI-Text to display gesture-listener messages and gesture information.")] public GUIText gestureInfo; // singleton instance of the class private static PeopleGestureListener instance = null; // internal variables to track if progress message has been displayed private bool progressDisplayed; private float progressGestureTime; // whether the needed gesture has been detected or not private bool swipeLeft; private bool swipeRight; private bool swipeUp; /// <summary> /// Gets the singleton CubeGestureListener instance. /// </summary> /// <value>The CubeGestureListener instance.</value> public static PeopleGestureListener Instance { get { return instance; } } /// <summary> /// Determines whether swipe left is detected. /// </summary> /// <returns><c>true</c> if swipe left is detected; otherwise, <c>false</c>.</returns> public bool IsSwipeLeft() { if(swipeLeft) { swipeLeft = false; return true; } return false