프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / Standard Assets / Windows / Kinect / BodyFrameSource.cs @ 9

이력 | 보기 | 이력해설 | 다운로드 (15.6 KB)

1 3 KTH
#if !(UNITY_WSA_10_0 && NETFX_CORE)
2
using RootSystem = System;
3
using System.Linq;
4
using System.Collections.Generic;
5
namespace Windows.Kinect
6
{
7
    //
8
    // Windows.Kinect.BodyFrameSource
9
    //
10
    public sealed partial class BodyFrameSource : Helper.INativeWrapper
11
12
    {
13
        internal RootSystem.IntPtr _pNative;
14
        RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
15
16
        // Constructors and Finalizers
17
        internal BodyFrameSource(RootSystem.IntPtr pNative)
18
        {
19
            _pNative = pNative;
20
            Windows_Kinect_BodyFrameSource_AddRefObject(ref _pNative);
21
        }
22
23
        ~BodyFrameSource()
24
        {
25
            Dispose(false);
26
        }
27
28
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
29
        private static extern void Windows_Kinect_BodyFrameSource_ReleaseObject(ref RootSystem.IntPtr pNative);
30
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
31
        private static extern void Windows_Kinect_BodyFrameSource_AddRefObject(ref RootSystem.IntPtr pNative);
32
        private void Dispose(bool disposing)
33
        {
34
            if (_pNative == RootSystem.IntPtr.Zero)
35
            {
36
                return;
37
            }
38
39
            __EventCleanup();
40
41
            Helper.NativeObjectCache.RemoveObject<BodyFrameSource>(_pNative);
42
                Windows_Kinect_BodyFrameSource_ReleaseObject(ref _pNative);
43
44
            _pNative = RootSystem.IntPtr.Zero;
45
        }
46
47
48
        // Public Properties
49
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
50
        private static extern int Windows_Kinect_BodyFrameSource_get_BodyCount(RootSystem.IntPtr pNative);
51
        public  int BodyCount
52
        {
53
            get
54
            {
55
                if (_pNative == RootSystem.IntPtr.Zero)
56
                {
57
                    throw new RootSystem.ObjectDisposedException("BodyFrameSource");
58
                }
59
60
                return Windows_Kinect_BodyFrameSource_get_BodyCount(_pNative);
61
            }
62
        }
63
64
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
65
        private static extern bool Windows_Kinect_BodyFrameSource_get_IsActive(RootSystem.IntPtr pNative);
66
        public  bool IsActive
67
        {
68
            get
69
            {
70
                if (_pNative == RootSystem.IntPtr.Zero)
71
                {
72
                    throw new RootSystem.ObjectDisposedException("BodyFrameSource");
73
                }
74
75
                return Windows_Kinect_BodyFrameSource_get_IsActive(_pNative);
76
            }
77
        }
78
79
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
80
        private static extern RootSystem.IntPtr Windows_Kinect_BodyFrameSource_get_KinectSensor(RootSystem.IntPtr pNative);
81
        public  Windows.Kinect.KinectSensor KinectSensor
82
        {
83
            get
84
            {
85
                if (_pNative == RootSystem.IntPtr.Zero)
86
                {
87
                    throw new RootSystem.ObjectDisposedException("BodyFrameSource");
88
                }
89
90
                RootSystem.IntPtr objectPointer = Windows_Kinect_BodyFrameSource_get_KinectSensor(_pNative);
91
                Helper.ExceptionHelper.CheckLastError();
92
                if (objectPointer == RootSystem.IntPtr.Zero)
93
                {
94
                    return null;
95
                }
96
97
                return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n));
98
            }
99
        }
100
101
102
        // Events
103
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle;
104
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
105
        private delegate void _Windows_Kinect_FrameCapturedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
106
        private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>> Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>>();
107
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_FrameCapturedEventArgs_Delegate))]
108
        private static void Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
109
        {
110
            List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>> callbackList = null;
111
            Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
112
            lock(callbackList)
113
            {
114
                var objThis = Helper.NativeObjectCache.GetObject<BodyFrameSource>(pNative);
115
                var args = new Windows.Kinect.FrameCapturedEventArgs(result);
116
                foreach(var func in callbackList)
117
                {
118
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
119
                }
120
            }
121
        }
122
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
123
        private static extern void Windows_Kinect_BodyFrameSource_add_FrameCaptured(RootSystem.IntPtr pNative, _Windows_Kinect_FrameCapturedEventArgs_Delegate eventCallback, bool unsubscribe);
124
        public  event RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs> FrameCaptured
