com.wallstop-studios.unity-helpers 2.0.0-rc61 → 2.0.0-rc63

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.
Files changed (177) hide show
  1. package/Editor/AnimationCopier.cs +7 -14
  2. package/Editor/AnimationCreator.cs +7 -11
  3. package/Editor/AnimationEventEditor.cs +6 -6
  4. package/Editor/AnimatorControllerCopier.cs +7 -13
  5. package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +4 -6
  6. package/Editor/FitTextureSizeWizard.cs +4 -4
  7. package/Editor/PrefabCheckWizard.cs +10 -13
  8. package/Editor/SpriteSettingsApplier.cs +4 -4
  9. package/Editor/StringInListeDrawer.cs +2 -2
  10. package/Editor/TextureResizerWizard.cs +6 -12
  11. package/Editor/TextureSettingsApplier.cs +5 -5
  12. package/Editor/Utils/DxReadOnlyPropertyDrawer.cs +2 -2
  13. package/Editor/Utils/EditorUtilities.cs +1 -1
  14. package/Editor/WShowIfPropertyDrawer.cs +4 -4
  15. package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +1 -1
  16. package/Runtime/Core/Attributes/AnimationEventAttribute.cs +1 -1
  17. package/Runtime/Core/Attributes/ChildComponentAttribute.cs +2 -1
  18. package/Runtime/Core/Attributes/DxReadOnlyAttribute.cs +1 -1
  19. package/Runtime/Core/Attributes/KSerializableAttribute.cs +1 -1
  20. package/Runtime/Core/Attributes/NotNullAttribute.cs +1 -1
  21. package/Runtime/Core/Attributes/ParentComponent.cs +1 -1
  22. package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +1 -1
  23. package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +1 -1
  24. package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +12 -7
  25. package/Runtime/Core/Attributes/WShowIfAttribute.cs +1 -1
  26. package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +1 -1
  27. package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +1 -1
  28. package/Runtime/Core/DataStructure/Adapters/KGuid.cs +1 -1
  29. package/Runtime/Core/DataStructure/Adapters/KVector2.cs +1 -1
  30. package/Runtime/Core/DataStructure/Circle.cs +1 -1
  31. package/Runtime/Core/DataStructure/CyclicBuffer.cs +1 -1
  32. package/Runtime/Core/DataStructure/ISpatialTree.cs +1 -1
  33. package/Runtime/Core/DataStructure/KDTree.cs +1 -1
  34. package/Runtime/Core/DataStructure/QuadTree.cs +1 -1
  35. package/Runtime/Core/DataStructure/RTree.cs +1 -1
  36. package/Runtime/Core/DataStructure/StringWrapper.cs +1 -1
  37. package/Runtime/Core/DataStructure/TimedCache.cs +1 -1
  38. package/Runtime/Core/Extension/AnimatorExtensions.cs +1 -1
  39. package/Runtime/Core/Extension/AsyncOperationExtensions.cs +1 -1
  40. package/Runtime/Core/Extension/CircleExtensions.cs +1 -1
  41. package/Runtime/Core/Extension/ColorExtensions.cs +16 -1
  42. package/Runtime/Core/Extension/DictionaryExtensions.cs +1 -1
  43. package/Runtime/Core/Extension/DirectionExtensions.cs +1 -1
  44. package/Runtime/Core/Extension/EnumExtensions.cs +1 -1
  45. package/Runtime/Core/Extension/HashSetExtensions.cs +1 -1
  46. package/Runtime/Core/Extension/IEnumerableExtensions.cs +1 -1
  47. package/Runtime/Core/Extension/IListExtensions.cs +1 -1
  48. package/Runtime/Core/Extension/LoggingExtensions.cs +69 -122
  49. package/Runtime/Core/Extension/RandomExtensions.cs +1 -1
  50. package/Runtime/Core/Extension/SerializedPropertyExtensions.cs +2 -2
  51. package/Runtime/Core/Extension/StringExtensions.cs +1 -1
  52. package/Runtime/Core/Extension/UnityExtensions.cs +1 -2
  53. package/Runtime/Core/Helper/ArrayConverter.cs +1 -1
  54. package/Runtime/Core/Helper/AssignUtilities.cs +1 -1
  55. package/Runtime/Core/Helper/DirectoryHelper.cs +1 -1
  56. package/Runtime/Core/Helper/Enumerables.cs +1 -1
  57. package/Runtime/Core/Helper/FormattingHelpers.cs +1 -1
  58. package/Runtime/Core/Helper/Geometry.cs +1 -1
  59. package/Runtime/Core/Helper/Helpers.cs +6 -9
  60. package/Runtime/Core/Helper/IterationHelpers.cs +1 -1
  61. package/Runtime/Core/Helper/LifetimeHelpers.cs +2 -1
  62. package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs +517 -0
  63. package/Runtime/Core/Helper/Logging/UnityLogTagFormatter.cs.meta +3 -0
  64. package/Runtime/Core/Helper/Logging.meta +3 -0
  65. package/Runtime/Core/Helper/Objects.cs +1 -1
  66. package/Runtime/Core/Helper/Partials/LogHelpers.cs +2 -2
  67. package/Runtime/Core/Helper/Partials/MathHelpers.cs +1 -1
  68. package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +5 -11
  69. package/Runtime/Core/Helper/Partials/TransformHelpers.cs +1 -1
  70. package/Runtime/Core/Helper/ReflectionHelpers.cs +173 -36
  71. package/Runtime/Core/Helper/SceneHelper.cs +3 -5
  72. package/Runtime/Core/Helper/SpriteHelpers.cs +3 -3
  73. package/Runtime/Core/Helper/StringInList.cs +1 -1
  74. package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +2 -4
  75. package/Runtime/Core/Helper/WallMath.cs +1 -1
  76. package/Runtime/Core/Math/Line.cs +1 -1
  77. package/Runtime/Core/Math/Parabola.cs +1 -1
  78. package/Runtime/Core/Math/PointPolygonCheck.cs +1 -1
  79. package/Runtime/Core/Math/Range.cs +1 -1
  80. package/Runtime/Core/Math/XXHash.cs +1 -1
  81. package/Runtime/Core/Model/Direction.cs +1 -1
  82. package/Runtime/Core/OneOf/FastOneOf.cs +1 -1
  83. package/Runtime/Core/OneOf/None.cs +1 -1
  84. package/Runtime/Core/Random/AbstractRandom.cs +1 -1
  85. package/Runtime/Core/Random/DotNetRandom.cs +1 -1
  86. package/Runtime/Core/Random/IRandom.cs +1 -1
  87. package/Runtime/Core/Random/LinearCongruentialGenerator.cs +1 -1
  88. package/Runtime/Core/Random/NativePcgRandom.cs +1 -1
  89. package/Runtime/Core/Random/PRNG.cs +1 -1
  90. package/Runtime/Core/Random/PcgRandom.cs +1 -1
  91. package/Runtime/Core/Random/PerlinNoise.cs +1 -1
  92. package/Runtime/Core/Random/RandomState.cs +1 -1
  93. package/Runtime/Core/Random/RandomUtilities.cs +1 -1
  94. package/Runtime/Core/Random/RomuDuo.cs +1 -1
  95. package/Runtime/Core/Random/SplitMix64.cs +1 -1
  96. package/Runtime/Core/Random/SquirrelRandom.cs +1 -1
  97. package/Runtime/Core/Random/SystemRandom.cs +1 -1
  98. package/Runtime/Core/Random/ThreadLocalRandom.cs +1 -1
  99. package/Runtime/Core/Random/UnityRandom.cs +1 -1
  100. package/Runtime/Core/Random/WyRandom.cs +1 -1
  101. package/Runtime/Core/Random/XorShiftRandom.cs +1 -1
  102. package/Runtime/Core/Random/XorShiroRandom.cs +1 -1
  103. package/Runtime/Core/Serialization/JsonConverters/ColorConverter.cs +1 -1
  104. package/Runtime/Core/Serialization/JsonConverters/GameObjectConverter.cs +1 -2
  105. package/Runtime/Core/Serialization/JsonConverters/Matrix4x4Converter.cs +1 -1
  106. package/Runtime/Core/Serialization/JsonConverters/TypeConverter.cs +1 -1
  107. package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +1 -1
  108. package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +1 -1
  109. package/Runtime/Core/Serialization/JsonConverters/Vector4Converter.cs +1 -1
  110. package/Runtime/Core/Serialization/Serializer.cs +1 -1
  111. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +1 -1
  112. package/Runtime/UI/LayeredImage.cs +1 -1
  113. package/Runtime/Utils/AnimationEventEqualityComparer.cs +1 -1
  114. package/Runtime/Utils/AnimatorEnumStateMachine.cs +1 -1
  115. package/Runtime/Utils/Buffers.cs +1 -1
  116. package/Runtime/Utils/CenterPointOffset.cs +1 -1
  117. package/Runtime/Utils/CircleLineRenderer.cs +4 -6
  118. package/Runtime/Utils/CoroutineHandler.cs +1 -1
  119. package/Runtime/Utils/DeferredDisposalResult.cs +1 -1
  120. package/Runtime/Utils/MatchColliderToSprite.cs +1 -1
  121. package/Runtime/Utils/Oscillator.cs +1 -1
  122. package/Runtime/Utils/RuntimeSingleton.cs +1 -1
  123. package/Runtime/Utils/SetTextureImportData.cs +1 -1
  124. package/Runtime/Utils/SpriteRendererMetadata.cs +1 -1
  125. package/Runtime/Utils/SpriteRendererSyncer.cs +1 -1
  126. package/Runtime/Utils/StartTracker.cs +1 -1
  127. package/Runtime/Utils/TextureScale.cs +1 -1
  128. package/Runtime/Utils/TypeNameSorter.cs +17 -0
  129. package/Runtime/Utils/TypeNameSorter.cs.meta +3 -0
  130. package/Runtime/Utils/UnityObjectNameComparer.cs +1 -1
  131. package/Runtime/WallstopStudios.UnityHelpers.asmdef +1 -1
  132. package/Tests/Runtime/Attributes/ChildComponentTests.cs +2 -2
  133. package/Tests/Runtime/Attributes/Components/ExpectChildSpriteRenderers.cs +2 -2
  134. package/Tests/Runtime/Attributes/Components/ExpectParentSpriteRenderers.cs +2 -2
  135. package/Tests/Runtime/Attributes/ParentComponentTests.cs +2 -2
  136. package/Tests/Runtime/Components/RelationalComponentTesterComplex.cs +2 -2
  137. package/Tests/Runtime/Components/RelationalComponentsTesterSimple.cs +4 -4
  138. package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +2 -2
  139. package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +3 -3
  140. package/Tests/Runtime/DataStructures/QuadTreeTests.cs +2 -2
  141. package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +4 -4
  142. package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +2 -2
  143. package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +2 -3
  144. package/Tests/Runtime/Extensions/EnumExtensionTests.cs +2 -2
  145. package/Tests/Runtime/Extensions/IListExtensionTests.cs +3 -3
  146. package/Tests/Runtime/Extensions/LoggingExtensionTests.cs +718 -0
  147. package/Tests/Runtime/Extensions/LoggingExtensionTests.cs.meta +3 -0
  148. package/Tests/Runtime/Extensions/RandomExtensionTests.cs +3 -3
  149. package/Tests/Runtime/Extensions/StringExtensionTests.cs +2 -2
  150. package/Tests/Runtime/Helper/ArrayConverterTests.cs +3 -3
  151. package/Tests/Runtime/Helper/FormattingHelperTests.cs +3 -3
  152. package/Tests/Runtime/Helper/ObjectHelperTests.cs +2 -2
  153. package/Tests/Runtime/Helper/ReflectionHelperTests.cs +3 -3
  154. package/Tests/Runtime/Helper/SceneHelperTests.cs +3 -3
  155. package/Tests/Runtime/Helper/WallMathTests.cs +5 -5
  156. package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +2 -2
  157. package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +2 -2
  158. package/Tests/Runtime/Performance/RandomPerformanceTests.cs +2 -2
  159. package/Tests/Runtime/Performance/RelationComponentPerformanceTests.cs +2 -2
  160. package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +2 -2
  161. package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +2 -2
  162. package/Tests/Runtime/Random/DotNetRandomTests.cs +2 -2
  163. package/Tests/Runtime/Random/LinearCongruentialGeneratorTests.cs +2 -2
  164. package/Tests/Runtime/Random/PcgRandomTests.cs +2 -2
  165. package/Tests/Runtime/Random/RandomTestBase.cs +7 -7
  166. package/Tests/Runtime/Random/RomuDuoRandomTests.cs +2 -2
  167. package/Tests/Runtime/Random/SplitMix64RandomTests.cs +2 -2
  168. package/Tests/Runtime/Random/SquirrelRandomTests.cs +2 -2
  169. package/Tests/Runtime/Random/SystemRandomTests.cs +2 -2
  170. package/Tests/Runtime/Random/UnityRandomTests.cs +2 -2
  171. package/Tests/Runtime/Random/WyRandomTests.cs +2 -2
  172. package/Tests/Runtime/Random/XorShiftRandomTests.cs +2 -2
  173. package/Tests/Runtime/Random/XorShiroRandomTests.cs +2 -2
  174. package/Tests/Runtime/Serialization/JsonSerializationTest.cs +5 -5
  175. package/Tests/Runtime/Utils/SpriteRendererMetadataTests.cs +3 -4
  176. package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef +1 -1
  177. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using System;
