private void CheckForGestures(Int64 UserId)
{
if (!playerGesturesData.ContainsKey(UserId) || !gesturesTrackingAtTime.ContainsKey(UserId))
return;
// check for gestures
if (Time.realtimeSinceStartup >= gesturesTrackingAtTime[UserId])
{
// get joint positions and tracking
int iAllJointsCount = sensorData.jointCount;
bool[] playerJointsTracked = new bool[iAllJointsCount];
Vector3[] playerJointsPos = new Vector3[iAllJointsCount];
int[] aiNeededJointIndexes = KinectGestures.GetNeededJointIndexes(instance);
int iNeededJointsCount = aiNeededJointIndexes.Length;
for (int i = 0; i < iNeededJointsCount; i++)
{
int joint = aiNeededJointIndexes[i];
if (joint >= 0 && IsJointTracked(UserId, joint))
{
playerJointsTracked[joint] = true;
playerJointsPos[joint] = GetJointPosition(UserId, joint);
}
}
// check for gestures
List<KinectGestures.GestureData> gesturesData = playerGesturesData[UserId];
int listGestureSize = gesturesData.Count;
float timestampNow = Time.realtimeSinceStartup;
string sDebugGestures = string.Empty; // "Tracked Gestures:\n";
for (int g = 0; g < listGestureSize; g++)
{
KinectGestures.GestureData gestureData = gesturesData[g];
if ((timestampNow >= gestureData.startTrackingAtTime) &&
!IsConflictingGestureInProgress(gestureData, ref gesturesData))
{
KinectGestures.CheckForGesture(UserId, ref gestureData, Time.realtimeSinceStartup,
ref playerJointsPos, ref playerJointsTracked);
gesturesData[g] = gestureData;
if (gestureData.complete)
{
gesturesTrackingAtTime[UserId] = timestampNow + minTimeBetweenGestures;
}
if (UserId == liPrimaryUserId)
{
sDebugGestures += string.Format("{0} - state: {1}, time: {2:F1}, progress: {3}%\n",
gestureData.gesture, gestureData.state,
gestureData.timestamp,
(int)(gestureData.progress * 100 + 0.5f));
}
}
}
playerGesturesData[UserId] = gesturesData;
if (gesturesDebugText && (UserId == liPrimaryUserId))
{
for (int i = 0; i < iNeededJointsCount; i++)
{
int joint = aiNeededJointIndexes[i];
sDebugGestures += string.Format("\n {0}: {1}", (KinectInterop.JointType)joint,
playerJointsTracked[joint] ? playerJointsPos[joint].ToString() : "");
}
gesturesDebugText.GetComponent<GUIText>().text = sDebugGestures;
}
}
}