t1 / TFDContents / Assets / KinectScripts / Samples / K2SensorChecker.cs @ 3
이력 | 보기 | 이력해설 | 다운로드 (1.96 KB)
| 1 |
#if !(UNITY_WSA_10_0 && NETFX_CORE) |
|---|---|
| 2 |
using UnityEngine; |
| 3 |
using System.Collections; |
| 4 |
using System.Collections.Generic; |
| 5 |
using System; |
| 6 |
|
| 7 |
public class K2SensorChecker : MonoBehaviour |
| 8 |
{
|
| 9 |
|
| 10 |
[Tooltip("GUI-Text to display information messages.")]
|
| 11 |
public GUIText infoText; |
| 12 |
|
| 13 |
|
| 14 |
// the sensor interface |
| 15 |
private DepthSensorInterface sensorInterface = null; |
| 16 |
// whether the sensor is available or not |
| 17 |
private bool bSensorAvailable = false; |
| 18 |
|
| 19 |
|
| 20 |
/// <summary> |
| 21 |
/// Determines whether there is a sensor available. |
| 22 |
/// </summary> |
| 23 |
/// <returns><c>true</c> if a sensor is available; otherwise, <c>false</c>.</returns> |
| 24 |
public bool IsSensorAvailable() |
| 25 |
{
|
| 26 |
return bSensorAvailable; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
void Awake() |
| 31 |
{
|
| 32 |
try |
| 33 |
{
|
| 34 |
// bool bOnceRestarted = false; |
| 35 |
// if(System.IO.File.Exists("SCrestart.txt"))
|
| 36 |
// {
|
| 37 |
// bOnceRestarted = true; |
| 38 |
// |
| 39 |
// try |
| 40 |
// {
|
| 41 |
// System.IO.File.Delete("SCrestart.txt");
|
| 42 |
// } |
| 43 |
// catch(Exception ex) |
| 44 |
// {
|
| 45 |
// Debug.LogError("Error deleting SCrestart.txt");
|
| 46 |
// Debug.LogError(ex.ToString()); |
| 47 |
// } |
| 48 |
// } |
| 49 |
|
| 50 |
// init the available sensor interfaces |
| 51 |
sensorInterface = new Kinect2Interface(); |
| 52 |
|
| 53 |
bool bNeedRestart = false; |
| 54 |
if(sensorInterface.InitSensorInterface(true, ref bNeedRestart)) |
| 55 |
{
|
| 56 |
if(bNeedRestart) |
| 57 |
{
|
| 58 |
System.IO.File.WriteAllText("SCrestart.txt", "Restarting level...");
|
| 59 |
KinectInterop.RestartLevel(gameObject, "SC"); |
| 60 |
return; |
| 61 |
} |
| 62 |
else |
| 63 |
{
|
| 64 |
// check if a sensor is connected |
| 65 |
bSensorAvailable = sensorInterface.GetSensorsCount() > 0; |
| 66 |
|
| 67 |
if(infoText != null) |
| 68 |
{
|
| 69 |
infoText.text = bSensorAvailable ? "Sensor is connected." : "No sensor is connected."; |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
else |
| 74 |
{
|
| 75 |
sensorInterface.FreeSensorInterface(true); |
| 76 |
sensorInterface = null; |
| 77 |
} |
| 78 |
|
| 79 |
} |
| 80 |
catch (Exception ex) |
| 81 |
{
|
| 82 |
Debug.LogError(ex.ToString()); |
| 83 |
|
| 84 |
if(infoText != null) |
| 85 |
{
|
| 86 |
infoText.text = ex.Message; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
|
| 92 |
} |
| 93 |
#endif |