com.wallstop-studios.unity-helpers 2.0.0-rc06 → 2.0.0-rc08
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/Runtime/Core/Extension/DirectionExtensions.cs +5 -2
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +19 -6
- package/Runtime/Core/Extension/RandomExtensions.cs +9 -87
- package/Runtime/Core/Extension/UnityExtensions.cs +2 -2
- package/Runtime/Core/Helper/Helpers.cs +1 -556
- package/Runtime/Core/Helper/Partials/LogHelpers.cs +13 -0
- package/Runtime/Core/Helper/Partials/LogHelpers.cs.meta +3 -0
- package/Runtime/Core/Helper/Partials/MathHelpers.cs +30 -0
- package/Runtime/Core/Helper/Partials/MathHelpers.cs.meta +3 -0
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs +388 -0
- package/Runtime/Core/Helper/Partials/ObjectHelpers.cs.meta +3 -0
- package/Runtime/Core/Helper/Partials/TransformHelpers.cs +167 -0
- package/Runtime/Core/Helper/Partials/TransformHelpers.cs.meta +3 -0
- package/Runtime/Core/Helper/Partials.meta +3 -0
- package/Runtime/Core/Random/AbstractRandom.cs +140 -154
- package/Runtime/Core/Random/IRandom.cs +26 -7
- package/Runtime/Core/Random/PerlinNoise.cs +369 -0
- package/Runtime/Core/Random/PerlinNoise.cs.meta +3 -0
- package/Runtime/Core/Random/SquirrelRandom.cs +9 -10
- package/Runtime/Core/Random/SystemRandom.cs +78 -41
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs +27 -0
- package/Tests/Runtime/Extensions/RandomExtensionTests.cs.meta +3 -0
- package/Tests/Runtime/Helper/ObjectHelperTests.cs +402 -0
- package/Tests/Runtime/Helper/ObjectHelperTests.cs.meta +3 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +58 -3
- package/Tests/Runtime/Random/RandomTestBase.cs +557 -6
- package/Tests/Runtime/Random/SquirrelRandomTests.cs +5 -0
- package/package.json +1 -1
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
public static class DirectionExtensions
|
|
11
11
|
{
|
|
12
|
-
private static readonly
|
|
12
|
+
private static readonly Direction[] Directions = Enum.GetValues(typeof(Direction))
|
|
13
|
+
.OfType<Direction>()
|
|
14
|
+
.Except(Enumerables.Of(Direction.None))
|
|
15
|
+
.ToArray();
|
|
13
16
|
|
|
14
17
|
public static Direction Opposite(this Direction direction)
|
|
15
18
|
{
|
|
@@ -106,7 +109,7 @@
|
|
|
106
109
|
|
|
107
110
|
public static Direction AsDirection(this Vector2 vector, bool preferAngles = false)
|
|
108
111
|
{
|
|
109
|
-
if (vector
|
|
112
|
+
if (vector == Vector2.zero)
|
|
110
113
|
{
|
|
111
114
|
return Direction.None;
|
|
112
115
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Extension
|
|
2
2
|
{
|
|
3
|
-
using Random;
|
|
4
3
|
using System;
|
|
5
4
|
using System.Collections.Concurrent;
|
|
6
5
|
using System.Collections.Generic;
|
|
7
6
|
using System.Linq;
|
|
7
|
+
using Random;
|
|
8
8
|
|
|
9
9
|
public static class IEnumerableExtensions
|
|
10
10
|
{
|
|
11
11
|
private static readonly ConcurrentDictionary<object, object> ComparerCache = new();
|
|
12
12
|
|
|
13
|
+
public static LinkedList<T> ToLinkedList<T>(this IEnumerable<T> source)
|
|
14
|
+
{
|
|
15
|
+
return new LinkedList<T>(source);
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
public static IList<T> AsList<T>(this IEnumerable<T> enumeration)
|
|
14
19
|
{
|
|
15
20
|
if (enumeration is IList<T> list)
|
|
@@ -20,18 +25,27 @@
|
|
|
20
25
|
return enumeration.ToList();
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
public static IEnumerable<T> OrderBy<T>(
|
|
28
|
+
public static IEnumerable<T> OrderBy<T>(
|
|
29
|
+
this IEnumerable<T> enumeration,
|
|
30
|
+
Func<T, T, int> comparer
|
|
31
|
+
)
|
|
24
32
|
{
|
|
25
|
-
FuncBasedComparer<T> comparerObject =
|
|
33
|
+
FuncBasedComparer<T> comparerObject =
|
|
34
|
+
(FuncBasedComparer<T>)
|
|
35
|
+
ComparerCache.GetOrAdd(comparer, () => new FuncBasedComparer<T>(comparer));
|
|
26
36
|
return enumeration.OrderBy(_ => _, comparerObject);
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
public static IEnumerable<T> Ordered<T>(this IEnumerable<T> enumerable)
|
|
39
|
+
public static IEnumerable<T> Ordered<T>(this IEnumerable<T> enumerable)
|
|
40
|
+
where T : IComparable
|
|
30
41
|
{
|
|
31
42
|
return enumerable.OrderBy(_ => _);
|
|
32
43
|
}
|
|
33
44
|
|
|
34
|
-
public static IEnumerable<T> Shuffled<T>(
|
|
45
|
+
public static IEnumerable<T> Shuffled<T>(
|
|
46
|
+
this IEnumerable<T> enumerable,
|
|
47
|
+
IRandom random = null
|
|
48
|
+
)
|
|
35
49
|
{
|
|
36
50
|
random = random ?? ThreadLocalRandom<PcgRandom>.Instance;
|
|
37
51
|
return enumerable.OrderBy(_ => random.Next());
|
|
@@ -90,7 +104,6 @@
|
|
|
90
104
|
return list;
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
|
|
94
107
|
private class FuncBasedComparer<T> : IComparer<T>
|
|
95
108
|
{
|
|
96
109
|
private readonly Func<T, T, int> _comparer;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Extension
|
|
2
2
|
{
|
|
3
|
-
using System;
|
|
4
|
-
using System.Collections.Generic;
|
|
5
|
-
using System.Linq;
|
|
6
3
|
using Helper;
|
|
7
4
|
using Random;
|
|
8
5
|
using UnityEngine;
|
|
@@ -14,15 +11,6 @@
|
|
|
14
11
|
return random.NextVector2(-amplitude, amplitude);
|
|
15
12
|
}
|
|
16
13
|
|
|
17
|
-
public static Vector2 NextVector2InRange(
|
|
18
|
-
this IRandom random,
|
|
19
|
-
float range,
|
|
20
|
-
Vector2? origin = null
|
|
21
|
-
)
|
|
22
|
-
{
|
|
23
|
-
return Helpers.GetRandomPointInCircle(origin ?? Vector2.zero, range, random);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
14
|
public static Vector2 NextVector2(
|
|
27
15
|
this IRandom random,
|
|
28
16
|
float minAmplitude,
|
|
@@ -34,6 +22,15 @@
|
|
|
34
22
|
return new Vector2(x, y);
|
|
35
23
|
}
|
|
36
24
|
|
|
25
|
+
public static Vector2 NextVector2InRange(
|
|
26
|
+
this IRandom random,
|
|
27
|
+
float range,
|
|
28
|
+
Vector2? origin = null
|
|
29
|
+
)
|
|
30
|
+
{
|
|
31
|
+
return Helpers.GetRandomPointInCircle(origin ?? Vector2.zero, range, random);
|
|
32
|
+
}
|
|
33
|
+
|
|
37
34
|
public static Vector3 NextVector3(this IRandom random, float amplitude)
|
|
38
35
|
{
|
|
39
36
|
return random.NextVector3(-amplitude, amplitude);
|
|
@@ -50,80 +47,5 @@
|
|
|
50
47
|
result.z = z;
|
|
51
48
|
return result;
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
public static T NextEnum<T>(this IRandom random)
|
|
55
|
-
where T : struct
|
|
56
|
-
{
|
|
57
|
-
T[] enumValues = (T[])Enum.GetValues(typeof(T));
|
|
58
|
-
if (enumValues.Length == 0)
|
|
59
|
-
{
|
|
60
|
-
return default(T);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (enumValues.Length == 1)
|
|
64
|
-
{
|
|
65
|
-
return enumValues[0];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (enumValues.Length == 2)
|
|
69
|
-
{
|
|
70
|
-
return random.NextBool() ? enumValues[0] : enumValues[1];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
int nextIndex = random.Next(0, enumValues.Length);
|
|
74
|
-
return enumValues[nextIndex];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public static T Next<T>(this IRandom random, IList<T> elements)
|
|
78
|
-
{
|
|
79
|
-
if (ReferenceEquals(elements, null) || elements.Count == 0)
|
|
80
|
-
{
|
|
81
|
-
return default(T);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
switch (elements.Count)
|
|
85
|
-
{
|
|
86
|
-
case 1:
|
|
87
|
-
return elements[0];
|
|
88
|
-
case 2:
|
|
89
|
-
return random.NextBool() ? elements[0] : elements[1];
|
|
90
|
-
default:
|
|
91
|
-
int index = random.Next(0, elements.Count);
|
|
92
|
-
return elements[index];
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public static T Next<T>(this IRandom random, IEnumerable<T> elements)
|
|
97
|
-
{
|
|
98
|
-
if (ReferenceEquals(elements, null))
|
|
99
|
-
{
|
|
100
|
-
return default(T);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
IList<T> elementsList = elements as IList<T>;
|
|
104
|
-
if (!ReferenceEquals(elementsList, null))
|
|
105
|
-
{
|
|
106
|
-
return Next(random, elementsList);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
ICollection<T> maybeCollection = elements as ICollection<T>;
|
|
110
|
-
if (!ReferenceEquals(maybeCollection, null))
|
|
111
|
-
{
|
|
112
|
-
int count = maybeCollection.Count;
|
|
113
|
-
int randomIndex = random.Next(0, count);
|
|
114
|
-
|
|
115
|
-
int i = 0;
|
|
116
|
-
foreach (T element in maybeCollection)
|
|
117
|
-
{
|
|
118
|
-
if (i++ == randomIndex)
|
|
119
|
-
{
|
|
120
|
-
return element;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
elementsList = elements.ToArray();
|
|
126
|
-
return Next(random, elementsList);
|
|
127
|
-
}
|
|
128
50
|
}
|
|
129
51
|
}
|
|
@@ -266,7 +266,7 @@
|
|
|
266
266
|
return convexHull;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
Vector3Int nextPoint = random.
|
|
269
|
+
Vector3Int nextPoint = random.NextOf(points);
|
|
270
270
|
Vector2 currentPointWorldPosition = CellToWorld(currentPoint);
|
|
271
271
|
Vector2 nextPointWorldPosition = CellToWorld(nextPoint);
|
|
272
272
|
foreach (Vector3Int point in points)
|
|
@@ -389,7 +389,7 @@
|
|
|
389
389
|
return convexHull;
|
|
390
390
|
}
|
|
391
391
|
|
|
392
|
-
FastVector3Int nextPoint = random.
|
|
392
|
+
FastVector3Int nextPoint = random.NextOf(points);
|
|
393
393
|
Vector2 currentPointWorldPosition = CellToWorld(currentPoint);
|
|
394
394
|
Vector2 nextPointWorldPosition = CellToWorld(nextPoint);
|
|
395
395
|
foreach (FastVector3Int point in points)
|