Example #1
0
    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;
            }
        }
    }
Example #2
0
    // 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);
    }
Example #3
0
	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;
			}
		}
		
	}