void Start() { CalibrationText = GameObject.Find("CalibrationText"); try { // Make sure we have the Open NI file. uint rc = KinectWrapper.Init(new StringBuilder("OpenNI.xml")); if (rc != 0) { throw new Exception(String.Format("Error initing OpenNI: {0}", Marshal.PtrToStringAnsi(KinectWrapper.GetStatusString(rc)))); } // Initialize depth & label map related stuff usersMapSize = KinectWrapper.GetDepthWidth() * KinectWrapper.GetDepthHeight(); usersLblTex = new Texture2D(KinectWrapper.GetDepthWidth(), KinectWrapper.GetDepthHeight()); usersMapColors = new Color[usersMapSize]; usersMapRect = new Rect(Screen.width - usersLblTex.width / 2, Screen.height - usersLblTex.height / 2, usersLblTex.width / 2, usersLblTex.height / 2); usersLabelMap = new short[usersMapSize]; usersDepthMap = new short[usersMapSize]; usersHistogramMap = new float[5000]; // Initialize user list to contain ALL users. allUsers = new List <uint>(); // Initialize user callbacks. NewUser = new KinectWrapper.UserDelegate(OnNewUser); CalibrationStarted = new KinectWrapper.UserDelegate(OnCalibrationStarted); CalibrationFailed = new KinectWrapper.UserDelegate(OnCalibrationFailed); CalibrationSuccess = new KinectWrapper.UserDelegate(OnCalibrationSuccess); UserLost = new KinectWrapper.UserDelegate(OnUserLost); // Pull the AvatarController from each of the players Avatars. Player1Controllers = new List <AvatarController>(); Player2Controllers = new List <AvatarController>(); // Add each of the avatars' controllers into a list for each player. foreach (GameObject avatar in Player1Avatars) { Player1Controllers.Add(avatar.GetComponent <AvatarController>()); } foreach (GameObject avatar in Player2Avatars) { Player2Controllers.Add(avatar.GetComponent <AvatarController>()); } // GUI Text. if (CalibrationText != null) { CalibrationText.guiText.text = "MATCH POSE TO CALIBRATE"; } // Start looking for users. KinectWrapper.StartLookingForUsers(NewUser, CalibrationStarted, CalibrationFailed, CalibrationSuccess, UserLost); Debug.Log("Waiting for users to calibrate"); // Set the default smoothing for the Kinect. KinectWrapper.SetSkeletonSmoothing(0.7); instance = this; OpenNIInitialized = true; } catch (DllNotFoundException ex) { Debug.LogError(ex.ToString()); if (CalibrationText != null) { CalibrationText.guiText.text = "Please check the OpenNI and NITE installations."; } } catch (Exception ex) { Debug.LogError(ex.ToString()); if (CalibrationText != null) { CalibrationText.guiText.text = ex.Message; } } }