4
4
  using System.Collections;
5
5
  using System.Collections.Generic;
6
+ using System.Linq;
6
7
  using System.Reflection;
7
8
  using System.Reflection.Emit;
8
9
  using System.Runtime.CompilerServices;
@@ -16,6 +17,53 @@
16
17
  private static readonly Dictionary<Type, Func<IList>> ListCreators = new();
17
18
  private static readonly Dictionary<Type, Func<int, IList>> ListWithCapacityCreators = new();
18
19
 
20
+ public static bool IsAttributeDefined<T>(
21
+ this ICustomAttributeProvider provider,
22
+ out T attribute,
23
+ bool inherit = true
24
+ )
25
+ where T : Attribute
26
+ {
27
+ try
28
+ {
29
+ if (provider.IsDefined(typeof(T), inherit))
30
+ {
31
+ attribute = (T)provider.GetCustomAttributes(typeof(T), inherit)[0];
32
+ return true;
33
+ }
34
+ }
35
+ catch
36
+ {
37
+ // Swallow
38
+ }
39
+ attribute = default;
40
+ return false;
41
+ }
42
+
43
+ public static Dictionary<string, PropertyInfo> LoadStaticPropertiesForType<T>()
44
+ {
45
+ Type type = typeof(T);
46
+ return type.GetProperties(BindingFlags.Static | BindingFlags.Public)
47
+ .Where(property => property.PropertyType == type)
48
+ .ToDictionary(
49
+ property => property.Name,
50
+ property => property,
51
+ StringComparer.OrdinalIgnoreCase
52
+ );
53
+ }
54
+
55
+ public static Dictionary<string, FieldInfo> LoadStaticFieldsForType<T>()
56
+ {
57
+ Type type = typeof(T);
58
+ return type.GetFields(BindingFlags.Static | BindingFlags.Public)
59
+ .Where(field => field.FieldType == type)
60
+ .ToDictionary(
61
+ field => field.Name,
62
+ field => field,
63
+ StringComparer.OrdinalIgnoreCase
64
+ );
65
+ }
66
+
19
67
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
20
68
  public static Array CreateArray(Type type, int length)
