com.wallstop-studios.unity-helpers 2.0.0-rc22 → 2.0.0-rc24

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 (60) hide show
  1. package/Editor/AnimationCopier.cs +39 -10
  2. package/Editor/AnimationCreator.cs +68 -24
  3. package/Editor/AnimationEventEditor.cs +206 -79
  4. package/Editor/AnimatorControllerCopier.cs +42 -14
  5. package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +5 -2
  6. package/Editor/PrefabCheckWizard.cs +37 -14
  7. package/Editor/SpriteSettingsApplier.cs +23 -9
  8. package/Editor/TextureResizerWizard.cs +37 -14
  9. package/Editor/TextureSettingsApplier.cs +23 -10
  10. package/Editor/Utils/EditorUtilities.cs +4 -2
  11. package/Editor/Utils/ReadOnlyPropertyDrawer.cs +2 -4
  12. package/README.md +10 -0
  13. package/Runtime/Core/Attributes/AnimationEventAttribute.cs +52 -23
  14. package/Runtime/Core/Attributes/KSerializableAttribute.cs +2 -6
  15. package/Runtime/Core/Attributes/NotNullAttribute.cs +3 -4
  16. package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +1 -3
  17. package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +12 -6
  18. package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +1 -0
  19. package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +13 -8
  20. package/Runtime/Core/DataStructure/Adapters/KGuid.cs +24 -7
  21. package/Runtime/Core/DataStructure/Adapters/KVector2.cs +1 -0
  22. package/Runtime/Core/DataStructure/Circle.cs +1 -1
  23. package/Runtime/Core/DataStructure/CyclicBuffer.cs +45 -49
  24. package/Runtime/Core/DataStructure/ISpatialTree.cs +22 -20
  25. package/Runtime/Core/DataStructure/StringWrapper.cs +1 -0
  26. package/Runtime/Core/Extension/CircleExtensions.cs +2 -2
  27. package/Runtime/Core/Extension/DictionaryExtensions.cs +62 -17
  28. package/Runtime/Core/Extension/StringExtensions.cs +30 -10
  29. package/Runtime/Core/Helper/Enumerables.cs +1 -1
  30. package/Runtime/Core/Helper/LifetimeHelpers.cs +2 -1
  31. package/Runtime/Core/Math/Line.cs +1 -1
  32. package/Runtime/Core/Math/Parabola.cs +4 -2
  33. package/Runtime/Core/Math/PointPolygonCheck.cs +12 -5
  34. package/Runtime/Core/Math/Range.cs +9 -8
  35. package/Runtime/Core/Math/XXHash.cs +22 -20
  36. package/Runtime/Core/Model/Direction.cs +26 -9
  37. package/Runtime/Core/OneOf/FastOneOf.cs +11 -4
  38. package/Runtime/Core/OneOf/None.cs +1 -3
  39. package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +13 -4
  40. package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +15 -5
  41. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +2 -3
  42. package/Runtime/Utils/AnimationEventEqualityComparer.cs +22 -10
  43. package/Runtime/Utils/AnimatorEnumStateMachine.cs +3 -4
  44. package/Runtime/Utils/Buffers.cs +1 -1
  45. package/Runtime/Utils/CenterPointOffset.cs +1 -2
  46. package/Runtime/Utils/CoroutineHandler.cs +1 -1
  47. package/Runtime/Utils/Oscillator.cs +4 -2
  48. package/Runtime/Utils/SetTextureImportData.cs +1 -1
  49. package/Runtime/Utils/SpriteRendererSyncer.cs +5 -3
  50. package/Runtime/Utils/TextureScale.cs +21 -6
  51. package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +1 -1
  52. package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +213 -0
  53. package/Tests/Runtime/DataStructures/CyclicBufferTests.cs.meta +3 -0
  54. package/Tests/Runtime/DataStructures/QuadTreeTests.cs +1 -1
  55. package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +1 -1
  56. package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +41 -21
  57. package/Tests/Runtime/Extensions/StringExtensionTests.cs +1 -1
  58. package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +1 -1
  59. package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +1 -1
  60. package/package.json +3 -2