125
        {
126
            add
127
            {
128
                Helper.EventPump.EnsureInitialized();
129
130
                Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
131
                var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
132
                lock (callbackList)
133
                {
134
                    callbackList.Add(value);
135
                    if(callbackList.Count == 1)
136
                    {
137
                        var del = new _Windows_Kinect_FrameCapturedEventArgs_Delegate(Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler);
138
                        _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
139
                        Windows_Kinect_BodyFrameSource_add_FrameCaptured(_pNative, del, false);
140
                    }
141
                }
142
            }
143
            remove
144
            {
145
                if (_pNative == RootSystem.IntPtr.Zero)
146
                {
147
                    return;
148
                }
149
150
                Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
151
                var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
152
                lock (callbackList)
153
                {
154
                    callbackList.Remove(value);
155
                    if(callbackList.Count == 0)
156
                    {
157
                        Windows_Kinect_BodyFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
158
                        _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
159
                    }
160
                }
161
            }
162
        }
163
164
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
165
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
166
        private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
167
        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>>>();
168
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
169
        private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
170
        {
171
            List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
172
            Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
173
            lock(callbackList)
174
            {
175
                var objThis = Helper.NativeObjectCache.GetObject<BodyFrameSource>(pNative);
176
                var args = new Windows.Data.PropertyChangedEventArgs(result);
177
                foreach(var func in callbackList)
178
                {
179
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
180
                }
181
            }
182
        }
183
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
184
        private static extern void Windows_Kinect_BodyFrameSource_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
185
        public  event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
186
        {
187
            add
188
            {
189
                Helper.EventPump.EnsureInitialized();
190
191
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
192
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
193
                lock (callbackList)
194
                {
195
                    callbackList.Add(value);
196
                    if(callbackList.Count == 1)
197
                    {
198
                        var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
199
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
200
                        Windows_Kinect_BodyFrameSource_add_PropertyChanged(_pNative, del, false);
201
                    }
202
                }
203
            }
204
            remove
205
            {
206
                if (_pNative == RootSystem.IntPtr.Zero)
207
                {
208
                    return;
209
                }
210
211
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
212
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
213
                lock (callbackList)
214
                {
215
                    callbackList.Remove(value);
216
                    if(callbackList.Count == 0)
217
                    {
218
                        Windows_Kinect_BodyFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
219
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
220
                    }
221
                }
222
            }
223
        }
224
225
226
        // Public Methods
227
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
228
        private static extern RootSystem.IntPtr Windows_Kinect_BodyFrameSource_OpenReader(RootSystem.IntPtr pNative);
229
        public Windows.Kinect.BodyFrameReader OpenReader()
230
        {
231
            if (_pNative == RootSystem.IntPtr.Zero)
232
            {
233
                throw new RootSystem.ObjectDisposedException("BodyFrameSource");
234
            }
235
236
            RootSystem.IntPtr objectPointer = Windows_Kinect_BodyFrameSource_OpenReader(_pNative);
237
            Helper.ExceptionHelper.CheckLastError();
238
            if (objectPointer == RootSystem.IntPtr.Zero)
239
            {
240
                return null;
241
            }
242
243
            return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.BodyFrameReader>(objectPointer, n => new Windows.Kinect.BodyFrameReader(n));
244
        }
245
246
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
247
        private static extern void Windows_Kinect_BodyFrameSource_OverrideHandTracking(RootSystem.IntPtr pNative, ulong trackingId);
248
        public void OverrideHandTracking(ulong trackingId)
249
        {
250
            if (_pNative == RootSystem.IntPtr.Zero)
251
            {
252
                throw new RootSystem.ObjectDisposedException("BodyFrameSource");
253
            }
254
255
            Windows_Kinect_BodyFrameSource_OverrideHandTracking(_pNative, trackingId);
256
            Helper.ExceptionHelper.CheckLastError();
257
        }
258
259
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
260
        private static extern void Windows_Kinect_BodyFrameSource_OverrideHandTracking_1(RootSystem.IntPtr pNative, ulong oldTrackingId, ulong newTrackingId);
261
        public void OverrideHandTracking(ulong oldTrackingId, ulong newTrackingId)
262
        {
263
            if (_pNative == RootSystem.IntPtr.Zero)
264
            {
265
                throw new RootSystem.ObjectDisposedException("BodyFrameSource");
266
            }
267
268
            Windows_Kinect_BodyFrameSource_OverrideHandTracking_1(_pNative, oldTrackingId, newTrackingId);
269
            Helper.ExceptionHelper.CheckLastError();
270
        }
271
272
        private void __EventCleanup()
273
        {
274
            {
275
                Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
276
                var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
277
                lock (callbackList)
278
                {
279
                    if (callbackList.Count > 0)
280
                    {
281
                        callbackList.Clear();
282
                        if (_pNative != RootSystem.IntPtr.Zero)
283
                        {
284
                            Windows_Kinect_BodyFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
285
                        }
286
                        _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
287
                    }
288
                }
289
            }
290
            {
291
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
292
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
293
                lock (callbackList)
294
                {
295
                    if (callbackList.Count > 0)
296
                    {
297
                        callbackList.Clear();
298
                        if (_pNative != RootSystem.IntPtr.Zero)
299
                        {
300
                            Windows_Kinect_BodyFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
301
                        }
302
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
303
                    }
304
                }
305
            }
306
        }
307
    }
308
309
}
310
#endif