com.wallstop-studios.unity-helpers 2.0.0-rc64 → 2.0.0-rc65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,17 +9,21 @@
|
|
|
9
9
|
using Extension;
|
|
10
10
|
using Partials;
|
|
11
11
|
using Random;
|
|
12
|
-
using UnityEditor;
|
|
13
12
|
using UnityEngine;
|
|
14
13
|
using Utils;
|
|
15
14
|
using Object = UnityEngine.Object;
|
|
15
|
+
#if UNITY_EDITOR
|
|
16
|
+
using UnityEditor;
|
|
17
|
+
#endif
|
|
16
18
|
|
|
17
19
|
public static partial class Helpers
|
|
18
20
|
{
|
|
19
21
|
private static readonly WaitForEndOfFrame WaitForEndOfFrame = new();
|
|
20
22
|
private static readonly Dictionary<Type, MethodInfo> AwakeMethodsByType = new();
|
|
21
|
-
private static readonly Object LogObject = new();
|
|
22
|
-
private static readonly Dictionary<string, Object> ObjectsByTag = new(
|
|
23
|
+
private static readonly Object LogObject = new() { name = "Wallstop Log Helper" };
|
|
24
|
+
private static readonly Dictionary<string, Object> ObjectsByTag = new(
|
|
25
|
+
StringComparer.Ordinal
|
|
26
|
+
);
|
|
23
27
|
|
|
24
28
|
// https://gamedevelopment.tutsplus.com/tutorials/unity-solution-for-hitting-moving-targets--cms-29633
|
|
25
29
|
public static Vector2 PredictCurrentTarget(
|
|
@@ -599,11 +603,6 @@
|
|
|
599
603
|
return true;
|
|
600
604
|
}
|
|
601
605
|
|
|
602
|
-
if (lhs.name == null || rhs.name == null)
|
|
603
|
-
{
|
|
604
|
-
return false;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
606
|
const string clone = "(Clone)";
|
|
608
607
|
string lhsName = lhs.name;
|
|
609
608
|
while (lhsName.EndsWith(clone))
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
#if !((UNITY_WEBGL && !UNITY_EDITOR) || ENABLE_IL2CPP)
|
|
2
|
+
#define EMIT_DYNAMIC_IL
|
|
3
|
+
#endif
|
|
4
|
+
|
|
5
|
+
namespace WallstopStudios.UnityHelpers.Core.Helper
|
|
2
6
|
{
|
|
3
7
|
using System;
|
|
4
8
|
using System.Collections;
|
|
@@ -91,7 +95,7 @@
|
|
|
91
95
|
|
|
92
96
|
public static Func<object, object> GetFieldGetter(FieldInfo field)
|
|
93
97
|
{
|
|
94
|
-
#if
|
|
98
|
+
#if !EMIT_DYNAMIC_IL
|
|
95
99
|
return field.GetValue;
|
|
96
100
|
#else
|
|
97
101
|
DynamicMethod dynamicMethod = new(
|
|
@@ -125,7 +129,7 @@
|
|
|
125
129
|
|
|
126
130
|
public static Func<object, object> GetPropertyGetter(PropertyInfo property)
|
|
127
131
|
{
|
|
128
|
-
#if
|
|
132
|
+
#if !EMIT_DYNAMIC_IL
|
|
129
133
|
return property.GetValue;
|
|
130
134
|
#else
|
|
131
135
|
MethodInfo getMethod = property.GetGetMethod(true);
|
|
@@ -167,7 +171,7 @@
|
|
|
167
171
|
throw new ArgumentException(nameof(field));
|
|
168
172
|
}
|
|
169
173
|
|
|
170
|
-
#if
|
|
174
|
+
#if !EMIT_DYNAMIC_IL
|
|
171
175
|
return () => field.GetValue(null);
|
|
172
176
|
#else
|
|
173
177
|
DynamicMethod dynamicMethod = new(
|
|
@@ -197,7 +201,7 @@
|
|
|
197
201
|
|
|
198
202
|
public static Func<TInstance, TValue> GetFieldGetter<TInstance, TValue>(FieldInfo field)
|
|
199
203
|
{
|
|
200
|
-
#if
|
|
204
|
+
#if !EMIT_DYNAMIC_IL
|
|
201
205
|
return Getter;
|
|
202
206
|
TValue Getter(TInstance instance)
|
|
203
207
|
{
|
|
@@ -268,9 +272,7 @@
|
|
|
268
272
|
public static Func<TValue> GetStaticPropertyGetter<TValue>(PropertyInfo property)
|
|
269
273
|
{
|
|
270
274
|
MethodInfo getMethod = property.GetGetMethod(true);
|
|
271
|
-
|
|
272
|
-
#if UNITY_WEBGL && !UNITY_EDITOR
|
|
273
|
-
|
|
275
|
+
#if !EMIT_DYNAMIC_IL
|
|
274
276
|
return Getter;
|
|
275
277
|
TValue Getter()
|
|
276
278
|
{
|
|
@@ -278,7 +280,6 @@
|
|
|
278
280
|
return (TValue)property.GetValue(null, null);
|
|
279
281
|
}
|
|
280
282
|
#endif
|
|
281
|
-
|
|
282
283
|
DynamicMethod dynamicMethod = new(
|
|
283
284
|
$"GetStatic_{property.DeclaringType.Name}_{property.Name}",
|
|
284
285
|
typeof(TValue),
|
|
@@ -324,7 +325,7 @@
|
|
|
324
325
|
throw new ArgumentException(nameof(field));
|
|
325
326
|
}
|
|
326
327
|
|
|
327
|
-
#if
|
|
328
|
+
#if !EMIT_DYNAMIC_IL
|
|
328
329
|
return Getter;
|
|
329
330
|
TValue Getter()
|
|
330
331
|
{
|
|
@@ -374,7 +375,7 @@
|
|
|
374
375
|
FieldInfo field
|
|
375
376
|
)
|
|
376
377
|
{
|
|
377
|
-
#if
|
|
378
|
+
#if !EMIT_DYNAMIC_IL
|
|
378
379
|
return Setter;
|
|
379
380
|
void Setter(ref TInstance instance, TValue newValue)
|
|
380
381
|
{
|
|
@@ -418,7 +419,7 @@
|
|
|
418
419
|
{
|
|
419
420
|
throw new ArgumentException(nameof(field));
|
|
420
421
|
}
|
|
421
|
-
#if
|
|
422
|
+
#if !EMIT_DYNAMIC_IL
|
|
422
423
|
return Setter;
|
|
423
424
|
void Setter(TValue newValue)
|
|
424
425
|
{
|
|
@@ -444,7 +445,7 @@
|
|
|
444
445
|
|
|
445
446
|
public static Action<object, object> GetFieldSetter(FieldInfo field)
|
|
446
447
|
{
|
|
447
|
-
#if
|
|
448
|
+
#if !EMIT_DYNAMIC_IL
|
|
448
449
|
return field.SetValue;
|
|
449
450
|
#else
|
|
450
451
|
DynamicMethod dynamicMethod = new(
|
|
@@ -481,7 +482,7 @@
|
|
|
481
482
|
{
|
|
482
483
|
throw new ArgumentException(nameof(field));
|
|
483
484
|
}
|
|
484
|
-
#if
|
|
485
|
+
#if !EMIT_DYNAMIC_IL
|
|
485
486
|
return value => field.SetValue(null, value);
|
|
486
487
|
#else
|
|
487
488
|
DynamicMethod dynamicMethod = new(
|
|
@@ -511,7 +512,7 @@
|
|
|
511
512
|
|
|
512
513
|
public static Func<int, Array> GetArrayCreator(Type elementType)
|
|
513
514
|
{
|
|
514
|
-
#if
|
|
515
|
+
#if !EMIT_DYNAMIC_IL
|
|
515
516
|
return size => Array.CreateInstance(elementType, size);
|
|
516
517
|
#else
|
|
517
518
|
DynamicMethod dynamicMethod = new(
|
|
@@ -532,7 +533,7 @@
|
|
|
532
533
|
public static Func<IList> GetListCreator(Type elementType)
|
|
533
534
|
{
|
|
534
535
|
Type listType = typeof(List<>).MakeGenericType(elementType);
|
|
535
|
-
#if
|
|
536
|
+
#if !EMIT_DYNAMIC_IL
|
|
536
537
|
return () => (IList)Activator.CreateInstance(listType);
|
|
537
538
|
#else
|
|
538
539
|
DynamicMethod dynamicMethod = new(
|
|
@@ -560,7 +561,7 @@
|
|
|
560
561
|
public static Func<int, IList> GetListWithCapacityCreator(Type elementType)
|
|
561
562
|
{
|
|
562
563
|
Type listType = typeof(List<>).MakeGenericType(elementType);
|
|
563
|
-
#if
|
|
564
|
+
#if !EMIT_DYNAMIC_IL
|
|
564
565
|
return _ => (IList)Activator.CreateInstance(listType);
|
|
565
566
|
#else
|
|
566
567
|
DynamicMethod dynamicMethod = new(
|