KinectSensor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.KinectSensor
  8. //
  9. public sealed partial class KinectSensor : Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal KinectSensor(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_KinectSensor_AddRefObject(ref _pNative);
  18. }
  19. ~KinectSensor()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_KinectSensor_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_KinectSensor_AddRefObject(ref RootSystem.IntPtr pNative);
  27. // Public Properties
  28. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  29. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_AudioSource(RootSystem.IntPtr pNative);
  30. public Windows.Kinect.AudioSource AudioSource
  31. {
  32. get
  33. {
  34. if (_pNative == RootSystem.IntPtr.Zero)
  35. {
  36. throw new RootSystem.ObjectDisposedException("KinectSensor");
  37. }
  38. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_AudioSource(_pNative);
  39. Helper.ExceptionHelper.CheckLastError();
  40. if (objectPointer == RootSystem.IntPtr.Zero)
  41. {
  42. return null;
  43. }
  44. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.AudioSource>(objectPointer, n => new Windows.Kinect.AudioSource(n));
  45. }
  46. }
  47. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  48. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_BodyFrameSource(RootSystem.IntPtr pNative);
  49. public Windows.Kinect.BodyFrameSource BodyFrameSource
  50. {
  51. get
  52. {
  53. if (_pNative == RootSystem.IntPtr.Zero)
  54. {
  55. throw new RootSystem.ObjectDisposedException("KinectSensor");
  56. }
  57. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_BodyFrameSource(_pNative);
  58. Helper.ExceptionHelper.CheckLastError();
  59. if (objectPointer == RootSystem.IntPtr.Zero)
  60. {
  61. return null;
  62. }
  63. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.BodyFrameSource>(objectPointer, n => new Windows.Kinect.BodyFrameSource(n));
  64. }
  65. }
  66. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  67. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_BodyIndexFrameSource(RootSystem.IntPtr pNative);
  68. public Windows.Kinect.BodyIndexFrameSource BodyIndexFrameSource
  69. {
  70. get
  71. {
  72. if (_pNative == RootSystem.IntPtr.Zero)
  73. {
  74. throw new RootSystem.ObjectDisposedException("KinectSensor");
  75. }
  76. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_BodyIndexFrameSource(_pNative);
  77. Helper.ExceptionHelper.CheckLastError();
  78. if (objectPointer == RootSystem.IntPtr.Zero)
  79. {
  80. return null;
  81. }
  82. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.BodyIndexFrameSource>(objectPointer, n => new Windows.Kinect.BodyIndexFrameSource(n));
  83. }
  84. }
  85. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  86. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_ColorFrameSource(RootSystem.IntPtr pNative);
  87. public Windows.Kinect.ColorFrameSource ColorFrameSource
  88. {
  89. get
  90. {
  91. if (_pNative == RootSystem.IntPtr.Zero)
  92. {
  93. throw new RootSystem.ObjectDisposedException("KinectSensor");
  94. }
  95. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_ColorFrameSource(_pNative);
  96. Helper.ExceptionHelper.CheckLastError();
  97. if (objectPointer == RootSystem.IntPtr.Zero)
  98. {
  99. return null;
  100. }
  101. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.ColorFrameSource>(objectPointer, n => new Windows.Kinect.ColorFrameSource(n));
  102. }
  103. }
  104. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  105. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_CoordinateMapper(RootSystem.IntPtr pNative);
  106. public Windows.Kinect.CoordinateMapper CoordinateMapper
  107. {
  108. get
  109. {
  110. if (_pNative == RootSystem.IntPtr.Zero)
  111. {
  112. throw new RootSystem.ObjectDisposedException("KinectSensor");
  113. }
  114. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_CoordinateMapper(_pNative);
  115. Helper.ExceptionHelper.CheckLastError();
  116. if (objectPointer == RootSystem.IntPtr.Zero)
  117. {
  118. return null;
  119. }
  120. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.CoordinateMapper>(objectPointer, n => new Windows.Kinect.CoordinateMapper(n));
  121. }
  122. }
  123. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  124. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_DepthFrameSource(RootSystem.IntPtr pNative);
  125. public Windows.Kinect.DepthFrameSource DepthFrameSource
  126. {
  127. get
  128. {
  129. if (_pNative == RootSystem.IntPtr.Zero)
  130. {
  131. throw new RootSystem.ObjectDisposedException("KinectSensor");
  132. }
  133. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_DepthFrameSource(_pNative);
  134. Helper.ExceptionHelper.CheckLastError();
  135. if (objectPointer == RootSystem.IntPtr.Zero)
  136. {
  137. return null;
  138. }
  139. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.DepthFrameSource>(objectPointer, n => new Windows.Kinect.DepthFrameSource(n));
  140. }
  141. }
  142. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  143. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_InfraredFrameSource(RootSystem.IntPtr pNative);
  144. public Windows.Kinect.InfraredFrameSource InfraredFrameSource
  145. {
  146. get
  147. {
  148. if (_pNative == RootSystem.IntPtr.Zero)
  149. {
  150. throw new RootSystem.ObjectDisposedException("KinectSensor");
  151. }
  152. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_InfraredFrameSource(_pNative);
  153. Helper.ExceptionHelper.CheckLastError();
  154. if (objectPointer == RootSystem.IntPtr.Zero)
  155. {
  156. return null;
  157. }
  158. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.InfraredFrameSource>(objectPointer, n => new Windows.Kinect.InfraredFrameSource(n));
  159. }
  160. }
  161. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  162. private static extern bool Windows_Kinect_KinectSensor_get_IsAvailable(RootSystem.IntPtr pNative);
  163. public bool IsAvailable
  164. {
  165. get
  166. {
  167. if (_pNative == RootSystem.IntPtr.Zero)
  168. {
  169. throw new RootSystem.ObjectDisposedException("KinectSensor");
  170. }
  171. return Windows_Kinect_KinectSensor_get_IsAvailable(_pNative);
  172. }
  173. }
  174. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  175. private static extern bool Windows_Kinect_KinectSensor_get_IsOpen(RootSystem.IntPtr pNative);
  176. public bool IsOpen
  177. {
  178. get
  179. {
  180. if (_pNative == RootSystem.IntPtr.Zero)
  181. {
  182. throw new RootSystem.ObjectDisposedException("KinectSensor");
  183. }
  184. return Windows_Kinect_KinectSensor_get_IsOpen(_pNative);
  185. }
  186. }
  187. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  188. private static extern Windows.Kinect.KinectCapabilities Windows_Kinect_KinectSensor_get_KinectCapabilities(RootSystem.IntPtr pNative);
  189. public Windows.Kinect.KinectCapabilities KinectCapabilities
  190. {
  191. get
  192. {
  193. if (_pNative == RootSystem.IntPtr.Zero)
  194. {
  195. throw new RootSystem.ObjectDisposedException("KinectSensor");
  196. }
  197. return Windows_Kinect_KinectSensor_get_KinectCapabilities(_pNative);
  198. }
  199. }
  200. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  201. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_LongExposureInfraredFrameSource(RootSystem.IntPtr pNative);
  202. public Windows.Kinect.LongExposureInfraredFrameSource LongExposureInfraredFrameSource
  203. {
  204. get
  205. {
  206. if (_pNative == RootSystem.IntPtr.Zero)
  207. {
  208. throw new RootSystem.ObjectDisposedException("KinectSensor");
  209. }
  210. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_LongExposureInfraredFrameSource(_pNative);
  211. Helper.ExceptionHelper.CheckLastError();
  212. if (objectPointer == RootSystem.IntPtr.Zero)
  213. {
  214. return null;
  215. }
  216. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.LongExposureInfraredFrameSource>(objectPointer, n => new Windows.Kinect.LongExposureInfraredFrameSource(n));
  217. }
  218. }
  219. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  220. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_get_UniqueKinectId(RootSystem.IntPtr pNative);
  221. public string UniqueKinectId
  222. {
  223. get
  224. {
  225. if (_pNative == RootSystem.IntPtr.Zero)
  226. {
  227. throw new RootSystem.ObjectDisposedException("KinectSensor");
  228. }
  229. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_get_UniqueKinectId(_pNative);
  230. Helper.ExceptionHelper.CheckLastError();
  231. var managedString = RootSystem.Runtime.InteropServices.Marshal.PtrToStringUni(objectPointer);
  232. RootSystem.Runtime.InteropServices.Marshal.FreeCoTaskMem(objectPointer);
  233. return managedString;
  234. }
  235. }
  236. // Events
  237. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handle;
  238. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  239. private delegate void _Windows_Kinect_IsAvailableChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  240. private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.IsAvailableChangedEventArgs>>> Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.IsAvailableChangedEventArgs>>>();
  241. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_IsAvailableChangedEventArgs_Delegate))]
  242. private static void Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  243. {
  244. List<RootSystem.EventHandler<Windows.Kinect.IsAvailableChangedEventArgs>> callbackList = null;
  245. Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  246. lock(callbackList)
  247. {
  248. var objThis = Helper.NativeObjectCache.GetObject<KinectSensor>(pNative);
  249. var args = new Windows.Kinect.IsAvailableChangedEventArgs(result);
  250. foreach(var func in callbackList)
  251. {
  252. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  253. }
  254. }
  255. }
  256. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  257. private static extern void Windows_Kinect_KinectSensor_add_IsAvailableChanged(RootSystem.IntPtr pNative, _Windows_Kinect_IsAvailableChangedEventArgs_Delegate eventCallback, bool unsubscribe);
  258. public event RootSystem.EventHandler<Windows.Kinect.IsAvailableChangedEventArgs> IsAvailableChanged
  259. {
  260. add
  261. {
  262. Helper.EventPump.EnsureInitialized();
  263. Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  264. var callbackList = Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks[_pNative];
  265. lock (callbackList)
  266. {
  267. callbackList.Add(value);
  268. if(callbackList.Count == 1)
  269. {
  270. var del = new _Windows_Kinect_IsAvailableChangedEventArgs_Delegate(Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handler);
  271. _Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  272. Windows_Kinect_KinectSensor_add_IsAvailableChanged(_pNative, del, false);
  273. }
  274. }
  275. }
  276. remove
  277. {
  278. if (_pNative == RootSystem.IntPtr.Zero)
  279. {
  280. return;
  281. }
  282. Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  283. var callbackList = Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks[_pNative];
  284. lock (callbackList)
  285. {
  286. callbackList.Remove(value);
  287. if(callbackList.Count == 0)
  288. {
  289. Windows_Kinect_KinectSensor_add_IsAvailableChanged(_pNative, Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handler, true);
  290. _Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handle.Free();
  291. }
  292. }
  293. }
  294. }
  295. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
  296. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  297. private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  298. private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>> Windows_Data_PropertyChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>>();
  299. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
  300. private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  301. {
  302. List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
  303. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  304. lock(callbackList)
  305. {
  306. var objThis = Helper.NativeObjectCache.GetObject<KinectSensor>(pNative);
  307. var args = new Windows.Data.PropertyChangedEventArgs(result);
  308. foreach(var func in callbackList)
  309. {
  310. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  311. }
  312. }
  313. }
  314. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  315. private static extern void Windows_Kinect_KinectSensor_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
  316. public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
  317. {
  318. add
  319. {
  320. Helper.EventPump.EnsureInitialized();
  321. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  322. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  323. lock (callbackList)
  324. {
  325. callbackList.Add(value);
  326. if(callbackList.Count == 1)
  327. {
  328. var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
  329. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  330. Windows_Kinect_KinectSensor_add_PropertyChanged(_pNative, del, false);
  331. }
  332. }
  333. }
  334. remove
  335. {
  336. if (_pNative == RootSystem.IntPtr.Zero)
  337. {
  338. return;
  339. }
  340. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  341. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  342. lock (callbackList)
  343. {
  344. callbackList.Remove(value);
  345. if(callbackList.Count == 0)
  346. {
  347. Windows_Kinect_KinectSensor_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  348. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  349. }
  350. }
  351. }
  352. }
  353. // Static Methods
  354. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  355. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_GetDefault();
  356. public static Windows.Kinect.KinectSensor GetDefault()
  357. {
  358. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_GetDefault();
  359. Helper.ExceptionHelper.CheckLastError();
  360. if (objectPointer == RootSystem.IntPtr.Zero)
  361. {
  362. return null;
  363. }
  364. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n));
  365. }
  366. // Public Methods
  367. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  368. private static extern void Windows_Kinect_KinectSensor_Open(RootSystem.IntPtr pNative);
  369. public void Open()
  370. {
  371. if (_pNative == RootSystem.IntPtr.Zero)
  372. {
  373. throw new RootSystem.ObjectDisposedException("KinectSensor");
  374. }
  375. Windows_Kinect_KinectSensor_Open(_pNative);
  376. Helper.ExceptionHelper.CheckLastError();
  377. }
  378. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  379. private static extern void Windows_Kinect_KinectSensor_Close(RootSystem.IntPtr pNative);
  380. public void Close()
  381. {
  382. if (_pNative == RootSystem.IntPtr.Zero)
  383. {
  384. throw new RootSystem.ObjectDisposedException("KinectSensor");
  385. }
  386. Windows_Kinect_KinectSensor_Close(_pNative);
  387. Helper.ExceptionHelper.CheckLastError();
  388. }
  389. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  390. private static extern RootSystem.IntPtr Windows_Kinect_KinectSensor_OpenMultiSourceFrameReader(RootSystem.IntPtr pNative, Windows.Kinect.FrameSourceTypes enabledFrameSourceTypes);
  391. public Windows.Kinect.MultiSourceFrameReader OpenMultiSourceFrameReader(Windows.Kinect.FrameSourceTypes enabledFrameSourceTypes)
  392. {
  393. if (_pNative == RootSystem.IntPtr.Zero)
  394. {
  395. throw new RootSystem.ObjectDisposedException("KinectSensor");
  396. }
  397. RootSystem.IntPtr objectPointer = Windows_Kinect_KinectSensor_OpenMultiSourceFrameReader(_pNative, enabledFrameSourceTypes);
  398. Helper.ExceptionHelper.CheckLastError();
  399. if (objectPointer == RootSystem.IntPtr.Zero)
  400. {
  401. return null;
  402. }
  403. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.MultiSourceFrameReader>(objectPointer, n => new Windows.Kinect.MultiSourceFrameReader(n));
  404. }
  405. private void __EventCleanup()
  406. {
  407. {
  408. Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  409. var callbackList = Windows_Kinect_IsAvailableChangedEventArgs_Delegate_callbacks[_pNative];
  410. lock (callbackList)
  411. {
  412. if (callbackList.Count > 0)
  413. {
  414. callbackList.Clear();
  415. if (_pNative != RootSystem.IntPtr.Zero)
  416. {
  417. Windows_Kinect_KinectSensor_add_IsAvailableChanged(_pNative, Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handler, true);
  418. }
  419. _Windows_Kinect_IsAvailableChangedEventArgs_Delegate_Handle.Free();
  420. }
  421. }
  422. }
  423. {
  424. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  425. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  426. lock (callbackList)
  427. {
  428. if (callbackList.Count > 0)
  429. {
  430. callbackList.Clear();
  431. if (_pNative != RootSystem.IntPtr.Zero)
  432. {
  433. Windows_Kinect_KinectSensor_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  434. }
  435. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }