void Start() { int hr = 0; try { if (startKinectServer) { // start the Kinect-server app hr = StartKinectServer(); if (hr != 0) { throw new Exception("Kinect2Server not started"); } } // try to initialize the default Kinect2 sensor KinectWrapper.FrameSource dwFlags = KinectWrapper.FrameSource.TypeBody; if (computeColorMap) { dwFlags |= KinectWrapper.FrameSource.TypeColor; } if (computeUserMap) { dwFlags |= KinectWrapper.FrameSource.TypeDepth | KinectWrapper.FrameSource.TypeBodyIndex | KinectWrapper.FrameSource.TypeInfrared; } hr = KinectWrapper.InitDefaultKinectSensor(dwFlags, KinectWrapper.Constants.ColorImageWidth, KinectWrapper.Constants.ColorImageHeight); if (hr != 0) { throw new Exception("InitDefaultKinectSensor failed"); } // transform matrix - kinect to world kinectToWorld.SetTRS(new Vector3(0.0f, sensorHeight, 0.0f), Quaternion.identity, Vector3.one); } catch (Exception ex) { string message = ex.Message + " - " + KinectWrapper.GetSystemErrorMessage(hr); Debug.LogError(message); Debug.LogException(ex); if (calibrationText != null) { calibrationText.guiText.text = message; } return; } // init skeleton structures bodyFrame = new KinectWrapper.BodyFrame(true); // get the main camera rectangle Rect cameraRect = Camera.main.pixelRect; // calculate map width and height in percent, if needed if (MapsPercentWidth == 0f) { MapsPercentWidth = (KinectWrapper.Constants.DepthImageWidth / 2) / cameraRect.width; } if (MapsPercentHeight == 0f) { MapsPercentHeight = (KinectWrapper.Constants.DepthImageHeight / 2) / cameraRect.height; } if (computeUserMap) { // init user-depth structures //depthImage = new KinectWrapper.DepthBuffer(true); //bodyIndexImage = new KinectWrapper.BodyIndexBuffer(true); // Initialize depth & label map related stuff // usersMapSize = KinectWrapper.Constants.DepthImageWidth * KinectWrapper.Constants.DepthImageHeight; usersLblTex = new Texture2D(KinectWrapper.Constants.DepthImageWidth, KinectWrapper.Constants.DepthImageHeight); // usersMapColors = new Color32[usersMapSize]; // usersPrevState = new ushort[usersMapSize]; usersMapRect = new Rect(cameraRect.width - cameraRect.width * MapsPercentWidth, cameraRect.height, cameraRect.width * MapsPercentWidth, -cameraRect.height * MapsPercentHeight); // usersHistogramMap = new float[8192]; } if (computeColorMap) { // init color image structures //colorImage = new KinectWrapper.ColorBuffer(true); // Initialize color map related stuff usersClrTex = new Texture2D(KinectWrapper.Constants.ColorImageWidth, KinectWrapper.Constants.ColorImageHeight); usersClrRect = new Rect(cameraRect.width - cameraRect.width * MapsPercentWidth, cameraRect.height, cameraRect.width * MapsPercentWidth, -cameraRect.height * MapsPercentHeight); if (computeUserMap) { usersMapRect.x -= cameraRect.width * MapsPercentWidth; //usersClrTex.width / 2; } } // Initialize user list to contain all users. alUserIds = new List <Int64>(); dictUserIdToIndex = new Dictionary <Int64, int>(); kinectInitialized = true; instance = this; DontDestroyOnLoad(gameObject); // GUI Text. if (calibrationText != null) { calibrationText.guiText.text = "WAITING FOR USERS"; } Debug.Log("Waiting for users."); }