forked from jacksondunstan/UnityNativeScripting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBindings.cs
More file actions
2157 lines (2000 loc) · 75.7 KB
/
Copy pathBindings.cs
File metadata and controls
2157 lines (2000 loc) · 75.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using AOT;
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using UnityEngine;
namespace NativeScript
{
/// <summary>
/// Internals of the bindings between native and .NET code.
/// Game code shouldn't go here.
/// </summary>
/// <author>
/// Jackson Dunstan, 2017, http://JacksonDunstan.com
/// </author>
/// <license>
/// MIT
/// </license>
public static class Bindings
{
// Holds objects and provides handles to them in the form of ints
public static class ObjectStore
{
// Lookup handles by object.
static Dictionary<object, int> objectHandleCache;
// Stored objects. The first is never used so 0 can be "null".
static object[] objects;
// Stack of available handles.
static int[] handles;
// Index of the next available handle
static int nextHandleIndex;
// The maximum number of objects to store. Must be positive.
static int maxObjects;
public static void Init(int maxObjects)
{
ObjectStore.maxObjects = maxObjects;
objectHandleCache = new Dictionary<object, int>(maxObjects);
// Initialize the objects as all null plus room for the
// first to always be null.
objects = new object[maxObjects + 1];
// Initialize the handles stack as 1, 2, 3, ...
handles = new int[maxObjects];
for (
int i = 0, handle = maxObjects;
i < maxObjects;
++i, --handle)
{
handles[i] = handle;
}
nextHandleIndex = maxObjects - 1;
}
public static int Store(object obj)
{
// Null is always zero
if (object.ReferenceEquals(obj, null))
{
return 0;
}
lock (objects)
{
// Pop a handle off the stack
int handle = handles[nextHandleIndex];
nextHandleIndex--;
// Store the object
objects[handle] = obj;
objectHandleCache.Add(obj, handle);
return handle;
}
}
public static object Get(int handle)
{
return objects[handle];
}
public static int GetHandle(object obj)
{
// Null is always zero
if (object.ReferenceEquals(obj, null))
{
return 0;
}
lock (objects)
{
int handle;
// Get handle from object cache
if (objectHandleCache.TryGetValue(obj, out handle))
{
return handle;
}
}
// Object not found
return Store(obj);
}
public static object Remove(int handle)
{
// Null is never stored, so there's nothing to remove
if (handle == 0)
{
return null;
}
lock (objects)
{
// Forget the object
object obj = objects[handle];
objects[handle] = null;
// Push the handle onto the stack
nextHandleIndex++;
handles[nextHandleIndex] = handle;
// Remove the object from the cache
objectHandleCache.Remove(obj);
return obj;
}
}
}
// Holds structs and provides handles to them in the form of ints
public static class StructStore<T>
where T : struct
{
// Stored structs. The first is never used so 0 can be "null".
static T[] structs;
// Stack of available handles
static int[] handles;
// Index of the next available handle
static int nextHandleIndex;
public static void Init(int maxStructs)
{
// Initialize the objects as all default plus room for the
// first to always be unused.
structs = new T[maxStructs + 1];
// Initialize the handles stack as 1, 2, 3, ...
handles = new int[maxStructs];
for (
int i = 0, handle = maxStructs;
i < maxStructs;
++i, --handle)
{
handles[i] = handle;
}
nextHandleIndex = maxStructs - 1;
}
public static int Store(T structToStore)
{
lock (structs)
{
// Pop a handle off the stack
int handle = handles[nextHandleIndex];
nextHandleIndex--;
// Store the struct
structs[handle] = structToStore;
return handle;
}
}
public static void Replace(int handle, ref T structToStore)
{
structs[handle] = structToStore;
}
public static T Get(int handle)
{
return structs[handle];
}
public static void Remove(int handle)
{
if (handle != 0)
{
lock (structs)
{
// Forget the struct
structs[handle] = default(T);
// Push the handle onto the stack
nextHandleIndex++;
handles[nextHandleIndex] = handle;
}
}
}
}
/// <summary>
/// A reusable version of UnityEngine.WaitForSecondsRealtime to avoid
/// GC allocs
/// </summary>
class ReusableWaitForSecondsRealtime : CustomYieldInstruction
{
private float waitTime;
public float WaitTime
{
set
{
waitTime = Time.realtimeSinceStartup + value;
}
}
public override bool keepWaiting
{
get
{
return Time.realtimeSinceStartup < waitTime;
}
}
public ReusableWaitForSecondsRealtime(float time)
{
WaitTime = time;
}
}
public enum DestroyFunction
{
/*BEGIN DESTROY FUNCTION ENUMERATORS*/
BaseBallScript
/*END DESTROY FUNCTION ENUMERATORS*/
}
struct DestroyEntry
{
public DestroyFunction Function;
public int CppHandle;
public DestroyEntry(DestroyFunction function, int cppHandle)
{
Function = function;
CppHandle = cppHandle;
}
}
// Name of the plugin when using [DllImport]
#if !UNITY_EDITOR && UNITY_IOS
const string PLUGIN_NAME = "__Internal";
#else
const string PLUGIN_NAME = "NativeScript";
#endif
// Path to load the plugin from when running inside the editor
#if UNITY_EDITOR_OSX
const string PLUGIN_PATH = "/Plugins/Editor/NativeScript.bundle/Contents/MacOS/NativeScript";
#elif UNITY_EDITOR_LINUX
const string PLUGIN_PATH = "/Plugins/Editor/libNativeScript.so";
#elif UNITY_EDITOR_WIN
const string PLUGIN_PATH = "/Plugins/Editor/NativeScript.dll";
const string PLUGIN_TEMP_PATH = "/Plugins/Editor/NativeScript_temp.dll";
#endif
enum InitMode : byte
{
FirstBoot,
Reload
}
#if UNITY_EDITOR
// Handle to the C++ DLL
static IntPtr libraryHandle;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void InitDelegate(
IntPtr memory,
int memorySize,
InitMode initMode);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetCsharpExceptionDelegate(int handle);
/*BEGIN CPP DELEGATES*/
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int NewBaseBallScriptDelegateType(int param0);
public static NewBaseBallScriptDelegateType NewBaseBallScript;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void DestroyBaseBallScriptDelegateType(int param0);
public static DestroyBaseBallScriptDelegateType DestroyBaseBallScript;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MyGameAbstractBaseBallScriptUpdateDelegateType(int thisHandle);
public static MyGameAbstractBaseBallScriptUpdateDelegateType MyGameAbstractBaseBallScriptUpdate;
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetCsharpExceptionSystemNullReferenceExceptionDelegateType(int param0);
public static SetCsharpExceptionSystemNullReferenceExceptionDelegateType SetCsharpExceptionSystemNullReferenceException;
/*END CPP DELEGATES*/
#endif
#if UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr dlopen(
string path,
int flag);
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr dlsym(
IntPtr handle,
string symbolName);
[DllImport("__Internal", CallingConvention = CallingConvention.Cdecl)]
static extern int dlclose(
IntPtr handle);
static IntPtr OpenLibrary(
string path)
{
IntPtr handle = dlopen(path, 1); // 1 = lazy, 2 = now
if (handle == IntPtr.Zero)
{
throw new Exception("Couldn't open native library: " + path);
}
return handle;
}
static void CloseLibrary(
IntPtr libraryHandle)
{
dlclose(libraryHandle);
}
static T GetDelegate<T>(
IntPtr libraryHandle,
string functionName) where T : class
{
IntPtr symbol = dlsym(libraryHandle, functionName);
if (symbol == IntPtr.Zero)
{
throw new Exception("Couldn't get function: " + functionName);
}
return Marshal.GetDelegateForFunctionPointer(
symbol,
typeof(T)) as T;
}
#elif UNITY_EDITOR_WIN
[DllImport("kernel32", SetLastError=true, CharSet = CharSet.Ansi)]
static extern IntPtr LoadLibrary(
string path);
[DllImport("kernel32", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)]
static extern IntPtr GetProcAddress(
IntPtr libraryHandle,
string symbolName);
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool FreeLibrary(
IntPtr libraryHandle);
static IntPtr OpenLibrary(string path)
{
IntPtr handle = LoadLibrary(path);
if (handle == IntPtr.Zero)
{
throw new Exception("Couldn't open native library: " + path);
}
return handle;
}
static void CloseLibrary(IntPtr libraryHandle)
{
FreeLibrary(libraryHandle);
}
static T GetDelegate<T>(
IntPtr libraryHandle,
string functionName) where T : class
{
IntPtr symbol = GetProcAddress(libraryHandle, functionName);
if (symbol == IntPtr.Zero)
{
throw new Exception("Couldn't get function: " + functionName);
}
return Marshal.GetDelegateForFunctionPointer(
symbol,
typeof(T)) as T;
}
#else
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern void Init(
IntPtr memory,
int memorySize,
InitMode initMode);
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
static extern void SetCsharpException(int handle);
/*BEGIN IMPORTS*/
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int NewBaseBallScript(int thisHandle);
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void DestroyBaseBallScript(int thisHandle);
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void MyGameAbstractBaseBallScriptUpdate(int thisHandle);
[DllImport(PLUGIN_NAME, CallingConvention = CallingConvention.Cdecl)]
public static extern void SetCsharpExceptionSystemNullReferenceException(int thisHandle);
/*END IMPORTS*/
#endif
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void ReleaseObjectDelegateType(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int StringNewDelegateType(string chars);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void SetExceptionDelegateType(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int ArrayGetLengthDelegateType(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int EnumerableGetEnumeratorDelegateType(int handle);
/*BEGIN DELEGATE TYPES*/
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void ReleaseSystemDecimalDelegateType(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int SystemDecimalConstructorSystemDoubleDelegateType(double value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int SystemDecimalConstructorSystemUInt64DelegateType(ulong value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxDecimalDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnboxDecimalDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate UnityEngine.Vector3 UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingleDelegateType(float x, float y, float z);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate UnityEngine.Vector3 UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3DelegateType(ref UnityEngine.Vector3 a, ref UnityEngine.Vector3 b);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxVector3DelegateType(ref UnityEngine.Vector3 val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate UnityEngine.Vector3 UnboxVector3DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnityEngineObjectPropertyGetNameDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void UnityEngineObjectPropertySetNameDelegateType(int thisHandle, int valueHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnityEngineComponentPropertyGetTransformDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate UnityEngine.Vector3 UnityEngineTransformPropertyGetPositionDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void UnityEngineTransformPropertySetPositionDelegateType(int thisHandle, ref UnityEngine.Vector3 value);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int SystemCollectionsIEnumeratorPropertyGetCurrentDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate bool SystemCollectionsIEnumeratorMethodMoveNextDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnityEngineGameObjectMethodAddComponentMyGameBaseBallScriptDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveTypeDelegateType(UnityEngine.PrimitiveType type);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void UnityEngineDebugMethodLogSystemObjectDelegateType(int messageHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnityEngineMonoBehaviourPropertyGetTransformDelegateType(int thisHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int SystemExceptionConstructorSystemStringDelegateType(int messageHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxPrimitiveTypeDelegateType(UnityEngine.PrimitiveType val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate UnityEngine.PrimitiveType UnboxPrimitiveTypeDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate float UnityEngineTimePropertyGetDeltaTimeDelegateType();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void BaseBallScriptConstructorDelegateType(int cppHandle, ref int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void ReleaseBaseBallScriptDelegateType(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxBooleanDelegateType(bool val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate bool UnboxBooleanDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxSByteDelegateType(sbyte val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate sbyte UnboxSByteDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxByteDelegateType(byte val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate byte UnboxByteDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxInt16DelegateType(short val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate short UnboxInt16DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxUInt16DelegateType(ushort val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate ushort UnboxUInt16DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxInt32DelegateType(int val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int UnboxInt32DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxUInt32DelegateType(uint val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate uint UnboxUInt32DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxInt64DelegateType(long val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate long UnboxInt64DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxUInt64DelegateType(ulong val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate ulong UnboxUInt64DelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxCharDelegateType(char val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate char UnboxCharDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxSingleDelegateType(float val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate float UnboxSingleDelegateType(int valHandle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int BoxDoubleDelegateType(double val);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate double UnboxDoubleDelegateType(int valHandle);
/*END DELEGATE TYPES*/
#if UNITY_EDITOR_WIN
private static readonly string pluginTempPath = Application.dataPath + PLUGIN_TEMP_PATH;
#endif
public static Exception UnhandledCppException;
#if UNITY_EDITOR
private static readonly string pluginPath = Application.dataPath + PLUGIN_PATH;
public static SetCsharpExceptionDelegate SetCsharpException;
#endif
static IntPtr memory;
static int memorySize;
static DestroyEntry[] destroyQueue;
static int destroyQueueCount;
static int destroyQueueCapacity;
static object destroyQueueLockObj;
// Fixed delegates
static readonly ReleaseObjectDelegateType ReleaseObjectDelegate = new ReleaseObjectDelegateType(ReleaseObject);
static readonly StringNewDelegateType StringNewDelegate = new StringNewDelegateType(StringNew);
static readonly SetExceptionDelegateType SetExceptionDelegate = new SetExceptionDelegateType(SetException);
static readonly ArrayGetLengthDelegateType ArrayGetLengthDelegate = new ArrayGetLengthDelegateType(ArrayGetLength);
static readonly EnumerableGetEnumeratorDelegateType EnumerableGetEnumeratorDelegate = new EnumerableGetEnumeratorDelegateType(EnumerableGetEnumerator);
// Generated delegates
/*BEGIN CSHARP DELEGATES*/
static readonly ReleaseSystemDecimalDelegateType ReleaseSystemDecimalDelegate = new ReleaseSystemDecimalDelegateType(ReleaseSystemDecimal);
static readonly SystemDecimalConstructorSystemDoubleDelegateType SystemDecimalConstructorSystemDoubleDelegate = new SystemDecimalConstructorSystemDoubleDelegateType(SystemDecimalConstructorSystemDouble);
static readonly SystemDecimalConstructorSystemUInt64DelegateType SystemDecimalConstructorSystemUInt64Delegate = new SystemDecimalConstructorSystemUInt64DelegateType(SystemDecimalConstructorSystemUInt64);
static readonly BoxDecimalDelegateType BoxDecimalDelegate = new BoxDecimalDelegateType(BoxDecimal);
static readonly UnboxDecimalDelegateType UnboxDecimalDelegate = new UnboxDecimalDelegateType(UnboxDecimal);
static readonly UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingleDelegateType UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingleDelegate = new UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingleDelegateType(UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingle);
static readonly UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3DelegateType UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3Delegate = new UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3DelegateType(UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3);
static readonly BoxVector3DelegateType BoxVector3Delegate = new BoxVector3DelegateType(BoxVector3);
static readonly UnboxVector3DelegateType UnboxVector3Delegate = new UnboxVector3DelegateType(UnboxVector3);
static readonly UnityEngineObjectPropertyGetNameDelegateType UnityEngineObjectPropertyGetNameDelegate = new UnityEngineObjectPropertyGetNameDelegateType(UnityEngineObjectPropertyGetName);
static readonly UnityEngineObjectPropertySetNameDelegateType UnityEngineObjectPropertySetNameDelegate = new UnityEngineObjectPropertySetNameDelegateType(UnityEngineObjectPropertySetName);
static readonly UnityEngineComponentPropertyGetTransformDelegateType UnityEngineComponentPropertyGetTransformDelegate = new UnityEngineComponentPropertyGetTransformDelegateType(UnityEngineComponentPropertyGetTransform);
static readonly UnityEngineTransformPropertyGetPositionDelegateType UnityEngineTransformPropertyGetPositionDelegate = new UnityEngineTransformPropertyGetPositionDelegateType(UnityEngineTransformPropertyGetPosition);
static readonly UnityEngineTransformPropertySetPositionDelegateType UnityEngineTransformPropertySetPositionDelegate = new UnityEngineTransformPropertySetPositionDelegateType(UnityEngineTransformPropertySetPosition);
static readonly SystemCollectionsIEnumeratorPropertyGetCurrentDelegateType SystemCollectionsIEnumeratorPropertyGetCurrentDelegate = new SystemCollectionsIEnumeratorPropertyGetCurrentDelegateType(SystemCollectionsIEnumeratorPropertyGetCurrent);
static readonly SystemCollectionsIEnumeratorMethodMoveNextDelegateType SystemCollectionsIEnumeratorMethodMoveNextDelegate = new SystemCollectionsIEnumeratorMethodMoveNextDelegateType(SystemCollectionsIEnumeratorMethodMoveNext);
static readonly UnityEngineGameObjectMethodAddComponentMyGameBaseBallScriptDelegateType UnityEngineGameObjectMethodAddComponentMyGameBaseBallScriptDelegate = new UnityEngineGameObjectMethodAddComponentMyGameBaseBallScriptDelegateType(UnityEngineGameObjectMethodAddComponentMyGameBaseBallScript);
static readonly UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveTypeDelegateType UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveTypeDelegate = new UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveTypeDelegateType(UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveType);
static readonly UnityEngineDebugMethodLogSystemObjectDelegateType UnityEngineDebugMethodLogSystemObjectDelegate = new UnityEngineDebugMethodLogSystemObjectDelegateType(UnityEngineDebugMethodLogSystemObject);
static readonly UnityEngineMonoBehaviourPropertyGetTransformDelegateType UnityEngineMonoBehaviourPropertyGetTransformDelegate = new UnityEngineMonoBehaviourPropertyGetTransformDelegateType(UnityEngineMonoBehaviourPropertyGetTransform);
static readonly SystemExceptionConstructorSystemStringDelegateType SystemExceptionConstructorSystemStringDelegate = new SystemExceptionConstructorSystemStringDelegateType(SystemExceptionConstructorSystemString);
static readonly BoxPrimitiveTypeDelegateType BoxPrimitiveTypeDelegate = new BoxPrimitiveTypeDelegateType(BoxPrimitiveType);
static readonly UnboxPrimitiveTypeDelegateType UnboxPrimitiveTypeDelegate = new UnboxPrimitiveTypeDelegateType(UnboxPrimitiveType);
static readonly UnityEngineTimePropertyGetDeltaTimeDelegateType UnityEngineTimePropertyGetDeltaTimeDelegate = new UnityEngineTimePropertyGetDeltaTimeDelegateType(UnityEngineTimePropertyGetDeltaTime);
static readonly ReleaseBaseBallScriptDelegateType ReleaseBaseBallScriptDelegate = new ReleaseBaseBallScriptDelegateType(ReleaseBaseBallScript);
static readonly BaseBallScriptConstructorDelegateType BaseBallScriptConstructorDelegate = new BaseBallScriptConstructorDelegateType(BaseBallScriptConstructor);
static readonly BoxBooleanDelegateType BoxBooleanDelegate = new BoxBooleanDelegateType(BoxBoolean);
static readonly UnboxBooleanDelegateType UnboxBooleanDelegate = new UnboxBooleanDelegateType(UnboxBoolean);
static readonly BoxSByteDelegateType BoxSByteDelegate = new BoxSByteDelegateType(BoxSByte);
static readonly UnboxSByteDelegateType UnboxSByteDelegate = new UnboxSByteDelegateType(UnboxSByte);
static readonly BoxByteDelegateType BoxByteDelegate = new BoxByteDelegateType(BoxByte);
static readonly UnboxByteDelegateType UnboxByteDelegate = new UnboxByteDelegateType(UnboxByte);
static readonly BoxInt16DelegateType BoxInt16Delegate = new BoxInt16DelegateType(BoxInt16);
static readonly UnboxInt16DelegateType UnboxInt16Delegate = new UnboxInt16DelegateType(UnboxInt16);
static readonly BoxUInt16DelegateType BoxUInt16Delegate = new BoxUInt16DelegateType(BoxUInt16);
static readonly UnboxUInt16DelegateType UnboxUInt16Delegate = new UnboxUInt16DelegateType(UnboxUInt16);
static readonly BoxInt32DelegateType BoxInt32Delegate = new BoxInt32DelegateType(BoxInt32);
static readonly UnboxInt32DelegateType UnboxInt32Delegate = new UnboxInt32DelegateType(UnboxInt32);
static readonly BoxUInt32DelegateType BoxUInt32Delegate = new BoxUInt32DelegateType(BoxUInt32);
static readonly UnboxUInt32DelegateType UnboxUInt32Delegate = new UnboxUInt32DelegateType(UnboxUInt32);
static readonly BoxInt64DelegateType BoxInt64Delegate = new BoxInt64DelegateType(BoxInt64);
static readonly UnboxInt64DelegateType UnboxInt64Delegate = new UnboxInt64DelegateType(UnboxInt64);
static readonly BoxUInt64DelegateType BoxUInt64Delegate = new BoxUInt64DelegateType(BoxUInt64);
static readonly UnboxUInt64DelegateType UnboxUInt64Delegate = new UnboxUInt64DelegateType(UnboxUInt64);
static readonly BoxCharDelegateType BoxCharDelegate = new BoxCharDelegateType(BoxChar);
static readonly UnboxCharDelegateType UnboxCharDelegate = new UnboxCharDelegateType(UnboxChar);
static readonly BoxSingleDelegateType BoxSingleDelegate = new BoxSingleDelegateType(BoxSingle);
static readonly UnboxSingleDelegateType UnboxSingleDelegate = new UnboxSingleDelegateType(UnboxSingle);
static readonly BoxDoubleDelegateType BoxDoubleDelegate = new BoxDoubleDelegateType(BoxDouble);
static readonly UnboxDoubleDelegateType UnboxDoubleDelegate = new UnboxDoubleDelegateType(UnboxDouble);
/*END CSHARP DELEGATES*/
/// <summary>
/// Open the C++ plugin and call its PluginMain()
/// </summary>
///
/// <param name="memorySize">
/// Number of bytes of memory to make available to the C++ plugin
/// </param>
public static void Open(int memorySize)
{
/*BEGIN STORE INIT CALLS*/
NativeScript.Bindings.ObjectStore.Init(1000);
NativeScript.Bindings.StructStore<System.Decimal>.Init(1000);
/*END STORE INIT CALLS*/
// Allocate unmanaged memory
Bindings.memorySize = memorySize;
memory = Marshal.AllocHGlobal(memorySize);
// Allocate destroy queue
destroyQueueCapacity = 128;
destroyQueue = new DestroyEntry[destroyQueueCapacity];
destroyQueueLockObj = new object();
OpenPlugin(InitMode.FirstBoot);
}
// Reloading requires dynamic loading of the C++ plugin, which is only
// available in the editor
#if UNITY_EDITOR
/// <summary>
/// Reload the C++ plugin. Its memory is intact and false is passed for
/// the isFirstBoot parameter of PluginMain().
/// </summary>
public static void Reload()
{
DestroyAll();
ClosePlugin();
OpenPlugin(InitMode.Reload);
}
/// <summary>
/// Poll the plugin for changes and reload if any are found.
/// </summary>
///
/// <param name="pollTime">
/// Number of seconds between polls.
/// </param>
///
/// <returns>
/// Enumerator for this iterator function. Can be passed to
/// MonoBehaviour.StartCoroutine for easy usage.
/// </returns>
public static IEnumerator AutoReload(float pollTime)
{
// Get the original time
long lastWriteTime = File.GetLastWriteTime(pluginPath).Ticks;
ReusableWaitForSecondsRealtime poll
= new ReusableWaitForSecondsRealtime(pollTime);
do
{
// Poll. Reload if the last write time changed.
long cur = File.GetLastWriteTime(pluginPath).Ticks;
if (cur != lastWriteTime)
{
lastWriteTime = cur;
Reload();
}
// Wait to poll again
poll.WaitTime = pollTime;
yield return poll;
}
while (true);
}
#endif
private static void OpenPlugin(InitMode initMode)
{
#if UNITY_EDITOR
string loadPath;
#if UNITY_EDITOR_WIN
// Copy native library to temporary file
File.Copy(pluginPath, pluginTempPath, true);
loadPath = pluginTempPath;
#else
loadPath = pluginPath;
#endif
// Open native library
libraryHandle = OpenLibrary(loadPath);
InitDelegate Init = GetDelegate<InitDelegate>(
libraryHandle,
"Init");
SetCsharpException = GetDelegate<SetCsharpExceptionDelegate>(
libraryHandle,
"SetCsharpException");
/*BEGIN GETDELEGATE CALLS*/
NewBaseBallScript = GetDelegate<NewBaseBallScriptDelegateType>(libraryHandle, "NewBaseBallScript");
DestroyBaseBallScript = GetDelegate<DestroyBaseBallScriptDelegateType>(libraryHandle, "DestroyBaseBallScript");
MyGameAbstractBaseBallScriptUpdate = GetDelegate<MyGameAbstractBaseBallScriptUpdateDelegateType>(libraryHandle, "MyGameAbstractBaseBallScriptUpdate");
SetCsharpExceptionSystemNullReferenceException = GetDelegate<SetCsharpExceptionSystemNullReferenceExceptionDelegateType>(libraryHandle, "SetCsharpExceptionSystemNullReferenceException");
/*END GETDELEGATE CALLS*/
#endif
// Pass parameters through 'memory'
int curMemory = 0;
Marshal.WriteIntPtr(
memory,
curMemory,
Marshal.GetFunctionPointerForDelegate(ReleaseObjectDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(
memory,
curMemory,
Marshal.GetFunctionPointerForDelegate(StringNewDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(
memory,
curMemory,
Marshal.GetFunctionPointerForDelegate(SetExceptionDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(
memory,
curMemory,
Marshal.GetFunctionPointerForDelegate(ArrayGetLengthDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(
memory,
curMemory,
Marshal.GetFunctionPointerForDelegate(EnumerableGetEnumeratorDelegate));
curMemory += IntPtr.Size;
/*BEGIN INIT CALL*/
Marshal.WriteInt32(memory, curMemory, 1000); // max managed objects
curMemory += sizeof(int);
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(ReleaseSystemDecimalDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(SystemDecimalConstructorSystemDoubleDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(SystemDecimalConstructorSystemUInt64Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxDecimalDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxDecimalDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineVector3ConstructorSystemSingle_SystemSingle_SystemSingleDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineVector3Methodop_AdditionUnityEngineVector3_UnityEngineVector3Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxVector3Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxVector3Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineObjectPropertyGetNameDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineObjectPropertySetNameDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineComponentPropertyGetTransformDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineTransformPropertyGetPositionDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineTransformPropertySetPositionDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(SystemCollectionsIEnumeratorPropertyGetCurrentDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(SystemCollectionsIEnumeratorMethodMoveNextDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineGameObjectMethodAddComponentMyGameBaseBallScriptDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineGameObjectMethodCreatePrimitiveUnityEnginePrimitiveTypeDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineDebugMethodLogSystemObjectDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineMonoBehaviourPropertyGetTransformDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(SystemExceptionConstructorSystemStringDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxPrimitiveTypeDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxPrimitiveTypeDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnityEngineTimePropertyGetDeltaTimeDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(ReleaseBaseBallScriptDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BaseBallScriptConstructorDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxBooleanDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxBooleanDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxSByteDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxSByteDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxByteDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxByteDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxInt16Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxInt16Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxUInt16Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxUInt16Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxInt32Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxInt32Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxUInt32Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxUInt32Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxInt64Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxInt64Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxUInt64Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxUInt64Delegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxCharDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxCharDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxSingleDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxSingleDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(BoxDoubleDelegate));
curMemory += IntPtr.Size;
Marshal.WriteIntPtr(memory, curMemory, Marshal.GetFunctionPointerForDelegate(UnboxDoubleDelegate));
curMemory += IntPtr.Size;
/*END INIT CALL*/
// Init C++ library
Init(memory, memorySize, initMode);
if (UnhandledCppException != null)
{
Exception ex = UnhandledCppException;
UnhandledCppException = null;
throw new Exception("Unhandled C++ exception in Init", ex);
}
}
/// <summary>
/// Close the C++ plugin
/// </summary>
public static void Close()
{
ClosePlugin();
Marshal.FreeHGlobal(memory);
memory = IntPtr.Zero;
}
/// <summary>
/// Perform updates over time
/// </summary>
public static void Update()
{
DestroyAll();
}
private static void ClosePlugin()
{
#if UNITY_EDITOR
CloseLibrary(libraryHandle);
libraryHandle = IntPtr.Zero;
#endif
#if UNITY_EDITOR_WIN
File.Delete(pluginTempPath);
#endif
}
public static void QueueDestroy(DestroyFunction function, int cppHandle)
{
lock (destroyQueueLockObj)
{
// Grow capacity if necessary
int count = destroyQueueCount;
int capacity = destroyQueueCapacity;
DestroyEntry[] queue = destroyQueue;
if (count == capacity)
{
int newCapacity = capacity * 2;
DestroyEntry[] newQueue = new DestroyEntry[newCapacity];
for (int i = 0; i < capacity; ++i)
{
newQueue[i] = queue[i];
}
destroyQueueCapacity = newCapacity;
destroyQueue = newQueue;
queue = newQueue;
}
// Add to the end
queue[count] = new DestroyEntry(function, cppHandle);
destroyQueueCount = count + 1;
}
}
static void DestroyAll()
{
lock (destroyQueueLockObj)
{
int count = destroyQueueCount;
DestroyEntry[] queue = destroyQueue;
for (int i = 0; i < count; ++i)
{
DestroyEntry entry = queue[i];
switch (entry.Function)
{
/*BEGIN DESTROY QUEUE CASES*/
case DestroyFunction.BaseBallScript:
DestroyBaseBallScript(entry.CppHandle);
break;
/*END DESTROY QUEUE CASES*/
}
}
destroyQueueCount = 0;
}
}
////////////////////////////////////////////////////////////////
// C# functions for C++ to call
////////////////////////////////////////////////////////////////
[MonoPInvokeCallback(typeof(ReleaseObjectDelegateType))]
static void ReleaseObject(
int handle)
{
if (handle != 0)
{
ObjectStore.Remove(handle);
}
}
[MonoPInvokeCallback(typeof(StringNewDelegateType))]
static int StringNew(
string chars)
{
int handle = ObjectStore.Store(chars);
return handle;
}
[MonoPInvokeCallback(typeof(SetExceptionDelegateType))]
static void SetException(int handle)
{
UnhandledCppException = ObjectStore.Get(handle) as Exception;
}
[MonoPInvokeCallback(typeof(ArrayGetLengthDelegateType))]
static int ArrayGetLength(int handle)
{
return ((Array)ObjectStore.Get(handle)).Length;
}
[MonoPInvokeCallback(typeof(EnumerableGetEnumeratorDelegateType))]
static int EnumerableGetEnumerator(int handle)
{
return ObjectStore.Store(((IEnumerable)ObjectStore.Get(handle)).GetEnumerator());
}
/*BEGIN FUNCTIONS*/
[MonoPInvokeCallback(typeof(ReleaseSystemDecimalDelegateType))]
static void ReleaseSystemDecimal(int handle)
{
try
{
if (handle != 0)
{
NativeScript.Bindings.StructStore<System.Decimal>.Remove(handle);
}
}
catch (System.NullReferenceException ex)
{
UnityEngine.Debug.LogException(ex);