com.wallstop-studios.unity-helpers 2.0.0-rc65 → 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.
@@ -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-rc65",
3
+ "version": "2.0.0-rc66",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},