@@ -0,0 +1,213 @@
1
+ namespace UnityHelpers.Tests.DataStructures
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using Core.DataStructure;
7
+ using Core.Random;
8
+ using NUnit.Framework;
9
+
10
+ public sealed class CyclicBufferTests
11
+ {
12
+ private const int NumTries = 100;
13
+ private const int CapacityMultiplier = 3;
14
+
15
+ [Test]
16
+ public void InvalidCapacity()
17
+ {
18
+ Assert.Throws<ArgumentException>(() => new CyclicBuffer<int>(-1));
19
+ Assert.Throws<ArgumentException>(() => new CyclicBuffer<int>(int.MinValue));
20
+ for (int i = 0; i < NumTries; i++)
21
+ {
22
+ Assert.Throws<ArgumentException>(
23
+ () => new CyclicBuffer<int>(PRNG.Instance.Next(int.MinValue, -1))
24
+ );
25
+ }
26
+ }
27
+
28
+ [Test]
29
+ public void CapacityInitializedOk()
30
+ {
31
+ for (int i = 0; i < NumTries; i++)
32
+ {
33
+ int capacity = PRNG.Instance.Next(1, int.MaxValue);
34
+ CyclicBuffer<int> buffer = new(capacity);
35
+ Assert.AreEqual(capacity, buffer.capacity);
36
+ }
37
+ }
38
+
39
+ [Test]
40
+ public void CountInitializedOk()
41
+ {
42
+ for (int i = 0; i < NumTries; i++)
43
+ {
44
+ int capacity = PRNG.Instance.Next(1, int.MaxValue);
45
+ CyclicBuffer<int> buffer = new(capacity);
46
+ Assert.AreEqual(0, buffer.Count);
47
+ }
48
+ }
49
+
50
+ [Test]
51
+ public void ZeroCapacityOk()
52
+ {
53
+ CyclicBuffer<int> buffer = new(0);
54
+ CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
55
+ for (int i = 0; i < NumTries; ++i)
56
+ {
57
+ buffer.Add(PRNG.Instance.Next());
58
+ CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
59
+ }
60
+ }
61
+
62
+ [Test]
63
+ public void IntMaxCapacityOk()
64
+ {
65
+ CyclicBuffer<int> buffer = new(int.MaxValue);
66
+ CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
67
+ const int tries = 50;
68
+ List<int> expected = new(tries);
69
+ for (int i = 0; i < tries; ++i)
70
+ {
71
+ int value = PRNG.Instance.Next();
72
+ buffer.Add(value);
73
+ expected.Add(value);
74
+ if (!expected.SequenceEqual(buffer))
75
+ {
76
+ Assert.Fail(
77
+ $"Failure at iteration {i}, capacity={buffer.capacity}, "
78
+ + $"capacityMultiplier={CapacityMultiplier}\n"
79
+ + $"Expected: [{string.Join(",", expected)}], Actual: [{string.Join(",", buffer)}]"
80
+ );
81
+ }
82
+ }
83
+ }
84
+
85
+ [Test]
86
+ public void OneCapacityOk()
87
+ {
88
+ CyclicBuffer<int> buffer = new(1);
89
+ CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
90
+ int[] expected = new int[1];
91
+ for (int i = 0; i < NumTries; ++i)
92
+ {
93
+ int value = PRNG.Instance.Next();
94
+ buffer.Add(value);
95
+ expected[0] = value;
96
+ CollectionAssert.AreEquivalent(expected, buffer);
97
+ }
98
+ }
99
+
100
+ [Test]
101
+ public void InitialElementsVariableSize()
102
+ {
103
+ for (int i = 0; i < NumTries; ++i)
104
+ {
105
+ int capacity = PRNG.Instance.Next(100, 1_000);
106
+ int[] elements = Enumerable
107
+ .Range(0, (int)(capacity * PRNG.Instance.NextFloat(0.5f, 1.5f)))
108
+ .Select(_ => PRNG.Instance.Next())
109
+ .ToArray();
110
+ CyclicBuffer<int> buffer = new(capacity, elements);
111
+ if (capacity < elements.Length)
112
+ {
113
+ Assert.IsTrue(elements.Skip(elements.Length - capacity).SequenceEqual(buffer));
114
+ }
115
+ else
116
+ {
117
+ Assert.IsTrue(elements.SequenceEqual(buffer));
118
+ }
119
+ }
120
+ }
121
+
122
+ [Test]
123
+ public void InitialElementsSizeSameAsCapacity()
124
+ {
125
+ for (int i = 0; i < NumTries; ++i)
126
+ {
127
+ int capacity = PRNG.Instance.Next(100, 1_000);
128
+ int[] elements = Enumerable
129
+ .Range(0, capacity)
130
+ .Select(_ => PRNG.Instance.Next())
131
+ .ToArray();
132
+ CyclicBuffer<int> buffer = new(capacity, elements);
133
+ Assert.IsTrue(elements.SequenceEqual(buffer));
134
+ }
135
+ }
136
+
137
+ [Test]
138
+ public void InitialElementsEmptyInput()
139
+ {
140
+ for (int i = 0; i < NumTries; ++i)
141
+ {
142
+ int capacity = PRNG.Instance.Next(100, 1_000);
143
+ CyclicBuffer<int> buffer = new(capacity, Array.Empty<int>());
144
+ Assert.IsTrue(Array.Empty<int>().SequenceEqual(buffer));
145
+ }
146
+ }
147
+
148
+ [Test]
149
+ public void NormalAndWrappingBehavior()
150
+ {
151
+ LinkedList<int> expected = new();
152
+ for (int i = 0; i < NumTries; ++i)
153
+ {
154
+ int capacity = PRNG.Instance.Next(100, 1_000);
155
+ CyclicBuffer<int> buffer = new(capacity);
156
+ CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
157
+ expected.Clear();
158
+ for (int j = 0; j < capacity * CapacityMultiplier; ++j)
159
+ {
160
+ int newValue = PRNG.Instance.Next();
161
+ expected.AddLast(newValue);
162
+ while (capacity < expected.Count)
163
+ {
164
+ expected.RemoveFirst();
165
+ }
166
+ buffer.Add(newValue);
167
+ Assert.AreEqual(expected.Count, buffer.Count);
168
+ if (!expected.SequenceEqual(buffer))
169
+ {
170
+ Assert.Fail(
171
+ $"Failure at iteration {i}, j={j}, capacity={buffer.capacity}, "
172
+ + $"capacityMultiplier={CapacityMultiplier}\n"
173
+ + $"Expected: [{string.Join(",", expected)}], Actual: [{string.Join(",", buffer)}]"
174
+ );
175
+ }
176
+ }
177
+
178
+ foreach (int item in expected)
179
+ {
180
+ Assert.IsTrue(buffer.Contains(item));
181
+ }
182
+
183
+ for (int j = 0; j < NumTries; ++j)
184
+ {
185
+ Assert.IsFalse(buffer.Contains(PRNG.Instance.Next(int.MinValue, -1)));
186
+ }
187
+ }
188
+ }
189
+
190
+ [Test]
191
+ public void ClearOk()
192
+ {
193
+ for (int i = 0; i < NumTries; ++i)
194
+ {
195
+ int capacity = PRNG.Instance.Next(100, 1_000);
196
+ CyclicBuffer<int> buffer = new(capacity);
197
+ float fillPercent = PRNG.Instance.NextFloat(0.5f, 1.5f);
198
+ for (int j = 0; j < capacity * fillPercent; ++j)
199
+ {
200
+ buffer.Add(PRNG.Instance.Next());
201
+ }
202
+
203
+ Assert.AreNotEqual(0, buffer.Count);
204
+ Assert.IsFalse(Array.Empty<int>().SequenceEqual(buffer));
205
+ buffer.Clear();
206
+
207
+ Assert.AreEqual(0, buffer.Count);
208
+ Assert.AreEqual(capacity, buffer.capacity);
209
+ Assert.IsTrue(Array.Empty<int>().SequenceEqual(buffer));
210
+ }
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: e6e1c3d02ef74aabb922aa776a8648f0
3
+ timeCreated: 1740364919
@@ -1,8 +1,8 @@
1
1
  namespace UnityHelpers.Tests.DataStructures
2
2
  {
3
3
  using System.Collections.Generic;
4
- using UnityEngine;
5
4
  using Core.DataStructure;
5
+ using UnityEngine;
6
6
 
7
7
  public sealed class QuadTreeTests : SpatialTreeTests<QuadTree<Vector2>>
8
8
  {
@@ -1,8 +1,8 @@
1
1
  namespace UnityHelpers.Tests.DataStructures
2
2
  {
3
3
  using System.Collections.Generic;
4
- using UnityEngine;
5
4
  using Core.DataStructure;
5
+ using UnityEngine;
6
6
 
7
7
  public sealed class UnbalancedKDTreeTests : SpatialTreeTests<KDTree<Vector2>>
8
8
  {
@@ -17,11 +17,13 @@
17
17
  Assert.AreEqual(value, dictionary["test"]);
18
18
 
19
19
  int newValue = dictionary.GetOrAdd(
20
- "test", () =>
20
+ "test",
21
+ () =>
21
22
  {
22
23
  Assert.Fail("Value Producer should not have been called!");
23
24
  return 200;
24
- });
25
+ }
26
+ );
25
27
  Assert.AreEqual(100, newValue);
26
28
 
27
29
  newValue = dictionary.GetOrAdd("test2", () => 300);
@@ -34,28 +36,34 @@
34
36
  {
35
37
  Dictionary<string, int> dictionary = new();
36
38
  int value = dictionary.GetOrAdd(
37
- "test", key =>
39
+ "test",
40
+ key =>
38
41
  {
39
42
  Assert.AreEqual("test", key);
40
43
  return 100;
41
- });
44
+ }
45
+ );
42
46
  Assert.AreEqual(100, value);
43
47
  Assert.AreEqual(value, dictionary["test"]);
44
48
 
45
49
  int newValue = dictionary.GetOrAdd(
46
- "test", key =>
50
+ "test",
51
+ key =>
47
52
  {
48
53
  Assert.Fail("Value Producer should not have been called!");
49
54
  return 200;
50
- });
55
+ }
56
+ );
51
57
  Assert.AreEqual(100, newValue);
52
58
 
53
59
  newValue = dictionary.GetOrAdd(
54
- "test2", key =>
60
+ "test2",
61
+ key =>
55
62
  {
56
63
  Assert.AreEqual("test2", key);
57
64
  return 300;
58
- });
65
+ }
66
+ );
59
67
  Assert.AreEqual(300, newValue);
60
68
  Assert.AreEqual(100, dictionary["test"]);
61
69
  }
@@ -82,11 +90,13 @@
82
90
  Assert.IsFalse(dictionary.ContainsKey("test"));
83
91
  dictionary["test"] = 150;
84
92
  value = dictionary.GetOrElse(
85
- "test", () =>
93
+ "test",
94
+ () =>
86
95
  {
87
96
  Assert.Fail("Producer should not be called.");
88
97
  return 100;
89
- });
98
+ }
99
+ );
90
100
  Assert.AreEqual(150, value);
91
101
  Assert.AreEqual(150, dictionary["test"]);
92
102
  }
@@ -96,20 +106,24 @@
96
106
  {
97
107
  Dictionary<string, int> dictionary = new();
98
108
  int value = dictionary.GetOrElse(
99
- "test", key =>
109
+ "test",
110
+ key =>
100
111
  {
101
112
  Assert.AreEqual("test", key);
102
113
  return 100;
103
- });
114
+ }
115
+ );
104
116
  Assert.AreEqual(100, value);
105
117
  Assert.IsFalse(dictionary.ContainsKey("test"));
106
118
  dictionary["test"] = 150;
107
119
  value = dictionary.GetOrElse(
108
- "test", () =>
120
+ "test",
121
+ () =>
109
122
  {
110
123
  Assert.Fail("Producer should not be called.");
111
124
  return 100;
112
- });
125
+ }
126
+ );
113
127
  Assert.AreEqual(150, value);
