com.wallstop-studios.unity-helpers 2.0.0-rc75.1 → 2.0.0-rc75.3

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.
@@ -711,48 +711,6 @@
711
711
  Repaint();
712
712
  }
713
713
 
714
- private static string GetRelativeAssetPath(string fullPath)
715
- {
716
- if (string.IsNullOrWhiteSpace(fullPath))
717
- {
718
- return null;
719
- }
720
-
721
- fullPath = fullPath.SanitizePath();
722
- if (
723
- fullPath.EndsWith("/Assets", StringComparison.OrdinalIgnoreCase)
724
- && Path.GetFileName(fullPath).Equals("Assets", StringComparison.OrdinalIgnoreCase)
725
- )
726
- {
727
- return "Assets";
728
- }
729
-
730
- string assetsPath = Application.dataPath.SanitizePath();
731
- if (fullPath.StartsWith(assetsPath, StringComparison.OrdinalIgnoreCase))
732
- {
733
- if (fullPath.Length == assetsPath.Length)
734
- {
735
- return "Assets";
736
- }
737
-
738
- int startIndex = assetsPath.Length;
739
- if (fullPath.Length > startIndex && fullPath[startIndex] == '/')
740
- {
741
- startIndex++;
742
- }
743
-
744
- return "Assets/" + fullPath.Substring(startIndex);
745
- }
746
-
747
- int assetIndex = fullPath.IndexOf("/Assets/", StringComparison.OrdinalIgnoreCase);
748
- if (assetIndex >= 0)
749
- {
750
- return fullPath.Substring(assetIndex + 1);
751
- }
752
-
753
- return null;
754
- }
755
-
756
714
  private static string GetFullPathFromRelative(string relativePath)
