Kinect.KinectManager.CalibrateUser C# (CSharp) Method

CalibrateUser() private method

private CalibrateUser ( Int64 userId, int bodyIndex ) : void
userId Int64
bodyIndex int
return void
        private void CalibrateUser(Int64 userId, int bodyIndex)
        {
            if (!alUserIds.Contains(userId))
            {
                if (CheckForCalibrationPose(userId, bodyIndex, playerCalibrationPose))
                {
                    int uidIndex = alUserIds.Count;

                    // check if to add or insert the new id
                    bool bInsertId = false;
                    for (int i = 0; i < avatarControllers.Count; i++)
                    {
                        AvatarController avatar = avatarControllers[i];

                        if (avatar && avatar.playerId != 0)
                        {
                            for (int u = 0; u < alUserIds.Count; u++)
                            {
                                if (avatar.playerId == alUserIds[u] && avatar.playerIndex > u)
                                {
                                    bInsertId = true;
                                    uidIndex = 0;
                                    break;
                                }
                            }

                            if (bInsertId)
                                break;
                        }
                    }

                    Debug.Log("Adding user " + uidIndex + ", ID: " + userId + ", Body: " + bodyIndex);
                    dictUserIdToIndex[userId] = bodyIndex;

                    if (!bInsertId)
                        alUserIds.Add(userId);
                    else
                        alUserIds.Insert(uidIndex, userId);

                    if (liPrimaryUserId == 0)
                    {
                        liPrimaryUserId = userId;

                        if (liPrimaryUserId != 0)
                        {
                            if (calibrationText != null && calibrationText.GetComponent<GUIText>().text != "")
                            {
                                calibrationText.GetComponent<GUIText>().text = "";
                            }
                        }
                    }

                    for (int i = 0; i < avatarControllers.Count; i++)
                    {
                        AvatarController avatar = avatarControllers[i];

                        //if(avatar && avatar.playerIndex == uidIndex)
                        if (avatar && avatar.playerIndex == uidIndex && avatar.playerId == 0)
                        {
                            avatar.playerId = userId;
                            avatar.SuccessfulCalibration(userId);
                        }
                    }

                    // add the gestures to detect, if any
                    foreach (KinectGestures.Gestures gesture in playerCommonGestures)
                    {
                        DetectGesture(userId, gesture);
                    }

                    // notify the gesture listeners about the new user
                    foreach (KinectGestures.GestureListenerInterface listener in gestureListeners)
                    {
                        if (listener != null)
                        {
                            listener.UserDetected(userId, 0);
                        }
                    }

                    ResetFilters();
                }
            }
        }
KinectManager