114
128
  Assert.AreEqual(150, dictionary["test"]);
115
129
  }
@@ -162,29 +176,35 @@
162
176
  {
163
177
  Dictionary<string, int> dictionary = new();
164
178
  int value = dictionary.TryAdd(
165
- "test", key =>
179
+ "test",
180
+ key =>
166
181
  {
167
182
  Assert.AreEqual("test", key);
168
183
  return 150;
169
- });
184
+ }
185
+ );
170
186
  Assert.AreEqual(150, value);
171
187
  Assert.AreEqual(value, dictionary["test"]);
172
188
 
173
189
  value = dictionary.TryAdd(
174
- "test", key =>
190
+ "test",
191
+ key =>
175
192
  {
176
193
  Assert.Fail("Creator should not have been called.");
177
194
  return 200;
178
- });
195
+ }
196
+ );
179
197
  Assert.AreEqual(150, value);
180
198
  Assert.AreEqual(value, dictionary["test"]);
181
199
 
182
200
  value = dictionary.TryAdd(
183
- "test2", key =>
201
+ "test2",
202
+ key =>
184
203
  {
185
204
  Assert.AreEqual("test2", key);
186
205
  return 350;
187
- });
206
+ }
207
+ );
188
208
  Assert.AreEqual(350, value);
189
209
  Assert.AreEqual(value, dictionary["test2"]);
