void Awake() { try { // bool bOnceRestarted = false; // if(System.IO.File.Exists("SCrestart.txt")) // { // bOnceRestarted = true; // // try // { // System.IO.File.Delete("SCrestart.txt"); // } // catch(Exception ex) // { // Debug.LogError("Error deleting SCrestart.txt"); // Debug.LogError(ex.ToString()); // } // } // init the available sensor interfaces sensorInterface = new Kinect2Interface(); bool bNeedRestart = false; if (sensorInterface.InitSensorInterface(true, ref bNeedRestart)) { if (bNeedRestart) { System.IO.File.WriteAllText("SCrestart.txt", "Restarting level..."); KinectInterop.RestartLevel(gameObject, "SC"); return; } else { // check if a sensor is connected bSensorAvailable = sensorInterface.GetSensorsCount() > 0; if (infoText != null) { infoText.text = bSensorAvailable ? "Sensor is connected." : "No sensor is connected."; } } } else { sensorInterface.FreeSensorInterface(true); sensorInterface = null; } } catch (Exception ex) { Debug.LogError(ex.ToString()); if (infoText != null) { infoText.text = ex.Message; } } }
// opens the default sensor and needed readers public static SensorData OpenDefaultSensor(DepthSensorInterface sensorInt, FrameSource dwFlags, float sensorAngle, bool bUseMultiSource) { SensorData sensorData = null; if (sensorInt == null) { return(sensorData); } try { if (sensorData == null) { sensorData = sensorInt.OpenDefaultSensor(dwFlags, sensorAngle, bUseMultiSource); if (sensorData != null) { sensorData.sensorInterface = sensorInt; sensorData.sensorIntPlatform = sensorInt.GetSensorPlatform(); Debug.Log("Interface used: " + sensorInt.GetType().Name); Debug.Log("Shader level: " + SystemInfo.graphicsShaderLevel); } } else { sensorInt.FreeSensorInterface(false); } } catch (Exception ex) { Debug.LogError("Initialization of the sensor failed."); Debug.LogError(ex.ToString()); try { sensorInt.FreeSensorInterface(false); } catch (Exception) { // do nothing } } return(sensorData); }
// initializes the available sensor interfaces public static List <DepthSensorInterface> InitSensorInterfaces(ref bool bNeedRestart) { List <DepthSensorInterface> listInterfaces = new List <DepthSensorInterface>(); var typeInterface = typeof(DepthSensorInterface); Type[] typesAvailable = typeInterface.Assembly.GetTypes(); foreach (Type type in typesAvailable) { if (typeInterface.IsAssignableFrom(type) && type != typeInterface) { DepthSensorInterface sensorInt = null; try { sensorInt = (DepthSensorInterface)Activator.CreateInstance(type); bool bIntNeedRestart = false; if (sensorInt.InitSensorInterface(ref bIntNeedRestart)) { bNeedRestart |= bIntNeedRestart; } else { sensorInt.FreeSensorInterface(); sensorInt = null; continue; } if (sensorInt.GetSensorsCount() <= 0) { sensorInt.FreeSensorInterface(); sensorInt = null; } } catch (Exception) { if (sensorInt != null) { try { sensorInt.FreeSensorInterface(); } catch (Exception) { // do nothing } finally { sensorInt = null; } } } if (sensorInt != null) { listInterfaces.Add(sensorInt); } } } return(listInterfaces); }
void Awake() { try { // bool bOnceRestarted = false; // if(System.IO.File.Exists("SCrestart.txt")) // { // bOnceRestarted = true; // // try // { // System.IO.File.Delete("SCrestart.txt"); // } // catch(Exception ex) // { // Debug.LogError("Error deleting SCrestart.txt"); // Debug.LogError(ex.ToString()); // } // } // init the available sensor interfaces sensorInterface = new Kinect2Interface(); bool bNeedRestart = false; if(sensorInterface.InitSensorInterface(true, ref bNeedRestart)) { if(bNeedRestart) { System.IO.File.WriteAllText("SCrestart.txt", "Restarting level..."); KinectInterop.RestartLevel(gameObject, "SC"); return; } else { // check if a sensor is connected bSensorAvailable = sensorInterface.GetSensorsCount() > 0; if(infoText != null) { infoText.GetComponent<GUIText>().text = bSensorAvailable ? "Sensor is connected." : "No sensor is connected."; } } } else { sensorInterface.FreeSensorInterface(true); sensorInterface = null; } } catch (Exception ex) { Debug.LogError(ex.ToString()); if(infoText != null) { infoText.GetComponent<GUIText>().text = ex.Message; } } }