1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using UnityEngine;
- using System.Collections;
- using Windows.Kinect;
- public class DepthSourceManager : MonoBehaviour
- {
- private KinectSensor _Sensor;
- private DepthFrameReader _Reader;
- private ushort[] _Data;
- public ushort[] GetData()
- {
- return _Data;
- }
- void Start ()
- {
- _Sensor = KinectSensor.GetDefault();
-
- if (_Sensor != null) {
- _Reader = _Sensor.DepthFrameSource.OpenReader ();
- _Data = new ushort[_Sensor.DepthFrameSource.FrameDescription.LengthInPixels];
-
- }
- }
-
- void Update ()
- {
- if (_Reader != null)
- {
- var frame = _Reader.AcquireLatestFrame();
- if (frame != null)
- {
- frame.CopyFrameDataToArray(_Data);
- frame.Dispose();
- frame = null;
- }
- }
- }
-
- void OnApplicationQuit()
- {
- if (_Reader != null)
- {
- _Reader.Dispose();
- _Reader = null;
- }
-
- if (_Sensor != null)
- {
- if (_Sensor.IsOpen)
- {
- _Sensor.Close();
- }
-
- _Sensor = null;
- }
- }
- }
|