//----------------------------------- end of public functions --------------------------------------// void Start() { try { // get sensor data KinectManager kinectManager = KinectManager.Instance; KinectInterop.SensorData sensorData = kinectManager != null ? kinectManager.GetSensorData() : null; if (sensorData == null || sensorData.sensorInterface == null) { throw new Exception("Visual gesture tracking cannot be started, because the KinectManager is missing or not initialized."); } if (sensorData.sensorInterface.GetSensorPlatform() != KinectInterop.DepthSensorPlatform.KinectSDKv2) { throw new Exception("Visual gesture tracking is only supported by Kinect SDK v2"); } // ensure the needed dlls are in place and face tracking is available for this interface bool bNeedRestart = false; if (IsVisualGesturesAvailable(ref bNeedRestart)) { if (bNeedRestart) { KinectInterop.RestartLevel(gameObject, "VG"); return; } } else { throw new Exception("Visual gesture tracking is not supported!"); } // initialize visual gesture tracker if (!InitVisualGestures()) { throw new Exception("Visual gesture tracking could not be initialized."); } // try to automatically detect the available gesture listeners in the scene if (visualGestureListeners.Count == 0) { MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[]; foreach (MonoBehaviour monoScript in monoScripts) { if (typeof(VisualGestureListenerInterface).IsAssignableFrom(monoScript.GetType()) && monoScript.enabled) { visualGestureListeners.Add(monoScript); } } } // all set instance = this; isVisualGestureInitialized = true; } catch (DllNotFoundException ex) { Debug.LogError(ex.ToString()); if (debugText != null) debugText.GetComponent<GUIText>().text = "Please check the Kinect and FT-Library installations."; } catch (Exception ex) { Debug.LogError(ex.ToString()); if (debugText != null) debugText.GetComponent<GUIText>().text = ex.Message; } }
void OnDestroy() { if (isVisualGestureInitialized) { // finish visual gesture tracking FinishVisualGestures(); } isVisualGestureInitialized = false; instance = null; }