190
210
  Assert.AreEqual(150, dictionary["test"]);
@@ -416,4 +436,4 @@
416
436
  Assert.AreEqual(1, value);
417
437
  }
418
438
  }
419
- }
439
+ }
@@ -28,4 +28,4 @@
28
28
  Assert.AreEqual("Pascal.Case", " __Pascal____ ___Case__ ".ToPascalCase(separator));
29
29
  }
30
30
  }
31
- }
31
+ }
@@ -1,8 +1,8 @@
1
1
  namespace UnityHelpers.Tests.Performance
2
2
  {
3
3
  using System.Collections.Generic;
4
- using UnityEngine;
5
4
  using Core.DataStructure;
5
+ using UnityEngine;
6
6
 
7
7
  public sealed class QuadTreePerformanceTests : SpatialTreePerformanceTest<QuadTree<Vector2>>
8
8
  {
@@ -1,8 +1,8 @@
1
1
  namespace UnityHelpers.Tests.Performance
2
2
  {
3
3
  using System.Collections.Generic;
4
- using UnityEngine;
5
4
  using Core.DataStructure;
5
+ using UnityEngine;
6
6
 
7
7
  public sealed class UnbalancedKDTreeTests : SpatialTreePerformanceTest<KDTree<Vector2>>
8
8
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.unity-helpers",
3
- "version": "2.0.0-rc22",
3
+ "version": "2.0.0-rc24",
4
4
  "displayName": "Unity Helpers",
5
5
  "description": "Various Unity Helper Library",
6
6
  "dependencies": {},
@@ -18,7 +18,8 @@
18
18
  "rtree",
19
19
  "r tree",
20
20
  "kd tree",
21
- "kdtree"
21
+ "kdtree",
22
+ "cyclic buffer"
22
23
  ],
23
24
  "license": "MIT",
24
25
  "repository": {