com.wallstop-studios.unity-helpers 2.0.0-rc05 → 2.0.0-rc07
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/DataStructure/TimedCache.cs +4 -3
- package/Runtime/Core/Extension/IListExtensions.cs +2 -2
- package/Runtime/Core/Extension/RandomExtensions.cs +23 -4
- package/Runtime/Core/Extension/UnityExtensions.cs +278 -90
- package/Runtime/Core/Helper/ArrayConverter.cs +39 -0
- package/Runtime/Core/Helper/ArrayConverter.cs.meta +3 -0
- package/Runtime/Core/Helper/Helpers.cs +133 -563
- 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/Helper/WallMath.cs +85 -22
- package/Runtime/Core/Random/AbstractRandom.cs +208 -162
- package/Runtime/Core/Random/DotNetRandom.cs +3 -5
- package/Runtime/Core/Random/PRNG.cs +7 -0
- package/Runtime/Core/Random/PRNG.cs.meta +3 -0
- package/Runtime/Core/Random/PcgRandom.cs +4 -6
- package/Runtime/Core/Random/RandomState.cs +31 -3
- package/Runtime/Core/Random/SquirrelRandom.cs +12 -15
- package/Runtime/Core/Random/SystemRandom.cs +92 -46
- package/Runtime/Core/Random/ThreadLocalRandom.cs +2 -1
- package/Runtime/Core/Random/UnityRandom.cs +2 -4
- package/Runtime/Core/Random/WyRandom.cs +2 -4
- package/Runtime/Core/Random/XorShiftRandom.cs +3 -5
- package/Runtime/Core/Serialization/Serializer.cs +36 -14
- package/Runtime/Utils/CircleLineRenderer.cs +17 -5
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +34 -10
- package/Tests/Runtime/Helper/ArrayConverterTests.cs +19 -0
- package/Tests/Runtime/Helper/ArrayConverterTests.cs.meta +3 -0
- package/Tests/Runtime/Helper/ObjectHelperTests.cs +402 -0
- package/Tests/Runtime/Helper/ObjectHelperTests.cs.meta +3 -0
- package/Tests/Runtime/Helper/WallMathTests.cs +221 -0
- package/Tests/Runtime/Helper/WallMathTests.cs.meta +3 -0
- package/Tests/Runtime/Helper.meta +3 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +58 -3
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +47 -34
- package/Tests/Runtime/Random/RandomTestBase.cs +284 -9
- package/Tests/Runtime/Random/SquirrelRandomTests.cs +5 -0
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +24 -11
- package/Tests/Runtime/Utils/SpriteRendererMetadataTests.cs +21 -17
- package/package.json +1 -1
|
@@ -15,8 +15,6 @@
|
|
|
15
15
|
IComparable,
|
|
16
16
|
IComparable<PcgRandom>
|
|
17
17
|
{
|
|
18
|
-
[DataMember(Name = "State")]
|
|
19
|
-
[JsonPropertyName("State")]
|
|
20
18
|
public static IRandom Instance => ThreadLocalRandom<PcgRandom>.Instance;
|
|
21
19
|
|
|
22
20
|
internal readonly ulong _increment;
|
|
@@ -34,11 +32,11 @@
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
[JsonConstructor]
|
|
37
|
-
public PcgRandom(RandomState
|
|
35
|
+
public PcgRandom(RandomState internalState)
|
|
38
36
|
{
|
|
39
|
-
_state =
|
|
40
|
-
_increment =
|
|
41
|
-
_cachedGaussian =
|
|
37
|
+
_state = internalState.State1;
|
|
38
|
+
_increment = internalState.State2;
|
|
39
|
+
_cachedGaussian = internalState.Gaussian;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
42
|
public PcgRandom(ulong increment, ulong state)
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
namespace UnityHelpers.Core.Random
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
|
+
using System.Linq;
|
|
5
|
+
using System.Runtime.Serialization;
|
|
4
6
|
using System.Text.Json.Serialization;
|
|
5
7
|
using Extension;
|
|
6
8
|
using Helper;
|
|
7
9
|
using ProtoBuf;
|
|
8
10
|
|
|
9
11
|
[Serializable]
|
|
12
|
+
[DataContract]
|
|
10
13
|
[ProtoContract]
|
|
11
14
|
public struct RandomState : IEquatable<RandomState>
|
|
12
15
|
{
|
|
13
16
|
public ulong State1 => _state1;
|
|
17
|
+
|
|
14
18
|
public ulong State2 => _state2;
|
|
15
19
|
|
|
16
20
|
public double? Gaussian
|
|
@@ -26,6 +30,8 @@
|
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
33
|
+
public byte[] Payload => _payload;
|
|
34
|
+
|
|
29
35
|
[ProtoMember(1)]
|
|
30
36
|
private ulong _state1;
|
|
31
37
|
|
|
@@ -38,16 +44,31 @@
|
|
|
38
44
|
[ProtoMember(4)]
|
|
39
45
|
private double _gaussian;
|
|
40
46
|
|
|
47
|
+
[ProtoMember(5)]
|
|
48
|
+
private byte[] _payload;
|
|
49
|
+
|
|
41
50
|
private int _hashCode;
|
|
42
51
|
|
|
43
52
|
[JsonConstructor]
|
|
44
|
-
public RandomState(
|
|
53
|
+
public RandomState(
|
|
54
|
+
ulong state1,
|
|
55
|
+
ulong state2 = 0,
|
|
56
|
+
double? gaussian = null,
|
|
57
|
+
byte[] payload = null
|
|
58
|
+
)
|
|
45
59
|
{
|
|
46
60
|
_state1 = state1;
|
|
47
61
|
_state2 = state2;
|
|
48
62
|
_hasGaussian = gaussian.HasValue;
|
|
49
63
|
_gaussian = gaussian ?? 0;
|
|
50
|
-
|
|
64
|
+
_payload = payload?.ToArray();
|
|
65
|
+
_hashCode = Objects.ValueTypeHashCode(
|
|
66
|
+
state1,
|
|
67
|
+
state2,
|
|
68
|
+
_hasGaussian,
|
|
69
|
+
_gaussian,
|
|
70
|
+
_payload != null
|
|
71
|
+
);
|
|
51
72
|
}
|
|
52
73
|
|
|
53
74
|
public RandomState(Guid guid)
|
|
@@ -57,7 +78,14 @@
|
|
|
57
78
|
_state2 = BitConverter.ToUInt64(guidBytes, sizeof(ulong));
|
|
58
79
|
_hasGaussian = false;
|
|
59
80
|
_gaussian = 0;
|
|
60
|
-
|
|
81
|
+
_payload = null;
|
|
82
|
+
_hashCode = Objects.ValueTypeHashCode(
|
|
83
|
+
_state1,
|
|
84
|
+
_state2,
|
|
85
|
+
_hasGaussian,
|
|
86
|
+
_gaussian,
|
|
87
|
+
_payload != null
|
|
88
|
+
);
|
|
61
89
|
}
|
|
62
90
|
|
|
63
91
|
[ProtoAfterDeserialization]
|
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
public static readonly SquirrelRandom Instance = ThreadLocalRandom<SquirrelRandom>.Instance;
|
|
18
18
|
|
|
19
|
-
[JsonPropertyName("State")]
|
|
20
|
-
[DataMember(Name = "State")]
|
|
21
19
|
public override RandomState InternalState => new(_position, gaussian: _cachedGaussian);
|
|
22
20
|
|
|
23
21
|
private uint _position;
|
|
@@ -31,15 +29,15 @@
|
|
|
31
29
|
}
|
|
32
30
|
|
|
33
31
|
[JsonConstructor]
|
|
34
|
-
public SquirrelRandom(RandomState
|
|
32
|
+
public SquirrelRandom(RandomState internalState)
|
|
35
33
|
{
|
|
36
|
-
_position = unchecked((uint)
|
|
37
|
-
_cachedGaussian =
|
|
34
|
+
_position = unchecked((uint)internalState.State1);
|
|
35
|
+
_cachedGaussian = internalState.Gaussian;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
public override uint NextUint()
|
|
41
39
|
{
|
|
42
|
-
return
|
|
40
|
+
return NextUintInternal(ref _position);
|
|
43
41
|
}
|
|
44
42
|
|
|
45
43
|
// Does not advance the RNG
|
|
@@ -53,16 +51,15 @@
|
|
|
53
51
|
return new SquirrelRandom(InternalState);
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
private static uint NextUintInternal(uint seed)
|
|
54
|
+
private static uint NextUintInternal(ref uint seed)
|
|
57
55
|
{
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return result;
|
|
56
|
+
seed *= BitNoise1;
|
|
57
|
+
seed ^= (seed >> 8);
|
|
58
|
+
seed += BitNoise2;
|
|
59
|
+
seed ^= (seed << 8);
|
|
60
|
+
seed *= BitNoise3;
|
|
61
|
+
seed ^= (seed >> 8);
|
|
62
|
+
return seed;
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
// https://youtu.be/LWFzPP8ZbdU?t=2906
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
using System;
|
|
4
4
|
using System.Runtime.Serialization;
|
|
5
5
|
using System.Text.Json.Serialization;
|
|
6
|
+
using Helper;
|
|
6
7
|
|
|
7
8
|
/// <summary>
|
|
8
9
|
/// Implementation dependent upon .Net's Random class.
|
|
@@ -11,105 +12,150 @@
|
|
|
11
12
|
[DataContract]
|
|
12
13
|
public sealed class SystemRandom : AbstractRandom
|
|
13
14
|
{
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
private const int HalfwayInt = int.MaxValue / 2;
|
|
16
|
+
private const int SeedArraySize = 56;
|
|
17
|
+
private const int LastSeedIndex = SeedArraySize - 1;
|
|
18
|
+
|
|
19
|
+
public static IRandom Instance => ThreadLocalRandom<SystemRandom>.Instance;
|
|
20
|
+
|
|
16
21
|
public override RandomState InternalState =>
|
|
17
|
-
new(
|
|
22
|
+
new(
|
|
23
|
+
unchecked((ulong)_inext),
|
|
24
|
+
unchecked((ulong)_inextp),
|
|
25
|
+
_cachedGaussian,
|
|
26
|
+
ArrayConverter.IntArrayToByteArrayBlockCopy(_seedArray)
|
|
27
|
+
);
|
|
18
28
|
|
|
19
29
|
/*
|
|
20
30
|
Copied from Random.cs source. Apparently it isn't guaranteed to be the
|
|
21
|
-
same across platforms
|
|
31
|
+
same across platforms, a fact which defeats the purpose of these serializable
|
|
32
|
+
randoms.
|
|
22
33
|
*/
|
|
23
|
-
private int
|
|
24
|
-
private int
|
|
25
|
-
private readonly int[]
|
|
26
|
-
|
|
27
|
-
public static IRandom Instance => ThreadLocalRandom<SystemRandom>.Instance;
|
|
34
|
+
private int _inext;
|
|
35
|
+
private int _inextp;
|
|
36
|
+
private readonly int[] _seedArray = new int[SeedArraySize];
|
|
28
37
|
|
|
29
38
|
public SystemRandom()
|
|
30
|
-
: this(
|
|
39
|
+
: this(Guid.NewGuid().GetHashCode()) { }
|
|
31
40
|
|
|
32
41
|
public SystemRandom(int seed)
|
|
33
42
|
{
|
|
34
43
|
int num1 = 161803398 - (seed == int.MinValue ? int.MaxValue : Math.Abs(seed));
|
|
35
|
-
|
|
44
|
+
_seedArray[LastSeedIndex] = num1;
|
|
36
45
|
int num2 = 1;
|
|
37
|
-
for (int index1 = 1; index1 <
|
|
46
|
+
for (int index1 = 1; index1 < LastSeedIndex; ++index1)
|
|
38
47
|
{
|
|
39
|
-
int index2 = 21 * index1 %
|
|
40
|
-
|
|
48
|
+
int index2 = 21 * index1 % LastSeedIndex;
|
|
49
|
+
_seedArray[index2] = num2;
|
|
41
50
|
num2 = num1 - num2;
|
|
42
51
|
if (num2 < 0)
|
|
52
|
+
{
|
|
43
53
|
num2 += int.MaxValue;
|
|
44
|
-
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
num1 = _seedArray[index2];
|
|
45
57
|
}
|
|
46
58
|
for (int index3 = 1; index3 < 5; ++index3)
|
|
47
59
|
{
|
|
48
|
-
for (int index4 = 1; index4 <
|
|
60
|
+
for (int index4 = 1; index4 < SeedArraySize; ++index4)
|
|
49
61
|
{
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
62
|
+
int value = _seedArray[index4] -= _seedArray[1 + (index4 + 30) % LastSeedIndex];
|
|
63
|
+
if (value < 0)
|
|
64
|
+
{
|
|
65
|
+
_seedArray[index4] += int.MaxValue;
|
|
66
|
+
}
|
|
53
67
|
}
|
|
54
68
|
}
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
|
|
70
|
+
_inext = 0;
|
|
71
|
+
_inextp = 21;
|
|
57
72
|
}
|
|
58
73
|
|
|
59
74
|
[JsonConstructor]
|
|
60
|
-
public SystemRandom(RandomState
|
|
75
|
+
public SystemRandom(RandomState internalState)
|
|
61
76
|
{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
unchecked
|
|
78
|
+
{
|
|
79
|
+
_inext = (int)internalState.State1;
|
|
80
|
+
_inextp = (int)internalState.State2;
|
|
81
|
+
}
|
|
82
|
+
_cachedGaussian = internalState.Gaussian;
|
|
83
|
+
_seedArray = ArrayConverter.ByteArrayToIntArrayBlockCopy(internalState.Payload);
|
|
65
84
|
}
|
|
66
85
|
|
|
67
|
-
public override
|
|
86
|
+
public override int Next()
|
|
68
87
|
{
|
|
69
|
-
int
|
|
70
|
-
int
|
|
88
|
+
int localINext = _inext;
|
|
89
|
+
int localINextP = _inextp;
|
|
71
90
|
int index1;
|
|
72
|
-
if ((index1 =
|
|
91
|
+
if ((index1 = localINext + 1) >= SeedArraySize)
|
|
92
|
+
{
|
|
73
93
|
index1 = 1;
|
|
94
|
+
}
|
|
95
|
+
|
|
74
96
|
int index2;
|
|
75
|
-
if ((index2 =
|
|
97
|
+
if ((index2 = localINextP + 1) >= SeedArraySize)
|
|
98
|
+
{
|
|
76
99
|
index2 = 1;
|
|
77
|
-
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
int num = _seedArray[index1] - _seedArray[index2];
|
|
78
103
|
if (num == int.MaxValue)
|
|
104
|
+
{
|
|
79
105
|
--num;
|
|
106
|
+
}
|
|
107
|
+
|
|
80
108
|
if (num < 0)
|
|
109
|
+
{
|
|
81
110
|
num += int.MaxValue;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_seedArray[index1] = num;
|
|
114
|
+
_inext = index1;
|
|
115
|
+
_inextp = index2;
|
|
116
|
+
return num;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public override uint NextUint()
|
|
120
|
+
{
|
|
121
|
+
if (NextBool())
|
|
122
|
+
{
|
|
123
|
+
return unchecked((uint)(Next() ^ 0x80000000));
|
|
124
|
+
}
|
|
125
|
+
return unchecked((uint)Next());
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public override bool NextBool()
|
|
129
|
+
{
|
|
130
|
+
return Next() < HalfwayInt;
|
|
86
131
|
}
|
|
87
132
|
|
|
88
133
|
public override double NextDouble()
|
|
89
134
|
{
|
|
90
|
-
double
|
|
135
|
+
double random;
|
|
91
136
|
do
|
|
92
137
|
{
|
|
93
|
-
|
|
94
|
-
} while (
|
|
138
|
+
random = Next() / (1.0 * int.MaxValue);
|
|
139
|
+
} while (1.0 <= random);
|
|
95
140
|
|
|
96
|
-
return
|
|
141
|
+
return random;
|
|
97
142
|
}
|
|
98
143
|
|
|
99
144
|
public override float NextFloat()
|
|
100
145
|
{
|
|
101
|
-
|
|
146
|
+
float random;
|
|
147
|
+
do
|
|
148
|
+
{
|
|
149
|
+
random = Next() * (1f / int.MaxValue);
|
|
150
|
+
} while (1f <= random);
|
|
151
|
+
|
|
152
|
+
return random;
|
|
102
153
|
}
|
|
103
154
|
|
|
104
155
|
public override IRandom Copy()
|
|
105
156
|
{
|
|
106
157
|
SystemRandom copy = new(InternalState);
|
|
107
|
-
|
|
108
|
-
for (int i = 0; i < SeedArray.Length; ++i)
|
|
109
|
-
{
|
|
110
|
-
copy.SeedArray[i] = SeedArray[i];
|
|
111
|
-
}
|
|
112
|
-
|
|
158
|
+
Array.Copy(_seedArray, copy._seedArray, _seedArray.Length);
|
|
113
159
|
return copy;
|
|
114
160
|
}
|
|
115
161
|
}
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
{
|
|
11
11
|
public static readonly UnityRandom Instance = new();
|
|
12
12
|
|
|
13
|
-
[JsonPropertyName("State")]
|
|
14
|
-
[DataMember(Name = "State")]
|
|
15
13
|
public override RandomState InternalState
|
|
16
14
|
{
|
|
17
15
|
get
|
|
@@ -38,11 +36,11 @@
|
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
[JsonConstructor]
|
|
41
|
-
public UnityRandom(RandomState
|
|
39
|
+
public UnityRandom(RandomState internalState)
|
|
42
40
|
{
|
|
43
41
|
unchecked
|
|
44
42
|
{
|
|
45
|
-
_seed =
|
|
43
|
+
_seed = internalState.Gaussian != null ? (int)internalState.State1 : null;
|
|
46
44
|
}
|
|
47
45
|
}
|
|
48
46
|
|
|
@@ -16,8 +16,6 @@
|
|
|
16
16
|
|
|
17
17
|
public static IRandom Instance => ThreadLocalRandom<WyRandom>.Instance;
|
|
18
18
|
|
|
19
|
-
[JsonPropertyName("State")]
|
|
20
|
-
[DataMember(Name = "State")]
|
|
21
19
|
public override RandomState InternalState => new RandomState(_state);
|
|
22
20
|
|
|
23
21
|
private ulong _state;
|
|
@@ -32,9 +30,9 @@
|
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
[JsonConstructor]
|
|
35
|
-
public WyRandom(RandomState
|
|
33
|
+
public WyRandom(RandomState internalState)
|
|
36
34
|
{
|
|
37
|
-
_state =
|
|
35
|
+
_state = internalState.State1;
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
public WyRandom(ulong state)
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
{
|
|
11
11
|
public static IRandom Instance => ThreadLocalRandom<XorShiftRandom>.Instance;
|
|
12
12
|
|
|
13
|
-
[JsonPropertyName("State")]
|
|
14
|
-
[DataMember(Name = "State")]
|
|
15
13
|
public override RandomState InternalState => new(_state, 0, _cachedGaussian);
|
|
16
14
|
|
|
17
15
|
private uint _state;
|
|
@@ -25,10 +23,10 @@
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
[JsonConstructor]
|
|
28
|
-
public XorShiftRandom(RandomState
|
|
26
|
+
public XorShiftRandom(RandomState internalState)
|
|
29
27
|
{
|
|
30
|
-
_state = unchecked((uint)
|
|
31
|
-
_cachedGaussian =
|
|
28
|
+
_state = unchecked((uint)internalState.State1);
|
|
29
|
+
_cachedGaussian = internalState.Gaussian;
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
public override uint NextUint()
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
{
|
|
3
3
|
using System;
|
|
4
4
|
using System.ComponentModel;
|
|
5
|
-
using Extension;
|
|
6
|
-
using JsonConverters;
|
|
7
5
|
using System.IO;
|
|
8
6
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
9
7
|
using System.Text;
|
|
10
8
|
using System.Text.Json;
|
|
11
9
|
using System.Text.Json.Serialization;
|
|
10
|
+
using Extension;
|
|
11
|
+
using JsonConverters;
|
|
12
12
|
|
|
13
13
|
internal static class SerializerEncoding
|
|
14
14
|
{
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
{
|
|
31
31
|
new JsonStringEnumConverter(),
|
|
32
32
|
Vector3Converter.Instance,
|
|
33
|
-
Vector2Converter.Instance
|
|
33
|
+
Vector2Converter.Instance,
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
36
|
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
{
|
|
46
46
|
new JsonStringEnumConverter(),
|
|
47
47
|
Vector3Converter.Instance,
|
|
48
|
-
Vector2Converter.Instance
|
|
48
|
+
Vector2Converter.Instance,
|
|
49
49
|
},
|
|
50
50
|
WriteIndented = true,
|
|
51
51
|
};
|
|
@@ -70,7 +70,10 @@
|
|
|
70
70
|
return ProtoDeserialize<T>(serialized);
|
|
71
71
|
default:
|
|
72
72
|
throw new InvalidEnumArgumentException(
|
|
73
|
-
nameof(serializationType),
|
|
73
|
+
nameof(serializationType),
|
|
74
|
+
(int)serializationType,
|
|
75
|
+
typeof(SerializationType)
|
|
76
|
+
);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
|
@@ -84,7 +87,10 @@
|
|
|
84
87
|
return ProtoSerialize(instance);
|
|
85
88
|
default:
|
|
86
89
|
throw new InvalidEnumArgumentException(
|
|
87
|
-
nameof(serializationType),
|
|
90
|
+
nameof(serializationType),
|
|
91
|
+
(int)serializationType,
|
|
92
|
+
typeof(SerializationType)
|
|
93
|
+
);
|
|
88
94
|
}
|
|
89
95
|
}
|
|
90
96
|
|
|
@@ -123,9 +129,14 @@
|
|
|
123
129
|
return memoryStream.ToArray();
|
|
124
130
|
}
|
|
125
131
|
|
|
126
|
-
public static T JsonDeserialize<T>(string data)
|
|
132
|
+
public static T JsonDeserialize<T>(string data, Type type = null)
|
|
127
133
|
{
|
|
128
|
-
return
|
|
134
|
+
return (T)
|
|
135
|
+
JsonSerializer.Deserialize(
|
|
136
|
+
data,
|
|
137
|
+
type ?? typeof(T),
|
|
138
|
+
SerializerEncoding.NormalJsonOptions
|
|
139
|
+
);
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
public static byte[] JsonSerialize<T>(T input)
|
|
@@ -135,13 +146,24 @@
|
|
|
135
146
|
|
|
136
147
|
public static string JsonStringify<T>(T input, bool pretty = false)
|
|
137
148
|
{
|
|
138
|
-
JsonSerializerOptions options =
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
JsonSerializerOptions options = pretty
|
|
150
|
+
? SerializerEncoding.PrettyJsonOptions
|
|
151
|
+
: SerializerEncoding.NormalJsonOptions;
|
|
152
|
+
Type parameterType = typeof(T);
|
|
153
|
+
if (
|
|
154
|
+
parameterType.IsAbstract
|
|
155
|
+
|| parameterType.IsInterface
|
|
156
|
+
|| parameterType == typeof(object)
|
|
157
|
+
)
|
|
141
158
|
{
|
|
142
159
|
object data = input;
|
|
143
|
-
|
|
144
|
-
|
|
160
|
+
if (data == null)
|
|
161
|
+
{
|
|
162
|
+
return "{}";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Type type = data.GetType();
|
|
166
|
+
return JsonSerializer.Serialize(data, type, options);
|
|
145
167
|
}
|
|
146
168
|
|
|
147
169
|
return JsonSerializer.Serialize(input, options);
|
|
@@ -159,4 +181,4 @@
|
|
|
159
181
|
File.WriteAllText(path, jsonAsText);
|
|
160
182
|
}
|
|
161
183
|
}
|
|
162
|
-
}
|
|
184
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
public int baseSegments = 4;
|
|
18
18
|
public float updateRateSeconds = 0.1f;
|
|
19
19
|
public Color color = Color.grey;
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
public Vector3 Offset
|
|
22
22
|
{
|
|
23
23
|
get => _offset;
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
[SiblingComponent]
|
|
28
28
|
private CircleCollider2D _collider;
|
|
29
|
+
|
|
29
30
|
[SiblingComponent]
|
|
30
31
|
private LineRenderer[] _lineRenderers;
|
|
31
32
|
|
|
@@ -70,7 +71,11 @@
|
|
|
70
71
|
|
|
71
72
|
if (maxLineWidth < minLineWidth)
|
|
72
73
|
{
|
|
73
|
-
this.LogWarn(
|
|
74
|
+
this.LogWarn(
|
|
75
|
+
"MaxLineWidth {0} smaller than MinLineWidth {1}.",
|
|
76
|
+
maxLineWidth,
|
|
77
|
+
minLineWidth
|
|
78
|
+
);
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -98,7 +103,10 @@
|
|
|
98
103
|
lineRenderer.positionCount = numSegments;
|
|
99
104
|
|
|
100
105
|
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
101
|
-
float lineWidth =
|
|
106
|
+
float lineWidth =
|
|
107
|
+
minLineWidth == maxLineWidth
|
|
108
|
+
? minLineWidth
|
|
109
|
+
: PRNG.Instance.NextFloat(minLineWidth, maxLineWidth);
|
|
102
110
|
|
|
103
111
|
lineRenderer.startWidth = lineWidth;
|
|
104
112
|
lineRenderer.endWidth = lineWidth;
|
|
@@ -106,12 +114,16 @@
|
|
|
106
114
|
float distanceMultiplier = _collider.radius;
|
|
107
115
|
|
|
108
116
|
float angle = 360f / numSegments;
|
|
109
|
-
float offsetRadians =
|
|
117
|
+
float offsetRadians = PRNG.Instance.NextFloat(angle);
|
|
110
118
|
float currentOffset = offsetRadians;
|
|
111
119
|
Vector3[] positions = new Vector3[numSegments];
|
|
112
120
|
for (int i = 0; i < numSegments; ++i)
|
|
113
121
|
{
|
|
114
|
-
positions[i] =
|
|
122
|
+
positions[i] =
|
|
123
|
+
new Vector3(
|
|
124
|
+
Mathf.Cos(Mathf.Deg2Rad * currentOffset),
|
|
125
|
+
Mathf.Sin(Mathf.Deg2Rad * currentOffset)
|
|
126
|
+
) * distanceMultiplier;
|
|
115
127
|
currentOffset += angle % 360f;
|
|
116
128
|
}
|
|
117
129
|
|