Kinect.KinectManager.RemoveUser C# (CSharp) Method

RemoveUser() private method

private RemoveUser ( Int64 userId ) : void
userId Int64
return void
        private void RemoveUser(Int64 userId)
        {
            int uidIndex = alUserIds.IndexOf(userId);
            Debug.LogWarning("Removing user " + uidIndex + ", ID: " + userId + ", Body: " + dictUserIdToIndex[userId]);

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

                //if(avatar && avatar.playerIndex >= uidIndex && avatar.playerIndex < alUserIds.Count)
                if (avatar && avatar.playerId == userId)
                {
                    avatar.ResetToInitialPosition();
                    avatar.playerId = 0;
                }
            }

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

            // clear gestures list for this user
            ClearGestures(userId);

            // clear calibration data for this user
            if (playerCalibrationData.ContainsKey(userId))
            {
                playerCalibrationData.Remove(userId);
            }

            // clean up the outdated calibration data in the data dictionary
            List<Int64> alCalDataKeys = new List<Int64>(playerCalibrationData.Keys);

            foreach (Int64 calUserID in alCalDataKeys)
            {
                KinectGestures.GestureData gestureData = playerCalibrationData[calUserID];

                if ((gestureData.timestamp + 60f) < Time.realtimeSinceStartup)
                {
                    playerCalibrationData.Remove(calUserID);
                }
            }

            alCalDataKeys.Clear();

            // remove from global users list
            dictUserIdToIndex.Remove(userId);
            alUserIds.Remove(userId);

            if (liPrimaryUserId == userId)
            {
                if (alUserIds.Count > 0)
                {
                    if (SetPrimaryUserID(alUserIds[0]))
                    {
                        Debug.LogWarning("New Primary User ID: " + GetPrimaryUserID());
                        if(avatarControllers.Count > 0)
                            avatarControllers[0].playerId = GetPrimaryUserID();
                    }
                    else
                        liPrimaryUserId = 0;
                    //dictUserIdToIndex[liPrimaryUserId] = 0;
                }
                else
                {
                    liPrimaryUserId = 0;
                }
            }

            //		for(int i = 0; i < avatarControllers.Count; i++)
            //		{
            //			AvatarController avatar = avatarControllers[i];
            //			
            //			if(avatar && avatar.playerIndex >= uidIndex && avatar.playerIndex < alUserIds.Count)
            //			{
            //				avatar.SuccessfulCalibration(alUserIds[avatar.playerIndex]);
            //			}
            //		}

            if (liPrimaryUserId == 0)
            {
                Debug.Log("Waiting for users.");

                if (calibrationText != null)
                {
                    calibrationText.GetComponent<GUIText>().text = "WAITING FOR USERS";
                }
            }
        }
KinectManager