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
|
@@ -59,14 +59,20 @@
|
|
|
59
59
|
return new KGuid(System.Guid.NewGuid());
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
public KGuid(Guid guid)
|
|
62
|
+
public KGuid(Guid guid)
|
|
63
|
+
: this(guid.ToByteArray()) { }
|
|
63
64
|
|
|
64
65
|
[JsonConstructor]
|
|
65
|
-
public KGuid(string guid)
|
|
66
|
+
public KGuid(string guid)
|
|
67
|
+
: this(System.Guid.Parse(guid)) { }
|
|
66
68
|
|
|
67
69
|
public KGuid(byte[] guidBytes)
|
|
68
70
|
{
|
|
69
|
-
_a =
|
|
71
|
+
_a =
|
|
72
|
+
(int)guidBytes[3] << 24
|
|
73
|
+
| (int)guidBytes[2] << 16
|
|
74
|
+
| (int)guidBytes[1] << 8
|
|
75
|
+
| (int)guidBytes[0];
|
|
70
76
|
_b = (short)((int)guidBytes[5] << 8 | (int)guidBytes[4]);
|
|
71
77
|
_c = (short)((int)guidBytes[7] << 8 | (int)guidBytes[6]);
|
|
72
78
|
_d = guidBytes[8];
|
|
@@ -83,7 +89,18 @@
|
|
|
83
89
|
public static implicit operator Guid(KGuid guid)
|
|
84
90
|
{
|
|
85
91
|
return new Guid(
|
|
86
|
-
guid._a,
|
|
92
|
+
guid._a,
|
|
93
|
+
guid._b,
|
|
94
|
+
guid._c,
|
|
95
|
+
guid._d,
|
|
96
|
+
guid._e,
|
|
97
|
+
guid._f,
|
|
98
|
+
guid._g,
|
|
99
|
+
guid._h,
|
|
100
|
+
guid._i,
|
|
101
|
+
guid._j,
|
|
102
|
+
guid._k
|
|
103
|
+
);
|
|
87
104
|
}
|
|
88
105
|
|
|
89
106
|
public static implicit operator KGuid(Guid guid)
|
|
@@ -237,7 +254,7 @@
|
|
|
237
254
|
{
|
|
238
255
|
KGuid otherKGuid => Equals(otherKGuid),
|
|
239
256
|
Guid otherGuid => Equals(otherGuid),
|
|
240
|
-
_ => false
|
|
257
|
+
_ => false,
|
|
241
258
|
};
|
|
242
259
|
}
|
|
243
260
|
|
|
@@ -275,7 +292,7 @@
|
|
|
275
292
|
_h,
|
|
276
293
|
_i,
|
|
277
294
|
_j,
|
|
278
|
-
_k
|
|
295
|
+
_k,
|
|
279
296
|
};
|
|
280
297
|
}
|
|
281
298
|
|
|
@@ -285,4 +302,4 @@
|
|
|
285
302
|
_hashCode = 0;
|
|
286
303
|
}
|
|
287
304
|
}
|
|
288
|
-
}
|
|
305
|
+
}
|
|
@@ -1,31 +1,19 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.DataStructure
|
|
2
2
|
{
|
|
3
|
-
using Helper;
|
|
4
3
|
using System;
|
|
5
4
|
using System.Collections;
|
|
6
5
|
using System.Collections.Generic;
|
|
7
|
-
using System.
|
|
8
|
-
|
|
9
|
-
public enum BufferAddMethod
|
|
10
|
-
{
|
|
11
|
-
Prepend,
|
|
12
|
-
Append
|
|
13
|
-
}
|
|
6
|
+
using System.Linq;
|
|
7
|
+
using Helper;
|
|
14
8
|
|
|
15
9
|
[Serializable]
|
|
16
|
-
public sealed class CyclicBuffer<T> :
|
|
10
|
+
public sealed class CyclicBuffer<T> : IReadOnlyList<T>
|
|
17
11
|
{
|
|
18
|
-
private readonly T[] _buffer;
|
|
19
|
-
|
|
20
|
-
private int _position;
|
|
21
|
-
|
|
22
|
-
public readonly BufferAddMethod AddMethod;
|
|
23
|
-
|
|
24
|
-
public readonly int Capacity;
|
|
25
|
-
|
|
26
12
|
public int Count { get; private set; }
|
|
13
|
+
public readonly int capacity;
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
private readonly List<T> _buffer;
|
|
16
|
+
private int _position;
|
|
29
17
|
|
|
30
18
|
public T this[int index]
|
|
31
19
|
{
|
|
@@ -41,24 +29,29 @@
|
|
|
41
29
|
}
|
|
42
30
|
}
|
|
43
31
|
|
|
44
|
-
public CyclicBuffer(int capacity,
|
|
32
|
+
public CyclicBuffer(int capacity, IEnumerable<T> initialContents = null)
|
|
45
33
|
{
|
|
46
34
|
if (capacity < 0)
|
|
47
35
|
{
|
|
48
36
|
throw new ArgumentException(nameof(capacity));
|
|
49
37
|
}
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
|
|
39
|
+
this.capacity = capacity;
|
|
52
40
|
_position = 0;
|
|
53
|
-
|
|
54
|
-
|
|
41
|
+
Count = 0;
|
|
42
|
+
_buffer = new List<T>();
|
|
43
|
+
foreach (T item in initialContents ?? Enumerable.Empty<T>())
|
|
44
|
+
{
|
|
45
|
+
Add(item);
|
|
46
|
+
}
|
|
55
47
|
}
|
|
56
48
|
|
|
57
49
|
public IEnumerator<T> GetEnumerator()
|
|
58
50
|
{
|
|
59
51
|
for (int i = 0; i < Count; ++i)
|
|
60
52
|
{
|
|
61
|
-
|
|
53
|
+
// No need for bounds check, we're safe
|
|
54
|
+
yield return _buffer[AdjustedIndexFor(i)];
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
|
|
@@ -69,9 +62,22 @@
|
|
|
69
62
|
|
|
70
63
|
public void Add(T item)
|
|
71
64
|
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
if (capacity == 0)
|
|
66
|
+
{
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (_position < _buffer.Count)
|
|
71
|
+
{
|
|
72
|
+
_buffer[_position] = item;
|
|
73
|
+
}
|
|
74
|
+
else
|
|
75
|
+
{
|
|
76
|
+
_buffer.Add(item);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
_position = _position.WrappedIncrement(capacity);
|
|
80
|
+
if (Count < capacity)
|
|
75
81
|
{
|
|
76
82
|
++Count;
|
|
77
83
|
}
|
|
@@ -86,32 +92,24 @@
|
|
|
86
92
|
|
|
87
93
|
public bool Peek(out T value)
|
|
88
94
|
{
|
|
89
|
-
|
|
95
|
+
const int firstIndex = 0;
|
|
96
|
+
if (InBounds(firstIndex))
|
|
90
97
|
{
|
|
91
|
-
value =
|
|
98
|
+
value = _buffer[AdjustedIndexFor(firstIndex)];
|
|
92
99
|
return true;
|
|
93
100
|
}
|
|
94
|
-
|
|
101
|
+
|
|
102
|
+
value = default;
|
|
95
103
|
return false;
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
private int AdjustedIndexFor(int index)
|
|
99
107
|
{
|
|
100
|
-
|
|
108
|
+
if (index < _buffer.Count)
|
|
101
109
|
{
|
|
102
|
-
|
|
103
|
-
{
|
|
104
|
-
return (_position - 1 + Capacity - index) % Capacity;
|
|
105
|
-
}
|
|
106
|
-
case BufferAddMethod.Append:
|
|
107
|
-
{
|
|
108
|
-
return index;
|
|
109
|
-
}
|
|
110
|
-
default:
|
|
111
|
-
{
|
|
112
|
-
throw new InvalidEnumArgumentException("Unexpected AddMethod: " + AddMethod);
|
|
113
|
-
}
|
|
110
|
+
return index;
|
|
114
111
|
}
|
|
112
|
+
return (_position - 1 + capacity - index) % capacity;
|
|
115
113
|
}
|
|
116
114
|
|
|
117
115
|
private void BoundsCheck(int index)
|
|
@@ -124,7 +122,7 @@
|
|
|
124
122
|
|
|
125
123
|
private bool InBounds(int index)
|
|
126
124
|
{
|
|
127
|
-
return
|
|
125
|
+
return 0 <= index && index < Count;
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
}
|
|
@@ -20,35 +20,37 @@
|
|
|
20
20
|
return GetElementsInBounds(
|
|
21
21
|
new Bounds(
|
|
22
22
|
new Vector3(position.x, position.y, 0f),
|
|
23
|
-
new Vector3(range * 2f, range * 2f, 1f)
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
new Vector3(range * 2f, range * 2f, 1f)
|
|
24
|
+
)
|
|
25
|
+
)
|
|
26
|
+
.Where(element =>
|
|
27
|
+
{
|
|
28
|
+
Vector2 elementPosition = elementTransformer(element);
|
|
29
|
+
if (!area.Contains(elementPosition))
|
|
26
30
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
{
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
return !minimumArea.Contains(elementPosition);
|
|
35
|
+
});
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
return GetElementsInBounds(
|
|
38
39
|
new Bounds(
|
|
39
40
|
new Vector3(position.x, position.y, 0f),
|
|
40
|
-
new Vector3(range * 2f, range * 2f, 1f)
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
new Vector3(range * 2f, range * 2f, 1f)
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
.Where(element =>
|
|
45
|
+
{
|
|
46
|
+
Vector2 elementPosition = elementTransformer(element);
|
|
47
|
+
if (!area.Contains(elementPosition))
|
|
43
48
|
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
49
51
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
IEnumerable<T> GetElementsInBounds(Bounds bounds);
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
{
|
|
10
10
|
public static IEnumerable<FastVector3Int> EnumerateArea(this Circle circle, int z = 0)
|
|
11
11
|
{
|
|
12
|
-
for (int x = (int)
|
|
12
|
+
for (int x = (int)-circle.radius; x < circle.radius; ++x)
|
|
13
13
|
{
|
|
14
|
-
for (int y = (int)
|
|
14
|
+
for (int y = (int)-circle.radius; y < circle.radius; ++y)
|
|
15
15
|
{
|
|
16
16
|
Vector2 point = new(x, y);
|
|
17
17
|
if (circle.Contains(point))
|
|
@@ -7,11 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
public static class DictionaryExtensions
|
|
9
9
|
{
|
|
10
|
-
public static V GetOrAdd<K, V>(
|
|
10
|
+
public static V GetOrAdd<K, V>(
|
|
11
|
+
this IDictionary<K, V> dictionary,
|
|
12
|
+
K key,
|
|
13
|
+
Func<V> valueProducer
|
|
14
|
+
)
|
|
11
15
|
{
|
|
12
16
|
if (dictionary is ConcurrentDictionary<K, V> concurrentDictionary)
|
|
13
17
|
{
|
|
14
|
-
return concurrentDictionary.GetOrAdd(
|
|
18
|
+
return concurrentDictionary.GetOrAdd(
|
|
19
|
+
key,
|
|
20
|
+
static (_, existing) => existing(),
|
|
21
|
+
valueProducer
|
|
22
|
+
);
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
if (dictionary.TryGetValue(key, out V result))
|
|
@@ -22,7 +30,11 @@
|
|
|
22
30
|
return dictionary[key] = valueProducer();
|
|
23
31
|
}
|
|
24
32
|
|
|
25
|
-
public static V GetOrAdd<K, V>(
|
|
33
|
+
public static V GetOrAdd<K, V>(
|
|
34
|
+
this IDictionary<K, V> dictionary,
|
|
35
|
+
K key,
|
|
36
|
+
Func<K, V> valueProducer
|
|
37
|
+
)
|
|
26
38
|
{
|
|
27
39
|
if (dictionary is ConcurrentDictionary<K, V> concurrentDictionary)
|
|
28
40
|
{
|
|
@@ -37,7 +49,11 @@
|
|
|
37
49
|
return dictionary[key] = valueProducer(key);
|
|
38
50
|
}
|
|
39
51
|
|
|
40
|
-
public static V GetOrElse<K, V>(
|
|
52
|
+
public static V GetOrElse<K, V>(
|
|
53
|
+
this IReadOnlyDictionary<K, V> dictionary,
|
|
54
|
+
K key,
|
|
55
|
+
Func<V> valueProducer
|
|
56
|
+
)
|
|
41
57
|
{
|
|
42
58
|
if (dictionary.TryGetValue(key, out V value))
|
|
43
59
|
{
|
|
@@ -47,7 +63,11 @@
|
|
|
47
63
|
return valueProducer.Invoke();
|
|
48
64
|
}
|
|
49
65
|
|
|
50
|
-
public static V GetOrElse<K, V>(
|
|
66
|
+
public static V GetOrElse<K, V>(
|
|
67
|
+
this IReadOnlyDictionary<K, V> dictionary,
|
|
68
|
+
K key,
|
|
69
|
+
Func<K, V> valueProducer
|
|
70
|
+
)
|
|
51
71
|
{
|
|
52
72
|
if (dictionary.TryGetValue(key, out V value))
|
|
53
73
|
{
|
|
@@ -57,11 +77,16 @@
|
|
|
57
77
|
return valueProducer.Invoke(key);
|
|
58
78
|
}
|
|
59
79
|
|
|
60
|
-
public static V GetOrAdd<K, V>(this IDictionary<K, V> dictionary, K key)
|
|
80
|
+
public static V GetOrAdd<K, V>(this IDictionary<K, V> dictionary, K key)
|
|
81
|
+
where V : new()
|
|
61
82
|
{
|
|
62
83
|
if (dictionary is ConcurrentDictionary<K, V> concurrentDictionary)
|
|
63
84
|
{
|
|
64
|
-
return concurrentDictionary.AddOrUpdate(
|
|
85
|
+
return concurrentDictionary.AddOrUpdate(
|
|
86
|
+
key,
|
|
87
|
+
_ => new V(),
|
|
88
|
+
(_, existing) => existing
|
|
89
|
+
);
|
|
65
90
|
}
|
|
66
91
|
|
|
67
92
|
if (dictionary.TryGetValue(key, out V result))
|
|
@@ -78,14 +103,20 @@
|
|
|
78
103
|
}
|
|
79
104
|
|
|
80
105
|
public static V AddOrUpdate<K, V>(
|
|
81
|
-
this IDictionary<K, V> dictionary,
|
|
106
|
+
this IDictionary<K, V> dictionary,
|
|
107
|
+
K key,
|
|
108
|
+
Func<K, V> creator,
|
|
109
|
+
Func<K, V, V> updater
|
|
110
|
+
)
|
|
82
111
|
{
|
|
83
112
|
if (dictionary is ConcurrentDictionary<K, V> concurrentDictionary)
|
|
84
113
|
{
|
|
85
114
|
return concurrentDictionary.AddOrUpdate(key, creator, updater);
|
|
86
115
|
}
|
|
87
116
|
|
|
88
|
-
V latest = dictionary.TryGetValue(key, out V value)
|
|
117
|
+
V latest = dictionary.TryGetValue(key, out V value)
|
|
118
|
+
? updater(key, value)
|
|
119
|
+
: creator(key);
|
|
89
120
|
dictionary[key] = latest;
|
|
90
121
|
return latest;
|
|
91
122
|
}
|
|
@@ -107,7 +138,10 @@
|
|
|
107
138
|
return value;
|
|
108
139
|
}
|
|
109
140
|
|
|
110
|
-
public static Dictionary<K, V> Merge<K, V>(
|
|
141
|
+
public static Dictionary<K, V> Merge<K, V>(
|
|
142
|
+
this IReadOnlyDictionary<K, V> lhs,
|
|
143
|
+
IReadOnlyDictionary<K, V> rhs
|
|
144
|
+
)
|
|
111
145
|
{
|
|
112
146
|
Dictionary<K, V> result = new();
|
|
113
147
|
if (0 < lhs.Count)
|
|
@@ -137,7 +171,9 @@
|
|
|
137
171
|
/// <param name="rhs">Changed dictionary.</param>
|
|
138
172
|
/// <returns>All elements of rhs that either don't exist in or are different from lhs</returns>
|
|
139
173
|
public static Dictionary<K, V> Difference<K, V>(
|
|
140
|
-
this IReadOnlyDictionary<K, V> lhs,
|
|
174
|
+
this IReadOnlyDictionary<K, V> lhs,
|
|
175
|
+
IReadOnlyDictionary<K, V> rhs
|
|
176
|
+
)
|
|
141
177
|
{
|
|
142
178
|
Dictionary<K, V> result = new(rhs.Count);
|
|
143
179
|
foreach (KeyValuePair<K, V> kvp in rhs)
|
|
@@ -170,18 +206,25 @@
|
|
|
170
206
|
return new Dictionary<K, V>(dictionary);
|
|
171
207
|
}
|
|
172
208
|
|
|
173
|
-
public static Dictionary<K, V> ToDictionary<K, V>(
|
|
209
|
+
public static Dictionary<K, V> ToDictionary<K, V>(
|
|
210
|
+
this IEnumerable<KeyValuePair<K, V>> prettyMuchADictionary
|
|
211
|
+
)
|
|
174
212
|
{
|
|
175
213
|
return prettyMuchADictionary.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
|
|
176
214
|
}
|
|
177
215
|
|
|
178
|
-
public static Dictionary<K, V> ToDictionary<K, V>(
|
|
216
|
+
public static Dictionary<K, V> ToDictionary<K, V>(
|
|
217
|
+
this IEnumerable<(K, V)> prettyMuchADictionary
|
|
218
|
+
)
|
|
179
219
|
{
|
|
180
220
|
return prettyMuchADictionary.ToDictionary(kvp => kvp.Item1, kvp => kvp.Item2);
|
|
181
221
|
}
|
|
182
222
|
|
|
183
223
|
public static bool ContentEquals<K, V>(
|
|
184
|
-
this IReadOnlyDictionary<K, V> dictionary,
|
|
224
|
+
this IReadOnlyDictionary<K, V> dictionary,
|
|
225
|
+
IReadOnlyDictionary<K, V> other
|
|
226
|
+
)
|
|
227
|
+
where V : IEquatable<V>
|
|
185
228
|
{
|
|
186
229
|
if (ReferenceEquals(dictionary, other))
|
|
187
230
|
{
|
|
@@ -193,8 +236,10 @@
|
|
|
193
236
|
return false;
|
|
194
237
|
}
|
|
195
238
|
|
|
196
|
-
return dictionary.Count == other.Count
|
|
197
|
-
|
|
239
|
+
return dictionary.Count == other.Count
|
|
240
|
+
&& dictionary.All(kvp =>
|
|
241
|
+
other.TryGetValue(kvp.Key, out V value) && kvp.Value.Equals(value)
|
|
242
|
+
);
|
|
198
243
|
}
|
|
199
244
|
|
|
200
245
|
public static void Deconstruct<K, V>(this KeyValuePair<K, V> kvp, out K key, out V value)
|
|
@@ -203,4 +248,4 @@
|
|
|
203
248
|
value = kvp.Value;
|
|
204
249
|
}
|
|
205
250
|
}
|
|
206
|
-
}
|
|
251
|
+
}
|
|
@@ -6,8 +6,17 @@
|
|
|
6
6
|
|
|
7
7
|
public static class StringExtensions
|
|
8
8
|
{
|
|
9
|
-
private static readonly HashSet<char> PascalCaseSeparators =
|
|
10
|
-
|
|
9
|
+
private static readonly HashSet<char> PascalCaseSeparators = new()
|
|
10
|
+
{
|
|
11
|
+
'_',
|
|
12
|
+
' ',
|
|
13
|
+
'\r',
|
|
14
|
+
'\n',
|
|
15
|
+
'\t',
|
|
16
|
+
'.',
|
|
17
|
+
'\'',
|
|
18
|
+
'"',
|
|
19
|
+
};
|
|
11
20
|
|
|
12
21
|
public static string Center(this string input, int length)
|
|
13
22
|
{
|
|
@@ -41,13 +50,18 @@
|
|
|
41
50
|
bool appendedAnySeparator = false;
|
|
42
51
|
for (int i = 0; i < value.Length; ++i)
|
|
43
52
|
{
|
|
44
|
-
while (
|
|
53
|
+
while (
|
|
54
|
+
startIndex < value.Length && PascalCaseSeparators.Contains(value[startIndex])
|
|
55
|
+
)
|
|
45
56
|
{
|
|
46
57
|
++startIndex;
|
|
47
58
|
}
|
|
48
59
|
|
|
49
|
-
if (
|
|
50
|
-
|
|
60
|
+
if (
|
|
61
|
+
startIndex < i
|
|
62
|
+
&& char.IsLower(value[i - 1])
|
|
63
|
+
&& (char.IsUpper(value[i]) || PascalCaseSeparators.Contains(value[i]))
|
|
64
|
+
)
|
|
51
65
|
{
|
|
52
66
|
_ = stringBuilder.Append(char.ToUpper(value[startIndex]));
|
|
53
67
|
if (1 < i - startIndex)
|
|
@@ -74,8 +88,11 @@
|
|
|
74
88
|
continue;
|
|
75
89
|
}
|
|
76
90
|
|
|
77
|
-
if (
|
|
78
|
-
|
|
91
|
+
if (
|
|
92
|
+
startIndex + 1 < i
|
|
93
|
+
&& char.IsLower(value[i])
|
|
94
|
+
&& (char.IsUpper(value[i - 1]) || PascalCaseSeparators.Contains(value[i - 1]))
|
|
95
|
+
)
|
|
79
96
|
{
|
|
80
97
|
_ = stringBuilder.Append(char.ToUpper(value[startIndex]));
|
|
81
98
|
if (1 < i - 1 - startIndex)
|
|
@@ -119,8 +136,11 @@
|
|
|
119
136
|
}
|
|
120
137
|
}
|
|
121
138
|
}
|
|
122
|
-
else if (
|
|
123
|
-
|
|
139
|
+
else if (
|
|
140
|
+
appendedAnySeparator
|
|
141
|
+
&& !string.IsNullOrEmpty(separator)
|
|
142
|
+
&& separator.Length <= stringBuilder.Length
|
|
143
|
+
)
|
|
124
144
|
{
|
|
125
145
|
stringBuilder.Remove(stringBuilder.Length - separator.Length, separator.Length);
|
|
126
146
|
}
|
|
@@ -128,4 +148,4 @@
|
|
|
128
148
|
return stringBuilder.ToString();
|
|
129
149
|
}
|
|
130
150
|
}
|
|
131
|
-
}
|
|
151
|
+
}
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
public static class LifetimeHelpers
|
|
6
6
|
{
|
|
7
|
-
public static void Destroy<T>(this T source, float? afterTime = null)
|
|
7
|
+
public static void Destroy<T>(this T source, float? afterTime = null)
|
|
8
|
+
where T : Object
|
|
8
9
|
{
|
|
9
10
|
source.SmartDestroy(afterTime);
|
|
10
11
|
}
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
{
|
|
22
22
|
if (length <= 0)
|
|
23
23
|
{
|
|
24
|
-
throw new ArgumentException(
|
|
24
|
+
throw new ArgumentException(
|
|
25
|
+
$"Expected a length greater than 0, but found: {length:0.00}."
|
|
26
|
+
);
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
Length = length;
|
|
@@ -42,4 +44,4 @@
|
|
|
42
44
|
return true;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
|
-
}
|
|
47
|
+
}
|
|
@@ -10,11 +10,18 @@
|
|
|
10
10
|
int j = polygon.Length - 1;
|
|
11
11
|
for (int i = 0; i < polygon.Length; i++)
|
|
12
12
|
{
|
|
13
|
-
if (
|
|
14
|
-
polygon[
|
|
13
|
+
if (
|
|
14
|
+
polygon[i].y < point.y && polygon[j].y >= point.y
|
|
15
|
+
|| polygon[j].y < point.y && polygon[i].y >= point.y
|
|
16
|
+
)
|
|
15
17
|
{
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
+
if (
|
|
19
|
+
polygon[i].x
|
|
20
|
+
+ (point.y - polygon[i].y)
|
|
21
|
+
/ (polygon[j].y - polygon[i].y)
|
|
22
|
+
* (polygon[j].x - polygon[i].x)
|
|
23
|
+
< point.x
|
|
24
|
+
)
|
|
18
25
|
{
|
|
19
26
|
result = !result;
|
|
20
27
|
}
|
|
@@ -26,4 +33,4 @@
|
|
|
26
33
|
return result;
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
|
-
}
|
|
36
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Math
|
|
2
2
|
{
|
|
3
|
-
using Extension;
|
|
4
|
-
using Helper;
|
|
5
3
|
using System;
|
|
6
4
|
using System.Runtime.Serialization;
|
|
7
5
|
using System.Text.Json.Serialization;
|
|
6
|
+
using Extension;
|
|
7
|
+
using Helper;
|
|
8
8
|
|
|
9
9
|
/// <summary>
|
|
10
10
|
/// Inclusive Range [min,max]
|
|
11
11
|
/// </summary>
|
|
12
12
|
[Serializable]
|
|
13
13
|
[DataContract]
|
|
14
|
-
public struct Range<T> : IEquatable<Range<T>>
|
|
14
|
+
public struct Range<T> : IEquatable<Range<T>>
|
|
15
|
+
where T : IEquatable<T>, IComparable<T>
|
|
15
16
|
{
|
|
16
17
|
[DataMember]
|
|
17
18
|
[JsonInclude]
|
|
@@ -40,10 +41,10 @@
|
|
|
40
41
|
|
|
41
42
|
public bool Equals(Range<T> other)
|
|
42
43
|
{
|
|
43
|
-
return min.Equals(other.min)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
return min.Equals(other.min)
|
|
45
|
+
&& max.Equals(other.max)
|
|
46
|
+
&& startInclusive == other.startInclusive
|
|
47
|
+
&& endInclusive == other.endInclusive;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
public override bool Equals(object obj)
|
|
@@ -88,4 +89,4 @@
|
|
|
88
89
|
return true;
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
}
|
|
92
|
+
}
|