757
715
  {
758
716
  if (string.IsNullOrWhiteSpace(relativePath))
@@ -804,10 +762,10 @@
804
762
  {
805
763
  try
806
764
  {
807
- using MD5 md5 = MD5.Create();
765
+ using SHA256 hashProvider = SHA256.Create();
808
766
  using FileStream stream = File.OpenRead(filePath);
809
- byte[] hashBytes = md5.ComputeHash(stream);
810
- return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
767
+ byte[] hash = hashProvider.ComputeHash(stream);
768
+ return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
811
769
  }
812
770
  catch (IOException ioEx)
813
771
  {
@@ -16,10 +16,10 @@
16
16
  [Serializable]
17
17
  public sealed class AnimationData
18
18
  {
19
- public const int DefaultFramesPerSecond = 12;
19
+ public const float DefaultFramesPerSecond = 12;
20
20
 
21
21
  public List<Sprite> frames = new();
22
- public int framesPerSecond = DefaultFramesPerSecond;
22
+ public float framesPerSecond = DefaultFramesPerSecond;
23
23
  public string animationName = string.Empty;
24
24
  public bool isCreatedFromAutoParse;
25
25
  public bool loop;
@@ -457,7 +457,7 @@
457
457
  (float)currentAnimationIndex / totalAnimations
458
458
  );
459
459
 
460
- int framesPerSecond = data.framesPerSecond;
460
+ float framesPerSecond = data.framesPerSecond;
461
461
  if (framesPerSecond <= 0)
462
462
  {
463
463
  this.LogWarn(
@@ -1,7 +1,7 @@
1
1
  namespace WallstopStudios.UnityHelpers.Tags
2
2
  {
3
3
  using System;
4
- using Core.DataStructure.Adapters;
4
+ using System.Threading;
5
5
  using Core.Extension;
6
6
 
7
7
  [Serializable]
@@ -10,16 +10,18 @@
10
10
  IComparable<EffectHandle>,
11
11
  IComparable
12
12
  {
13
+ private static long Id;
14
+
13
15
  public readonly AttributeEffect effect;
14
16
 
15
- public readonly KGuid id;
17
+ public readonly long id;
16
18
 
17
19
  public static EffectHandle CreateInstance(AttributeEffect effect)
18
20
  {
19
- return new EffectHandle(Guid.NewGuid(), effect);
21
+ return new EffectHandle(Interlocked.Increment(ref Id), effect);
20
22
  }
21
23
 
22
- private EffectHandle(KGuid id, AttributeEffect effect)
24
+ private EffectHandle(long id, AttributeEffect effect)
23
25
  {
24
26
  this.id = id;
25
27
  this.effect = effect;
@@ -1,9 +1,9 @@
1
1
  namespace WallstopStudios.UnityHelpers.Tags
2
2
  {
3
+ using System;
3
4
  using System.Collections.Generic;
4
5
  using System.Linq;
5
6
  using Core.Attributes;
6
- using Core.DataStructure.Adapters;
7
7
  using Core.Extension;
8
8
  using Core.Helper;
9
9
  using UnityEngine;
@@ -13,7 +13,10 @@
13
13
  [RequireComponent(typeof(TagHandler))]
14
14
  public sealed class EffectHandler : MonoBehaviour
15
15
  {
16
- [SiblingComponent()]
16
+ public event Action<EffectHandle> OnEffectApplied;
17
+ public event Action<EffectHandle> OnEffectRemoved;
18
+
19
+ [SiblingComponent]
17
20
  private TagHandler _tagHandler;
18
21
 
19
22
  [SiblingComponent(optional = true)]
@@ -26,11 +29,11 @@
26
29
  > _instancedCosmeticEffects = new();
27
30
 
28
31
  // Stores expiration time of duration effects (We store by Id because it's much cheaper to iterate Guids than it is EffectHandles
29
- private readonly Dictionary<KGuid, float> _effectExpirations = new();
30
- private readonly Dictionary<KGuid, EffectHandle> _effectHandlesById = new();
32
+ private readonly Dictionary<long, float> _effectExpirations = new();
33
+ private readonly Dictionary<long, EffectHandle> _effectHandlesById = new();
31
34
 
32
35
  // Used only to save allocations in Update()
33
- private readonly List<KGuid> _expiredEffectIds = new();
36
+ private readonly List<long> _expiredEffectIds = new();
34
37
  private readonly List<EffectHandle> _appliedEffects = new();
35
38
 
36
39
  private bool _initialized;
@@ -77,7 +80,7 @@
77
80
  && (effect.resetDurationOnReapplication || !_appliedEffects.Contains(handle))
78
81
  )
79
82
  {
80
- KGuid handleId = handle.id;
83
+ long handleId = handle.id;
81
84
  _effectExpirations[handleId] = Time.time + effect.duration;
82
85
  _effectHandlesById[handleId] = handle;
83
86
  }
@@ -123,10 +126,11 @@
123
126
  _ = _tagHandler.ForceRemoveTags(handle);
124
127
  }
125
128
 
126
- KGuid handleId = handle.id;
129
+ long handleId = handle.id;
127
130
  _ = _effectExpirations.Remove(handleId);
128
131
  _ = _effectHandlesById.Remove(handleId);
129
132
  InternalRemoveCosmeticEffects(handle);
133
+ OnEffectRemoved?.Invoke(handle);
130
134
  }
131
135
 
132
136
  private void InternalApplyEffect(EffectHandle handle)
@@ -142,7 +146,7 @@
142
146
  {
143
147
  if (effect.resetDurationOnReapplication || !exists)
144
148
  {
145
- KGuid handleId = handle.id;
149
+ long handleId = handle.id;
146
150
  _effectExpirations[handleId] = Time.time + effect.duration;
147
151
  _effectHandlesById[handleId] = handle;
148
152
  }
@@ -170,6 +174,8 @@
170
174
  attributesComponent.ForceApplyAttributeModifications(handle);
171
175
  }
172
176
  }
177
+
178
+ OnEffectApplied?.Invoke(handle);
173
179
  }
174
180
 
175
181
  private void InternalApplyEffect(AttributeEffect effect)
@@ -360,7 +366,7 @@
360
366
 
361
367
  _expiredEffectIds.Clear();
362
368
  float currentTime = Time.time;
363
- foreach (KeyValuePair<KGuid, float> entry in _effectExpirations)
369
+ foreach (KeyValuePair<long, float> entry in _effectExpirations)
364
370
  {
365
371
  if (entry.Value < currentTime)
366
372
  {
@@ -368,7 +374,7 @@
368
374
  }
369
375
  }
370
376
 
371
- foreach (KGuid expiredHandleId in _expiredEffectIds)
377
+ foreach (long expiredHandleId in _expiredEffectIds)
372
378
  {
373
379
  if (_effectHandlesById.TryGetValue(expiredHandleId, out EffectHandle expiredHandle))
374
380
  {
@@ -2,20 +2,23 @@
2
2
  {
3
3
  using System;
4
4
  using System.Collections.Generic;
5
- using Core.DataStructure.Adapters;
6
5
  using Core.Extension;
7
6
  using UnityEngine;
8
7
 
9
8
  [DisallowMultipleComponent]
10
9
  public sealed class TagHandler : MonoBehaviour
11
10
  {
11
+ public event Action<string> OnTagAdded;
12
+ public event Action<string> OnTagRemoved;
13
+ public event Action<string, uint> OnTagCountChanged;
14
+
12
15
  public IReadOnlyCollection<string> Tags => _tagCount.Keys;
13
16
 
14
17
  [SerializeField]
15
18
  private List<string> _initialEffectTags = new();
16
19
 
17
20
  private readonly Dictionary<string, uint> _tagCount = new(StringComparer.Ordinal);
18
- private readonly Dictionary<KGuid, EffectHandle> _effectHandles = new();
21
+ private readonly Dictionary<long, EffectHandle> _effectHandles = new();
19
22
 
20
23
  private void Awake()
21
24
  {
@@ -78,7 +81,7 @@
78
81
 
79
82
  public void ForceApplyTags(EffectHandle handle)
80
83
  {
81
- KGuid id = handle.id;
84
+ long id = handle.id;
82
85
  if (!_effectHandles.TryAdd(id, handle))
83
86
  {
84
87
  return;
@@ -97,7 +100,7 @@
97
100
 
98
101
  public bool ForceRemoveTags(EffectHandle handle)
99
102
  {
100
- KGuid id = handle.id;
103
+ long id = handle.id;
101
104
  if (!_effectHandles.Remove(id, out EffectHandle appliedHandle))
102
105
  {
103
106
  return false;
@@ -113,7 +116,19 @@
113
116
 
114
117
  private void InternalApplyTag(string effectTag)
115
118
  {
116
- _ = _tagCount.AddOrUpdate(effectTag, _ => 1U, (_, existing) => existing + 1);
119
+ uint currentCount = _tagCount.AddOrUpdate(
120
+ effectTag,
121
+ _ => 1U,
122
+ (_, existing) => existing + 1
123
+ );
124
+ if (currentCount == 1)
125
+ {
126
+ OnTagAdded?.Invoke(effectTag);
127
+ }
128
+ else
129
+ {
130
+ OnTagCountChanged?.Invoke(effectTag, currentCount);
131
+ }
117
132
  }
118
133
 
119
134
  private void InternalRemoveTag(string effectTag)
@@ -131,10 +146,12 @@
131
146
  if (count == 0)
132
147
  {
133
148
  _ = _tagCount.Remove(effectTag);
149
+ OnTagRemoved?.Invoke(effectTag);
134
150
  }
135
151
  else
136
152
  {
137
153
  _tagCount[effectTag] = count;
154
+ OnTagCountChanged?.Invoke(effectTag, count);
138
155
  }
139
156
  }
140
157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc75.1",
3
+ "version": "2.0.0-rc75.3",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -64,6 +64,8 @@
64
64
 
65
65
 
66
66
 
67
+
68
+
67
69
 
68
70
 
69
71