21
69
  {
@@ -43,11 +91,11 @@
43
91
 
44
92
  public static Func<object, object> GetFieldGetter(FieldInfo field)
45
93
  {
46
- #if WEB_GL
94
+ #if UNITY_WEBGL && !UNITY_EDITOR
47
95
  return field.GetValue;
48
96
  #else
49
97
  DynamicMethod dynamicMethod = new(
50
- $"Get{field.DeclaringType.Name}{field.Name}",
98
+ $"Get{field.DeclaringType.Name}_{field.Name}",
51
99
  typeof(object),
52
100
  new[] { typeof(object) },
53
101
  field.DeclaringType,
@@ -75,6 +123,43 @@
75
123
  #endif
76
124
  }
77
125
 
126
+ public static Func<object, object> GetPropertyGetter(PropertyInfo property)
127
+ {
128
+ #if UNITY_WEBGL && !UNITY_EDITOR
129
+ return property.GetValue;
130
+ #else
131
+ MethodInfo getMethod = property.GetGetMethod(true);
132
+
133
+ DynamicMethod dynamicMethod = new(
134
+ $"Get{property.DeclaringType.Name}_{property.Name}",
135
+ typeof(object),
136
+ new[] { typeof(object) },
137
+ property.DeclaringType,
138
+ true
139
+ );
140
+
141
+ ILGenerator il = dynamicMethod.GetILGenerator();
142
+ il.Emit(OpCodes.Ldarg_0);
143
+ il.Emit(
144
+ property.DeclaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass,
145
+ property.DeclaringType
146
+ );
147
+ il.Emit(
148
+ property.DeclaringType.IsValueType ? OpCodes.Call : OpCodes.Callvirt,
149
+ getMethod
150
+ );
151
+
152
+ if (property.PropertyType.IsValueType)
153
+ {
154
+ il.Emit(OpCodes.Box, property.PropertyType);
155
+ }
156
+
157
+ il.Emit(OpCodes.Ret);
158
+
159
+ return (Func<object, object>)dynamicMethod.CreateDelegate(typeof(Func<object, object>));
160
+ #endif
161
+ }
162
+
78
163
  public static Func<object> GetStaticFieldGetter(FieldInfo field)
79
164
  {
80
165
  if (!field.IsStatic)
@@ -82,11 +167,11 @@
82
167
  throw new ArgumentException(nameof(field));
83
168
  }
84
169
 
85
- #if WEB_GL
170
+ #if UNITY_WEBGL && !UNITY_EDITOR
86
171
  return () => field.GetValue(null);
87
172
  #else
88
173
  DynamicMethod dynamicMethod = new(
89
- $"Get{field.DeclaringType.Name}{field.Name}",
174
+ $"Get{field.DeclaringType.Name}_{field.Name}",
90
175
  typeof(object),
91
176
  Type.EmptyTypes, // No parameters for static fields
92
177
  field.DeclaringType,
@@ -112,7 +197,7 @@
112
197
 
113
198
  public static Func<TInstance, TValue> GetFieldGetter<TInstance, TValue>(FieldInfo field)
114
199
  {
115
- #if WEB_GL
200
+ #if UNITY_WEBGL && !UNITY_EDITOR
116
201
  return Getter;
117
202
  TValue Getter(TInstance instance)
118
203
  {
@@ -120,7 +205,7 @@
120
205
  }
121
206
  #else
122
207
  DynamicMethod dynamicMethod = new(
123
- $"GetGeneric{field.DeclaringType.Name}{field.Name}",
208
+ $"GetGeneric{field.DeclaringType.Name}_{field.Name}",
124
209
  typeof(TValue),
125
210
  new[] { typeof(TInstance) },
126
211
  field.DeclaringType,
@@ -180,6 +265,58 @@
180
265
  #endif
181
266
  }
182
267
 
268
+ public static Func<TValue> GetStaticPropertyGetter<TValue>(PropertyInfo property)
269
+ {
270
+ MethodInfo getMethod = property.GetGetMethod(true);
271
+
272
+ #if UNITY_WEBGL && !UNITY_EDITOR
273
+
274
+ return Getter;
275
+ TValue Getter()
276
+ {
277
+ // Use null for instance, null for indexer args for static properties
278
+ return (TValue)property.GetValue(null, null);
279
+ }
280
+ #endif
281
+
282
+ DynamicMethod dynamicMethod = new(
283
+ $"GetStatic_{property.DeclaringType.Name}_{property.Name}",
284
+ typeof(TValue),
285
+ Type.EmptyTypes,
286
+ property.DeclaringType,
287
+ true
288
+ );
289
+
290
+ ILGenerator il = dynamicMethod.GetILGenerator();
291
+
292
+ il.Emit(OpCodes.Call, getMethod);
293
+
294
+ Type actualType = property.PropertyType;
295
+ Type targetType = typeof(TValue);
296
+
297
+ if (actualType != targetType)
298
+ {
299
+ if (actualType.IsValueType)
300
+ {
301
+ il.Emit(OpCodes.Box, actualType);
302
+ if (targetType != typeof(object))
303
+ {
304
+ il.Emit(OpCodes.Castclass, targetType);
305
+ }
306
+ }
307
+ else
308
+ {
309
+ il.Emit(
310
+ targetType.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass,
311
+ targetType
312
+ );
313
+ }
314
+ }
315
+
316
+ il.Emit(OpCodes.Ret);
317
+ return (Func<TValue>)dynamicMethod.CreateDelegate(typeof(Func<TValue>));
318
+ }
319
+
183
320
  public static Func<TValue> GetStaticFieldGetter<TValue>(FieldInfo field)
184
321
  {
185
322
  if (!field.IsStatic)
@@ -187,7 +324,7 @@
187
324
  throw new ArgumentException(nameof(field));
188
325
  }
189
326
 
190
- #if WEB_GL
327
+ #if UNITY_WEBGL && !UNITY_EDITOR
191
328
  return Getter;
192
329
  TValue Getter()
193
330
  {
@@ -195,40 +332,40 @@
195
332
  }
196
333
  #else
197
334
  DynamicMethod dynamicMethod = new(
198
- $"GetGenericStatic{field.DeclaringType.Name}{field.Name}",
335
+ $"GetStatic_{field.DeclaringType.Name}_{field.Name}",
199
336
  typeof(TValue),
200
- Type.EmptyTypes, // no parameters needed for static fields
337
+ Type.EmptyTypes,
201
338
  field.DeclaringType,
202
339
  true
203
340
  );
204
341
 
205
342
  ILGenerator il = dynamicMethod.GetILGenerator();
206
343
 
207
- // Load the static field.
208
344
  il.Emit(OpCodes.Ldsfld, field);
209
345
 
210
- // Handle conversion from the field type to TValue.
211
- if (field.FieldType.IsValueType)
212
- {
213
- if (!typeof(TValue).IsValueType)
214
- {
215
- il.Emit(OpCodes.Box, field.FieldType);
216
- }
217
- }
218
- else
346
+ Type actualType = field.FieldType;
347
+ Type targetType = typeof(TValue);
348
+
349
+ if (actualType != targetType)
219
350
  {
220
- if (typeof(TValue).IsValueType)
351
+ if (actualType.IsValueType)
221
352
  {
222
- il.Emit(OpCodes.Unbox_Any, typeof(TValue));
353
+ il.Emit(OpCodes.Box, actualType);
354
+ if (targetType != typeof(object))
355
+ {
356
+ il.Emit(OpCodes.Castclass, targetType);
357
+ }
223
358
  }
224
- else if (typeof(TValue) != field.FieldType)
359
+ else
225
360
  {
226
- il.Emit(OpCodes.Castclass, typeof(TValue));
361
+ il.Emit(
362
+ targetType.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass,
363
+ targetType
364
+ );
227
365
  }
228
366
  }
229
367
 
230
368
  il.Emit(OpCodes.Ret);
231
-
232
369
  return (Func<TValue>)dynamicMethod.CreateDelegate(typeof(Func<TValue>));
233
370
  #endif
234
371
  }
@@ -237,7 +374,7 @@
237
374
  FieldInfo field
238
375
  )
239
376
  {
240
- #if WEB_GL
377
+ #if UNITY_WEBGL && !UNITY_EDITOR
241
378
  return Setter;
242
379
  void Setter(ref TInstance instance, TValue newValue)
243
380
  {
@@ -250,7 +387,7 @@
250
387
  Type valueType = field.FieldType;
251
388
 
252
389
  DynamicMethod dynamicMethod = new(
253
- $"SetFieldGeneric{field.DeclaringType.Name}{field.Name}",
390
+ $"SetFieldGeneric{field.DeclaringType.Name}_{field.Name}",
254
391
  MethodAttributes.Public | MethodAttributes.Static,
255
392
  CallingConventions.Standard,
256
393
  typeof(void),
@@ -281,7 +418,7 @@
281
418
  {
282
419
  throw new ArgumentException(nameof(field));
283
420
  }
284
- #if WEB_GL
421
+ #if UNITY_WEBGL && !UNITY_EDITOR
285
422
  return Setter;
286
423
  void Setter(TValue newValue)
287
424
  {
@@ -289,7 +426,7 @@
289
426
  }
290
427
  #else
291
428
  DynamicMethod dynamicMethod = new(
292
- $"SetFieldGenericStatic{field.DeclaringType.Name}{field.Name}",
429
+ $"SetFieldGenericStatic{field.DeclaringType.Name}_{field.Name}",
293
430
  typeof(void),
294
431
  new[] { typeof(TValue) },
295
432
  field.Module,
@@ -307,11 +444,11 @@
307
444
 
308
445
  public static Action<object, object> GetFieldSetter(FieldInfo field)
309
446
  {
310
- #if WEB_GL
447
+ #if UNITY_WEBGL && !UNITY_EDITOR
311
448
  return field.SetValue;
312
449
  #else
313
450
  DynamicMethod dynamicMethod = new(
314
- $"SetField{field.DeclaringType.Name}{field.Name}",
451
+ $"SetField{field.DeclaringType.Name}_{field.Name}",
315
452
  null,
316
453
  new[] { typeof(object), typeof(object) },
317
454
  field.DeclaringType.Module,
@@ -344,11 +481,11 @@
344
481
  {
345
482
  throw new ArgumentException(nameof(field));
346
483
  }
347
- #if WEB_GL
484
+ #if UNITY_WEBGL && !UNITY_EDITOR
348
485
  return value => field.SetValue(null, value);
349
486
  #else
350
487
  DynamicMethod dynamicMethod = new(
351
- $"SetFieldStatic{field.DeclaringType.Name}{field.Name}",
488
+ $"SetFieldStatic{field.DeclaringType.Name}_{field.Name}",
352
489
  null,
353
490
  new[] { typeof(object) },
354
491
  field.DeclaringType.Module,
@@ -374,7 +511,7 @@
374
511
 
375
512
  public static Func<int, Array> GetArrayCreator(Type elementType)
376
513
  {
377
- #if WEB_GL
514
+ #if UNITY_WEBGL && !UNITY_EDITOR
378
515
  return size => Array.CreateInstance(elementType, size);
379
516
  #else
380
517
  DynamicMethod dynamicMethod = new(
@@ -395,7 +532,7 @@
395
532
  public static Func<IList> GetListCreator(Type elementType)
396
533
  {
397
534
  Type listType = typeof(List<>).MakeGenericType(elementType);
398
- #if WEB_GL
535
+ #if UNITY_WEBGL && !UNITY_EDITOR
399
536
  return () => (IList)Activator.CreateInstance(listType);
400
537
  #else
401
538
  DynamicMethod dynamicMethod = new(
@@ -423,7 +560,7 @@
423
560
  public static Func<int, IList> GetListWithCapacityCreator(Type elementType)
424
561
  {
425
562
  Type listType = typeof(List<>).MakeGenericType(elementType);
426
- #if WEB_GL
563
+ #if UNITY_WEBGL && !UNITY_EDITOR
427
564
  return _ => (IList)Activator.CreateInstance(listType);
428
565
  #else
429
566
  DynamicMethod dynamicMethod = new(
@@ -1,18 +1,16 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using System;
4
4
  using System.Linq;
5
5
  using System.Threading.Tasks;
6
6
  using Extension;
7
+ using UnityEditor;
8
+ using UnityEditor.SceneManagement;
7
9
  using UnityEngine;
8
10
  using UnityEngine.Events;
9
11
  using UnityEngine.SceneManagement;
10
12
  using Utils;
11
13
  using Object = UnityEngine.Object;
12
- #if UNITY_EDITOR
13
- using UnityEditor;
14
- using UnityEditor.SceneManagement;
15
- #endif
16
14
 
17
15
  public static class SceneHelper
18
16
  {
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using Extension;
4
4
  using UnityEditor;
@@ -17,14 +17,14 @@
17
17
  string assetPath = AssetDatabase.GetAssetPath(texture);
18
18
  if (string.IsNullOrEmpty(assetPath))
19
19
  {
20
- texture.LogError("Failed to get asset path.");
20
+ texture.LogError($"Failed to get asset path.");
21
21
  return;
22
22
  }
23
23
 
24
24
  TextureImporter tImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
25
25
  if (tImporter == null)
26
26
  {
27
- texture.LogError("Failed to get texture importer.");
27
+ texture.LogError($"Failed to get texture importer.");
28
28
  return;
29
29
  }
30
30
 
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using System;
4
4
  using System.Reflection;
@@ -1,12 +1,10 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Concurrent;
5
+ using UnityEditor;
5
6
  using UnityEngine;
6
7
  using Utils;
7
- #if UNITY_EDITOR
8
- using UnityEditor;
9
- #endif
10
8
 
11
9
  [ExecuteAlways]
12
10
  public sealed class UnityMainThreadDispatcher : RuntimeSingleton<UnityMainThreadDispatcher>
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Helper
1
+ namespace WallstopStudios.UnityHelpers.Core.Helper
2
2
  {
3
3
  using System;
4
4
  using UnityEngine;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Math
1
+ namespace WallstopStudios.UnityHelpers.Core.Math
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Math
1
+ namespace WallstopStudios.UnityHelpers.Core.Math
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Math
1
+ namespace WallstopStudios.UnityHelpers.Core.Math
2
2
  {
3
3
  using UnityEngine;
4
4
 
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Math
1
+ namespace WallstopStudios.UnityHelpers.Core.Math
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Math
1
+ namespace WallstopStudios.UnityHelpers.Core.Math
2
2
  {
3
3
  using System.Runtime.CompilerServices;
4
4
  using System.Text;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Model
1
+ namespace WallstopStudios.UnityHelpers.Core.Model
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.OneOf
1
+ namespace WallstopStudios.UnityHelpers.Core.OneOf
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Generic;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.OneOf
1
+ namespace WallstopStudios.UnityHelpers.Core.OneOf
2
2
  {
3
3
  public readonly struct None { }
4
4
  }
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Concurrent;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Generic;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Text.Json.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
 
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  public static class PRNG
4
4
  {
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using Extension;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Linq;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using UnityEngine;
4
4
 
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.CompilerServices;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System.Threading;
4
4
 
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Diagnostics.CodeAnalysis;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.Serialization;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Random
1
+ namespace WallstopStudios.UnityHelpers.Core.Random
2
2
  {
3
3
  using System;
4
4
  using System.Runtime.CompilerServices;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Serialization.JsonConverters
1
+ namespace WallstopStudios.UnityHelpers.Core.Serialization.JsonConverters
2
2
  {
3
3
  using System;
4
4
  using System.Text.Json;
@@ -1,10 +1,9 @@
1
- namespace UnityHelpers.Core.Serialization.JsonConverters
1
+ namespace WallstopStudios.UnityHelpers.Core.Serialization.JsonConverters
2
2
  {
3
3
  using System;
4
4
  using System.Text.Json;
5
5
  using System.Text.Json.Serialization;
6
6
  using UnityEngine;
7
- using Object = UnityEngine.Object;
8
7
 
9
8
  public sealed class GameObjectConverter : JsonConverter<GameObject>
10
9
  {
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Serialization.JsonConverters
1
+ namespace WallstopStudios.UnityHelpers.Core.Serialization.JsonConverters
2
2
  {
3
3
  using System;
4
4
  using System.Text.Json;
@@ -1,4 +1,4 @@
1
- namespace UnityHelpers.Core.Serialization.JsonConverters
1
+ namespace WallstopStudios.UnityHelpers.Core.Serialization.JsonConverters
2
2
  {
3
3
  using System;
4
4
  using System.Text.Json;