com.wallstop-studios.unity-helpers 2.0.0-rc22 → 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/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
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
private const uint k_Prime32v5 = 374761393u;
|
|
19
19
|
|
|
20
20
|
public static uint Hash32(string text) => Hash32(text, Encoding.UTF8);
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
public static uint Hash32(string text, Encoding encoding) =>
|
|
23
|
+
Hash32(encoding.GetBytes(text));
|
|
24
|
+
|
|
22
25
|
public static uint Hash32(byte[] buffer)
|
|
23
26
|
{
|
|
24
27
|
unsafe
|
|
@@ -71,7 +74,10 @@
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
public static ulong Hash64(string text) => Hash64(text, Encoding.UTF8);
|
|
74
|
-
|
|
77
|
+
|
|
78
|
+
public static ulong Hash64(string text, Encoding encoding) =>
|
|
79
|
+
Hash64(encoding.GetBytes(text));
|
|
80
|
+
|
|
75
81
|
public static ulong Hash64(byte[] buffer)
|
|
76
82
|
{
|
|
77
83
|
unsafe
|
|
@@ -120,7 +126,6 @@
|
|
|
120
126
|
acc += (ulong)len;
|
|
121
127
|
acc = processRemaining64(pInput, acc, remainingLen);
|
|
122
128
|
|
|
123
|
-
|
|
124
129
|
return avalanche64(acc);
|
|
125
130
|
}
|
|
126
131
|
|
|
@@ -130,17 +135,19 @@
|
|
|
130
135
|
ref ulong acc1,
|
|
131
136
|
ref ulong acc2,
|
|
132
137
|
ref ulong acc3,
|
|
133
|
-
ref ulong acc4
|
|
138
|
+
ref ulong acc4
|
|
139
|
+
)
|
|
134
140
|
{
|
|
135
141
|
processLane64(ref acc1, ref pInput);
|
|
136
142
|
processLane64(ref acc2, ref pInput);
|
|
137
143
|
processLane64(ref acc3, ref pInput);
|
|
138
144
|
processLane64(ref acc4, ref pInput);
|
|
139
145
|
|
|
140
|
-
ulong acc =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
ulong acc =
|
|
147
|
+
Bits.RotateLeft(acc1, 1)
|
|
148
|
+
+ Bits.RotateLeft(acc2, 7)
|
|
149
|
+
+ Bits.RotateLeft(acc3, 12)
|
|
150
|
+
+ Bits.RotateLeft(acc4, 18);
|
|
144
151
|
|
|
145
152
|
mergeAccumulator64(ref acc, acc1);
|
|
146
153
|
mergeAccumulator64(ref acc, acc2);
|
|
@@ -158,10 +165,7 @@
|
|
|
158
165
|
}
|
|
159
166
|
|
|
160
167
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
161
|
-
private static unsafe ulong processRemaining64(
|
|
162
|
-
byte* pInput,
|
|
163
|
-
ulong acc,
|
|
164
|
-
int remainingLen)
|
|
168
|
+
private static unsafe ulong processRemaining64(byte* pInput, ulong acc, int remainingLen)
|
|
165
169
|
{
|
|
166
170
|
for (ulong lane; remainingLen >= 8; remainingLen -= 8, pInput += 8)
|
|
167
171
|
{
|
|
@@ -223,7 +227,8 @@
|
|
|
223
227
|
ref uint acc1,
|
|
224
228
|
ref uint acc2,
|
|
225
229
|
ref uint acc3,
|
|
226
|
-
ref uint acc4
|
|
230
|
+
ref uint acc4
|
|
231
|
+
)
|
|
227
232
|
{
|
|
228
233
|
processLane32(ref pInput, ref acc1);
|
|
229
234
|
processLane32(ref pInput, ref acc2);
|
|
@@ -231,9 +236,9 @@
|
|
|
231
236
|
processLane32(ref pInput, ref acc4);
|
|
232
237
|
|
|
233
238
|
return Bits.RotateLeft(acc1, 1)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
239
|
+
+ Bits.RotateLeft(acc2, 7)
|
|
240
|
+
+ Bits.RotateLeft(acc3, 12)
|
|
241
|
+
+ Bits.RotateLeft(acc4, 18);
|
|
237
242
|
}
|
|
238
243
|
|
|
239
244
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
@@ -245,10 +250,7 @@
|
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
248
|
-
private static unsafe uint processRemaining32(
|
|
249
|
-
byte* pInput,
|
|
250
|
-
uint acc,
|
|
251
|
-
int remainingLen)
|
|
253
|
+
private static unsafe uint processRemaining32(byte* pInput, uint acc, int remainingLen)
|
|
252
254
|
{
|
|
253
255
|
for (uint lane; remainingLen >= 4; remainingLen -= 4, pInput += 4)
|
|
254
256
|
{
|
|
@@ -7,15 +7,32 @@
|
|
|
7
7
|
[Serializable]
|
|
8
8
|
public enum Direction : short
|
|
9
9
|
{
|
|
10
|
-
[EnumMember]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[EnumMember]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
[EnumMember]
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
[EnumMember]
|
|
11
|
+
None = 0,
|
|
12
|
+
|
|
13
|
+
[EnumMember]
|
|
14
|
+
North = 1,
|
|
15
|
+
|
|
16
|
+
[EnumMember]
|
|
17
|
+
NorthEast = 2,
|
|
18
|
+
|
|
19
|
+
[EnumMember]
|
|
20
|
+
East = 4,
|
|
21
|
+
|
|
22
|
+
[EnumMember]
|
|
23
|
+
SouthEast = 8,
|
|
24
|
+
|
|
25
|
+
[EnumMember]
|
|
26
|
+
South = 16,
|
|
27
|
+
|
|
28
|
+
[EnumMember]
|
|
29
|
+
SouthWest = 32,
|
|
30
|
+
|
|
31
|
+
[EnumMember]
|
|
32
|
+
West = 64,
|
|
33
|
+
|
|
34
|
+
[EnumMember]
|
|
35
|
+
NorthWest = 128,
|
|
19
36
|
}
|
|
20
37
|
|
|
21
38
|
public static class DirectionConstants
|
|
@@ -44,14 +44,15 @@
|
|
|
44
44
|
{
|
|
45
45
|
if (_index != 0)
|
|
46
46
|
{
|
|
47
|
-
throw new InvalidOperationException(
|
|
47
|
+
throw new InvalidOperationException(
|
|
48
|
+
$"Cannot return as T0 as result is T{_index}"
|
|
49
|
+
);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
return _value0;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
|
|
55
56
|
public T1 AsT1
|
|
56
57
|
{
|
|
57
58
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
@@ -59,7 +60,9 @@
|
|
|
59
60
|
{
|
|
60
61
|
if (_index != 1)
|
|
61
62
|
{
|
|
62
|
-
throw new InvalidOperationException(
|
|
63
|
+
throw new InvalidOperationException(
|
|
64
|
+
$"Cannot return as T1 as result is T{_index}"
|
|
65
|
+
);
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
return _value1;
|
|
@@ -73,7 +76,9 @@
|
|
|
73
76
|
{
|
|
74
77
|
if (_index != 2)
|
|
75
78
|
{
|
|
76
|
-
throw new InvalidOperationException(
|
|
79
|
+
throw new InvalidOperationException(
|
|
80
|
+
$"Cannot return as T2 as result is T{_index}"
|
|
81
|
+
);
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
return _value2;
|
|
@@ -89,7 +94,9 @@
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
public static implicit operator FastOneOf<T0, T1, T2>(T0 value) => new(0, value0: value);
|
|
97
|
+
|
|
92
98
|
public static implicit operator FastOneOf<T0, T1, T2>(T1 value) => new(1, value1: value);
|
|
99
|
+
|
|
93
100
|
public static implicit operator FastOneOf<T0, T1, T2>(T2 value) => new(2, value2: value);
|
|
94
101
|
|
|
95
102
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
|
|
12
12
|
private Vector2Converter() { }
|
|
13
13
|
|
|
14
|
-
public override Vector2 Read(
|
|
14
|
+
public override Vector2 Read(
|
|
15
|
+
ref Utf8JsonReader reader,
|
|
16
|
+
Type typeToConvert,
|
|
17
|
+
JsonSerializerOptions options
|
|
18
|
+
)
|
|
15
19
|
{
|
|
16
20
|
if (reader.TokenType != JsonTokenType.StartObject)
|
|
17
21
|
{
|
|
18
22
|
throw new JsonException($"Invalid token type {reader.TokenType}");
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
float x = 0,
|
|
25
|
+
float x = 0,
|
|
26
|
+
y = 0;
|
|
22
27
|
|
|
23
28
|
while (reader.Read())
|
|
24
29
|
{
|
|
@@ -54,7 +59,11 @@
|
|
|
54
59
|
throw new JsonException("Incomplete JSON for Vector2");
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
public override void Write(
|
|
62
|
+
public override void Write(
|
|
63
|
+
Utf8JsonWriter writer,
|
|
64
|
+
Vector2 value,
|
|
65
|
+
JsonSerializerOptions options
|
|
66
|
+
)
|
|
58
67
|
{
|
|
59
68
|
writer.WriteStartObject();
|
|
60
69
|
writer.WriteNumber("x", value.x);
|
|
@@ -62,4 +71,4 @@
|
|
|
62
71
|
writer.WriteEndObject();
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
|
-
}
|
|
74
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Serialization.JsonConverters
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
-
using UnityEngine;
|
|
5
4
|
using System.Text.Json;
|
|
6
5
|
using System.Text.Json.Serialization;
|
|
6
|
+
using UnityEngine;
|
|
7
7
|
|
|
8
8
|
public sealed class Vector3Converter : JsonConverter<Vector3>
|
|
9
9
|
{
|
|
@@ -11,14 +11,20 @@
|
|
|
11
11
|
|
|
12
12
|
private Vector3Converter() { }
|
|
13
13
|
|
|
14
|
-
public override Vector3 Read(
|
|
14
|
+
public override Vector3 Read(
|
|
15
|
+
ref Utf8JsonReader reader,
|
|
16
|
+
Type typeToConvert,
|
|
17
|
+
JsonSerializerOptions options
|
|
18
|
+
)
|
|
15
19
|
{
|
|
16
20
|
if (reader.TokenType != JsonTokenType.StartObject)
|
|
17
21
|
{
|
|
18
22
|
throw new JsonException($"Invalid token type {reader.TokenType}");
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
float x = 0,
|
|
25
|
+
float x = 0,
|
|
26
|
+
y = 0,
|
|
27
|
+
z = 0;
|
|
22
28
|
|
|
23
29
|
while (reader.Read())
|
|
24
30
|
{
|
|
@@ -59,7 +65,11 @@
|
|
|
59
65
|
throw new JsonException("Incomplete JSON for Vector3");
|
|
60
66
|
}
|
|
61
67
|
|
|
62
|
-
public override void Write(
|
|
68
|
+
public override void Write(
|
|
69
|
+
Utf8JsonWriter writer,
|
|
70
|
+
Vector3 value,
|
|
71
|
+
JsonSerializerOptions options
|
|
72
|
+
)
|
|
63
73
|
{
|
|
64
74
|
writer.WriteStartObject();
|
|
65
75
|
writer.WriteNumber("x", value.x);
|
|
@@ -68,4 +78,4 @@
|
|
|
68
78
|
writer.WriteEndObject();
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
|
-
}
|
|
81
|
+
}
|
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
using System.Collections.Generic;
|
|
5
5
|
using UnityEngine;
|
|
6
6
|
|
|
7
|
-
public sealed class AnimationEventEqualityComparer
|
|
7
|
+
public sealed class AnimationEventEqualityComparer
|
|
8
|
+
: EqualityComparer<AnimationEvent>,
|
|
9
|
+
IComparer<AnimationEvent>
|
|
8
10
|
{
|
|
9
11
|
public static readonly AnimationEventEqualityComparer Instance = new();
|
|
10
12
|
|
|
11
|
-
private AnimationEventEqualityComparer()
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
}
|
|
13
|
+
private AnimationEventEqualityComparer() { }
|
|
15
14
|
|
|
16
15
|
// Returns a shallow copy with equatable values propagated
|
|
17
16
|
public AnimationEvent Copy(AnimationEvent instance)
|
|
@@ -93,13 +92,18 @@
|
|
|
93
92
|
|
|
94
93
|
return true;
|
|
95
94
|
}
|
|
96
|
-
|
|
97
95
|
|
|
98
96
|
public override int GetHashCode(AnimationEvent instance)
|
|
99
97
|
{
|
|
100
98
|
return HashCode.Combine(
|
|
101
|
-
instance.time,
|
|
102
|
-
instance.
|
|
99
|
+
instance.time,
|
|
100
|
+
instance.functionName,
|
|
101
|
+
instance.intParameter,
|
|
102
|
+
instance.floatParameter,
|
|
103
|
+
instance.stringParameter,
|
|
104
|
+
instance.objectReferenceParameter,
|
|
105
|
+
instance.messageOptions
|
|
106
|
+
);
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
public int Compare(AnimationEvent lhs, AnimationEvent rhs)
|
|
@@ -125,7 +129,11 @@
|
|
|
125
129
|
return timeComparison;
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
int functionNameComparison = string.Compare(
|
|
132
|
+
int functionNameComparison = string.Compare(
|
|
133
|
+
lhs.functionName,
|
|
134
|
+
rhs.functionName,
|
|
135
|
+
StringComparison.Ordinal
|
|
136
|
+
);
|
|
129
137
|
if (functionNameComparison != 0)
|
|
130
138
|
{
|
|
131
139
|
return functionNameComparison;
|
|
@@ -137,7 +145,11 @@
|
|
|
137
145
|
return intParameterComparison;
|
|
138
146
|
}
|
|
139
147
|
|
|
140
|
-
int stringParameterComparison = string.Compare(
|
|
148
|
+
int stringParameterComparison = string.Compare(
|
|
149
|
+
lhs.stringParameter,
|
|
150
|
+
rhs.stringParameter,
|
|
151
|
+
StringComparison.Ordinal
|
|
152
|
+
);
|
|
141
153
|
if (stringParameterComparison != 0)
|
|
142
154
|
{
|
|
143
155
|
return stringParameterComparison;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
namespace UnityHelpers.Utils
|
|
2
2
|
{
|
|
3
|
-
using Core.Extension;
|
|
4
3
|
using System;
|
|
5
4
|
using System.Collections.Generic;
|
|
6
5
|
using System.Globalization;
|
|
7
6
|
using System.Linq;
|
|
8
7
|
using System.Runtime.Serialization;
|
|
9
8
|
using System.Text.Json.Serialization;
|
|
9
|
+
using Core.Extension;
|
|
10
10
|
using UnityEngine;
|
|
11
11
|
|
|
12
12
|
/// <summary>
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
/// <typeparam name="T">Specific Enum being managed.</typeparam>
|
|
16
16
|
[DataContract]
|
|
17
17
|
public sealed class AnimatorEnumStateMachine<T>
|
|
18
|
-
where T : struct, IConvertible, IComparable,
|
|
19
|
-
IFormattable // This is as close as we can get to saying where T : Enum (https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum)
|
|
18
|
+
where T : struct, IConvertible, IComparable, IFormattable // This is as close as we can get to saying where T : Enum (https://stackoverflow.com/questions/79126/create-generic-method-constraining-t-to-an-enum)
|
|
20
19
|
{
|
|
21
20
|
private static readonly T[] Values = Enum.GetValues(typeof(T)).OfType<T>().ToArray();
|
|
22
21
|
|
|
@@ -86,4 +85,4 @@
|
|
|
86
85
|
return this.ToJson();
|
|
87
86
|
}
|
|
88
87
|
}
|
|
89
|
-
}
|
|
88
|
+
}
|
package/Runtime/Utils/Buffers.cs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
public float height = 1f;
|
|
11
11
|
|
|
12
12
|
private Vector3 _initialLocalPosition;
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
private void Awake()
|
|
15
15
|
{
|
|
16
16
|
_initialLocalPosition = transform.localPosition;
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
private void Update()
|
|
20
20
|
{
|
|
21
21
|
float time = Time.time;
|
|
22
|
-
transform.localPosition =
|
|
22
|
+
transform.localPosition =
|
|
23
|
+
_initialLocalPosition
|
|
24
|
+
+ new Vector3(Mathf.Cos(time * speed) * width, Mathf.Sin(time * speed) * height);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
|
|
48
48
|
private void LateUpdate()
|
|
49
49
|
{
|
|
50
|
-
SpriteRenderer localToMatch =
|
|
50
|
+
SpriteRenderer localToMatch =
|
|
51
|
+
dynamicToMatch != null ? GetDynamicSpriteRenderer() : toMatch;
|
|
51
52
|
if (localToMatch == null)
|
|
52
53
|
{
|
|
53
54
|
_spriteRenderer.sprite = null;
|
|
@@ -75,7 +76,8 @@
|
|
|
75
76
|
|
|
76
77
|
if (matchOrderInLayer)
|
|
77
78
|
{
|
|
78
|
-
_spriteRenderer.sortingOrder =
|
|
79
|
+
_spriteRenderer.sortingOrder =
|
|
80
|
+
DynamicSortingOrderOverride ?? localToMatch.sortingOrder;
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
_spriteRenderer.size = localToMatch.size;
|
|
@@ -95,4 +97,4 @@
|
|
|
95
97
|
return _cachedSpriteRenderer;
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
|
-
}
|
|
100
|
+
}
|
|
@@ -38,7 +38,12 @@
|
|
|
38
38
|
ThreadedScale(tex, newWidth, newHeight, true);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
private static void ThreadedScale(
|
|
41
|
+
private static void ThreadedScale(
|
|
42
|
+
Texture2D tex,
|
|
43
|
+
int newWidth,
|
|
44
|
+
int newHeight,
|
|
45
|
+
bool useBilinear
|
|
46
|
+
)
|
|
42
47
|
{
|
|
43
48
|
texColors = tex.GetPixels();
|
|
44
49
|
newColors = new Color[newWidth * newHeight];
|
|
@@ -123,9 +128,18 @@
|
|
|
123
128
|
int xFloor = (int)Mathf.Floor(x * ratioX);
|
|
124
129
|
float xLerp = x * ratioX - xFloor;
|
|
125
130
|
newColors[yw + x] = ColorLerpUnclamped(
|
|
126
|
-
ColorLerpUnclamped(
|
|
127
|
-
|
|
128
|
-
|
|
131
|
+
ColorLerpUnclamped(
|
|
132
|
+
texColors[y1 + xFloor],
|
|
133
|
+
texColors[y1 + xFloor + 1],
|
|
134
|
+
xLerp
|
|
135
|
+
),
|
|
136
|
+
ColorLerpUnclamped(
|
|
137
|
+
texColors[y2 + xFloor],
|
|
138
|
+
texColors[y2 + xFloor + 1],
|
|
139
|
+
xLerp
|
|
140
|
+
),
|
|
141
|
+
y * ratioY - yFloor
|
|
142
|
+
);
|
|
129
143
|
}
|
|
130
144
|
}
|
|
131
145
|
|
|
@@ -158,7 +172,8 @@
|
|
|
158
172
|
c1.r + (c2.r - c1.r) * value,
|
|
159
173
|
c1.g + (c2.g - c1.g) * value,
|
|
160
174
|
c1.b + (c2.b - c1.b) * value,
|
|
161
|
-
c1.a + (c2.a - c1.a) * value
|
|
175
|
+
c1.a + (c2.a - c1.a) * value
|
|
176
|
+
);
|
|
162
177
|
}
|
|
163
178
|
}
|
|
164
|
-
}
|
|
179
|
+
}
|
|
@@ -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
|
+
}
|