com.wallstop-studios.unity-helpers 2.0.0-rc64 → 2.0.0-rc66

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
- namespace WallstopStudios.UnityHelpers.Core.Helper
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
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 UNITY_WEBGL && !UNITY_EDITOR
564
+ #if !EMIT_DYNAMIC_IL
564
565
  return _ => (IList)Activator.CreateInstance(listType);
565
566
  #else
566
567
  DynamicMethod dynamicMethod = new(
@@ -0,0 +1,87 @@
1
+ namespace WallstopStudios.UnityHelpers.Utils
2
+ {
3
+ using System.Collections.Generic;
4
+ using Core.Extension;
5
+ using UnityEngine;
6
+
7
+ [DisallowMultipleComponent]
8
+ public class TagHandler : MonoBehaviour
9
+ {
10
+ [SerializeField]
11
+ protected List<string> _initialEffectTags = new();
12
+
13
+ protected readonly Dictionary<string, uint> _tagCount = new();
14
+
15
+ protected virtual void Awake()
16
+ {
17
+ if (_initialEffectTags is { Count: > 0 })
18
+ {
19
+ foreach (string effectTag in _initialEffectTags)
20
+ {
21
+ InternalApplyTag(effectTag);
22
+ }
23
+ }
24
+ }
25
+
26
+ public bool HasTag(string effectTag)
27
+ {
28
+ return _tagCount.ContainsKey(effectTag);
29
+ }
30
+
31
+ public bool HasAnyTag(IEnumerable<string> effectTags)
32
+ {
33
+ foreach (string effectTag in effectTags)
34
+ {
35
+ bool hasTag = _tagCount.ContainsKey(effectTag);
36
+ if (hasTag)
37
+ {
38
+ return true;
39
+ }
40
+ }
41
+
42
+ return false;
43
+ }
44
+
45
+ public bool HasAnyTag(IReadOnlyList<string> effectTags)
46
+ {
47
+ for (int i = 0; i < effectTags.Count; ++i)
48
+ {
49
+ string effectTag = effectTags[i];
50
+ bool hasTag = _tagCount.ContainsKey(effectTag);
51
+ if (hasTag)
52
+ {
53
+ return true;
54
+ }
55
+ }
56
+
57
+ return false;
58
+ }
59
+
60
+ private void InternalApplyTag(string effectTag)
61
+ {
62
+ _ = _tagCount.AddOrUpdate(effectTag, _ => 1U, (_, existing) => existing + 1);
63
+ }
64
+
65
+ private void InternalRemoveTag(string effectTag)
66
+ {
67
+ if (!_tagCount.TryGetValue(effectTag, out uint count))
68
+ {
69
+ return;
70
+ }
71
+
72
+ if (count != 0)
73
+ {
74
+ --count;
75
+ }
76
+
77
+ if (count == 0)
78
+ {
79
+ _ = _tagCount.Remove(effectTag);
80
+ }
81
+ else
82
+ {
83
+ _tagCount[effectTag] = count;
84
+ }
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 43799f39670a40f3b2f75e861c2a7256
3
+ timeCreated: 1746393282
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc64",
3
+ "version": "2.0.0-rc66",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},