com.wallstop-studios.unity-helpers 2.0.0-rc21 → 2.0.0-rc23
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.
- package/Editor/AnimationCopier.cs +39 -10
- package/Editor/AnimationCreator.cs +68 -24
- package/Editor/AnimationEventEditor.cs +206 -79
- package/Editor/AnimatorControllerCopier.cs +42 -14
- package/Editor/CustomEditors/MatchColliderToSpriteEditor.cs +5 -2
- package/Editor/PrefabCheckWizard.cs +37 -14
- package/Editor/SpriteSettingsApplier.cs +23 -9
- package/Editor/TextureResizerWizard.cs +37 -14
- package/Editor/TextureSettingsApplier.cs +23 -10
- package/Editor/Utils/EditorUtilities.cs +4 -2
- package/Editor/Utils/ReadOnlyPropertyDrawer.cs +2 -4
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs +52 -23
- package/Runtime/Core/Attributes/KSerializableAttribute.cs +2 -6
- package/Runtime/Core/Attributes/NotNullAttribute.cs +3 -4
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +1 -3
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +12 -6
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +1 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +13 -8
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs +24 -7
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs +1 -0
- package/Runtime/Core/DataStructure/Circle.cs +1 -1
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +42 -44
- package/Runtime/Core/DataStructure/ISpatialTree.cs +22 -20
- package/Runtime/Core/Extension/CircleExtensions.cs +2 -2
- package/Runtime/Core/Extension/DictionaryExtensions.cs +62 -17
- package/Runtime/Core/Extension/StringExtensions.cs +30 -10
- package/Runtime/Core/Helper/Enumerables.cs +1 -1
- package/Runtime/Core/Helper/LifetimeHelpers.cs +2 -1
- package/Runtime/Core/Math/Line.cs +1 -1
- package/Runtime/Core/Math/Parabola.cs +4 -2
- package/Runtime/Core/Math/PointPolygonCheck.cs +12 -5
- package/Runtime/Core/Math/Range.cs +9 -8
- package/Runtime/Core/Math/XXHash.cs +22 -20
- package/Runtime/Core/Model/Direction.cs +26 -9
- package/Runtime/Core/OneOf/FastOneOf.cs +11 -4
- package/Runtime/Core/OneOf/None.cs +1 -3
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +13 -4
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +15 -5
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +2 -3
- package/Runtime/Utils/AnimationEventEqualityComparer.cs +22 -10
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +3 -4
- package/Runtime/Utils/Buffers.cs +1 -1
- package/Runtime/Utils/CenterPointOffset.cs +1 -2
- package/Runtime/Utils/CoroutineHandler.cs +1 -1
- package/Runtime/Utils/Oscillator.cs +4 -2
- package/Runtime/Utils/SetTextureImportData.cs +1 -1
- package/Runtime/Utils/SpriteRendererMetadata.cs +56 -17
- package/Runtime/Utils/SpriteRendererSyncer.cs +5 -3
- package/Runtime/Utils/TextureScale.cs +21 -6
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/CyclicBufferTests.cs +101 -0
- package/Tests/Runtime/DataStructures/CyclicBufferTests.cs.meta +3 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +1 -1
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +1 -1
- package/Tests/Runtime/Extensions/DictionaryExtensionTests.cs +41 -21
- package/Tests/Runtime/Extensions/StringExtensionTests.cs +1 -1
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +1 -1
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,101 @@
|
|
|
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 ZeroCapacityOk()
|
|
30
|
+
{
|
|
31
|
+
CyclicBuffer<int> buffer = new(0);
|
|
32
|
+
CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
|
|
33
|
+
for (int i = 0; i < NumTries; ++i)
|
|
34
|
+
{
|
|
35
|
+
buffer.Add(PRNG.Instance.Next());
|
|
36
|
+
CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[Test]
|
|
41
|
+
public void IntMaxCapacityOk()
|
|
42
|
+
{
|
|
43
|
+
CyclicBuffer<int> buffer = new(int.MaxValue);
|
|
44
|
+
CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
|
|
45
|
+
const int tries = 50;
|
|
46
|
+
List<int> expected = new(tries);
|
|
47
|
+
for (int i = 0; i < tries; ++i)
|
|
48
|
+
{
|
|
49
|
+
int value = PRNG.Instance.Next();
|
|
50
|
+
buffer.Add(value);
|
|
51
|
+
expected.Add(value);
|
|
52
|
+
CollectionAssert.AreEquivalent(expected, buffer);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
[Test]
|
|
57
|
+
public void OneCapacityOk()
|
|
58
|
+
{
|
|
59
|
+
CyclicBuffer<int> buffer = new(1);
|
|
60
|
+
CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
|
|
61
|
+
int[] expected = new int[1];
|
|
62
|
+
for (int i = 0; i < NumTries; ++i)
|
|
63
|
+
{
|
|
64
|
+
int value = PRNG.Instance.Next();
|
|
65
|
+
buffer.Add(value);
|
|
66
|
+
expected[0] = value;
|
|
67
|
+
CollectionAssert.AreEquivalent(expected, buffer);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
[Test]
|
|
72
|
+
public void NormalAndWrappingBehavior()
|
|
73
|
+
{
|
|
74
|
+
List<int> expected = new();
|
|
75
|
+
for (int i = 0; i < NumTries; ++i)
|
|
76
|
+
{
|
|
77
|
+
int capacity = PRNG.Instance.Next(100, 1_000);
|
|
78
|
+
CyclicBuffer<int> buffer = new(capacity);
|
|
79
|
+
CollectionAssert.AreEquivalent(Array.Empty<int>(), buffer);
|
|
80
|
+
expected.Clear();
|
|
81
|
+
for (int j = 0; j < capacity * CapacityMultiplier; ++j)
|
|
82
|
+
{
|
|
83
|
+
int newValue = PRNG.Instance.Next();
|
|
84
|
+
if (capacity <= j)
|
|
85
|
+
{
|
|
86
|
+
expected[j % capacity] = newValue;
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
expected.Add(newValue);
|
|
91
|
+
}
|
|
92
|
+
buffer.Add(newValue);
|
|
93
|
+
Assert.IsTrue(
|
|
94
|
+
expected.SequenceEqual(buffer),
|
|
95
|
+
$"Failure at iteration {i}, j={j}, capacity={capacity}, capacityMultiplier={CapacityMultiplier}"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.wallstop-studios.unity-helpers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc23",
|
|
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": {
|