com.wallstop-studios.unity-helpers 1.0.0-rc4
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/.gitattributes +63 -0
- package/CHANGELOG.md +0 -0
- package/CHANGELOG.md.meta +7 -0
- package/Editor/AnimationCreator.cs +218 -0
- package/Editor/AnimationCreator.cs.meta +11 -0
- package/Editor/AnimationEventEditor.cs +742 -0
- package/Editor/AnimationEventEditor.cs.meta +11 -0
- package/Editor/PrefabCheckWizard.cs +140 -0
- package/Editor/PrefabCheckWizard.cs.meta +11 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +16 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef.meta +7 -0
- package/Editor.meta +8 -0
- package/LICENSE +21 -0
- package/LICENSE.md +7 -0
- package/LICENSE.md.meta +7 -0
- package/LICENSE.meta +7 -0
- package/README.md +2 -0
- package/README.md.meta +7 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs +102 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs +43 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs +85 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs +23 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs +33 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ParentComponent.cs +85 -0
- package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +8 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +14 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +89 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +66 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes.meta +8 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +91 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +180 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs +274 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs +79 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters.meta +8 -0
- package/Runtime/Core/DataStructure/Circle.cs +50 -0
- package/Runtime/Core/DataStructure/Circle.cs.meta +11 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +130 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs +58 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/KDTree.cs +186 -0
- package/Runtime/Core/DataStructure/KDTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/QuadTree.cs +184 -0
- package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/RTree.cs +247 -0
- package/Runtime/Core/DataStructure/RTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs +90 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -0
- package/Runtime/Core/DataStructure/TimedCache.cs +50 -0
- package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -0
- package/Runtime/Core/DataStructure.meta +8 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs +25 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/CircleExtensions.cs +25 -0
- package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/ColorExtensions.cs +72 -0
- package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs +173 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs +210 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs +12 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +109 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IListExtensions.cs +49 -0
- package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs +196 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/RandomExtensions.cs +110 -0
- package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/StringExtensions.cs +76 -0
- package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/UnityExtensions.cs +1409 -0
- package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension.meta +8 -0
- package/Runtime/Core/Helper/AssignUtilities.cs +14 -0
- package/Runtime/Core/Helper/AssignUtilities.cs.meta +11 -0
- package/Runtime/Core/Helper/Enumerables.cs +17 -0
- package/Runtime/Core/Helper/Enumerables.cs.meta +11 -0
- package/Runtime/Core/Helper/Geometry.cs +26 -0
- package/Runtime/Core/Helper/Geometry.cs.meta +11 -0
- package/Runtime/Core/Helper/Helpers.cs +1092 -0
- package/Runtime/Core/Helper/Helpers.cs.meta +11 -0
- package/Runtime/Core/Helper/IterationHelpers.cs +32 -0
- package/Runtime/Core/Helper/IterationHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs +12 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/Objects.cs +447 -0
- package/Runtime/Core/Helper/Objects.cs.meta +11 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs +53 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/StringInList.cs +31 -0
- package/Runtime/Core/Helper/StringInList.cs.meta +11 -0
- package/Runtime/Core/Helper/WallMath.cs +75 -0
- package/Runtime/Core/Helper/WallMath.cs.meta +11 -0
- package/Runtime/Core/Helper.meta +8 -0
- package/Runtime/Core/Math/Line.cs +51 -0
- package/Runtime/Core/Math/Line.cs.meta +11 -0
- package/Runtime/Core/Math/Parabola.cs +44 -0
- package/Runtime/Core/Math/Parabola.cs.meta +11 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs +25 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs.meta +11 -0
- package/Runtime/Core/Math/Range.cs +56 -0
- package/Runtime/Core/Math/Range.cs.meta +11 -0
- package/Runtime/Core/Math/XXHash.cs +308 -0
- package/Runtime/Core/Math/XXHash.cs.meta +11 -0
- package/Runtime/Core/Math.meta +8 -0
- package/Runtime/Core/Model/Direction.cs +26 -0
- package/Runtime/Core/Model/Direction.cs.meta +11 -0
- package/Runtime/Core/Model.meta +8 -0
- package/Runtime/Core/OneOf/FastOneOf.cs +145 -0
- package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -0
- package/Runtime/Core/OneOf/None.cs +6 -0
- package/Runtime/Core/OneOf/None.cs.meta +11 -0
- package/Runtime/Core/OneOf.meta +8 -0
- package/Runtime/Core/Random/AbstractRandom.cs +537 -0
- package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -0
- package/Runtime/Core/Random/IRandom.cs +141 -0
- package/Runtime/Core/Random/IRandom.cs.meta +11 -0
- package/Runtime/Core/Random/NativePcgRandom.cs +97 -0
- package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/PcgRandom.cs +142 -0
- package/Runtime/Core/Random/PcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/RandomState.cs +92 -0
- package/Runtime/Core/Random/RandomState.cs.meta +11 -0
- package/Runtime/Core/Random/RandomUtilities.cs +26 -0
- package/Runtime/Core/Random/RandomUtilities.cs.meta +11 -0
- package/Runtime/Core/Random/SquirrelRandom.cs +82 -0
- package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -0
- package/Runtime/Core/Random/SystemRandom.cs +110 -0
- package/Runtime/Core/Random/SystemRandom.cs.meta +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -0
- package/Runtime/Core/Random/UnityRandom.cs +24 -0
- package/Runtime/Core/Random/UnityRandom.cs.meta +11 -0
- package/Runtime/Core/Random/XorShiftRandom.cs +45 -0
- package/Runtime/Core/Random/XorShiftRandom.cs.meta +11 -0
- package/Runtime/Core/Random.meta +8 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters.meta +8 -0
- package/Runtime/Core/Serialization/Serializer.cs +125 -0
- package/Runtime/Core/Serialization/Serializer.cs.meta +11 -0
- package/Runtime/Core/Serialization.meta +8 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +102 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -0
- package/Runtime/Core/Threading.meta +8 -0
- package/Runtime/Core.meta +8 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll +0 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll +0 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll +0 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll.meta +33 -0
- package/Runtime/Protobuf-Net.meta +8 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs +149 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +80 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -0
- package/Runtime/Utils/Buffers.cs +32 -0
- package/Runtime/Utils/Buffers.cs.meta +11 -0
- package/Runtime/Utils/CircleLineRenderer.cs +122 -0
- package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -0
- package/Runtime/Utils/Oscillator.cs +25 -0
- package/Runtime/Utils/Oscillator.cs.meta +11 -0
- package/Runtime/Utils/SetTextureImportData.cs +67 -0
- package/Runtime/Utils/SetTextureImportData.cs.meta +11 -0
- package/Runtime/Utils.meta +8 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef +14 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef +17 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef.meta +7 -0
- package/Tests/Editor.meta +8 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +106 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures.meta +8 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +76 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +141 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs.meta +11 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/Performance.meta +8 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs +9 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/RandomTestBase.cs +117 -0
- package/Tests/Runtime/Random/RandomTestBase.cs.meta +11 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs +9 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs +10 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs +9 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs +9 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random.meta +8 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef +22 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef.meta +7 -0
- package/Tests/Runtime.meta +8 -0
- package/Tests.meta +8 -0
- package/Third Party Notices.md +1 -0
- package/Third Party Notices.md.meta +7 -0
- package/package.json +35 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure.Adapters
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
5
|
+
using Helper;
|
|
6
|
+
using ProtoBuf;
|
|
7
|
+
|
|
8
|
+
[Serializable]
|
|
9
|
+
[DataContract]
|
|
10
|
+
[ProtoContract]
|
|
11
|
+
public struct KGuid : IEquatable<KGuid>, IEquatable<Guid>, IComparable<KGuid>
|
|
12
|
+
{
|
|
13
|
+
/*
|
|
14
|
+
We need to store this in a NetworkList somewhere, and that means we can't have arrays.
|
|
15
|
+
Since we know the underlying data, do this shit (this is what a Guid looks like anyway)...
|
|
16
|
+
*/
|
|
17
|
+
[ProtoMember(1)]
|
|
18
|
+
private int _a;
|
|
19
|
+
[ProtoMember(2)]
|
|
20
|
+
private short _b;
|
|
21
|
+
[ProtoMember(3)]
|
|
22
|
+
private short _c;
|
|
23
|
+
[ProtoMember(4)]
|
|
24
|
+
private byte _d;
|
|
25
|
+
[ProtoMember(5)]
|
|
26
|
+
private byte _e;
|
|
27
|
+
[ProtoMember(6)]
|
|
28
|
+
private byte _f;
|
|
29
|
+
[ProtoMember(7)]
|
|
30
|
+
private byte _g;
|
|
31
|
+
[ProtoMember(8)]
|
|
32
|
+
private byte _h;
|
|
33
|
+
[ProtoMember(9)]
|
|
34
|
+
private byte _i;
|
|
35
|
+
[ProtoMember(10)]
|
|
36
|
+
private byte _j;
|
|
37
|
+
[ProtoMember(11)]
|
|
38
|
+
private byte _k;
|
|
39
|
+
|
|
40
|
+
private int _hashCode;
|
|
41
|
+
|
|
42
|
+
[DataMember]
|
|
43
|
+
private string Guid => ((Guid) this).ToString();
|
|
44
|
+
|
|
45
|
+
public static KGuid NewGuid()
|
|
46
|
+
{
|
|
47
|
+
return new KGuid(System.Guid.NewGuid());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public KGuid(Guid guid) : this(guid.ToByteArray())
|
|
51
|
+
{
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public KGuid(byte[] guidBytes)
|
|
55
|
+
{
|
|
56
|
+
_a = (int)guidBytes[3] << 24 | (int)guidBytes[2] << 16 | (int)guidBytes[1] << 8 | (int)guidBytes[0];
|
|
57
|
+
_b = (short)((int)guidBytes[5] << 8 | (int)guidBytes[4]);
|
|
58
|
+
_c = (short)((int)guidBytes[7] << 8 | (int)guidBytes[6]);
|
|
59
|
+
_d = guidBytes[8];
|
|
60
|
+
_e = guidBytes[9];
|
|
61
|
+
_f = guidBytes[10];
|
|
62
|
+
_g = guidBytes[11];
|
|
63
|
+
_h = guidBytes[12];
|
|
64
|
+
_i = guidBytes[13];
|
|
65
|
+
_j = guidBytes[14];
|
|
66
|
+
_k = guidBytes[15];
|
|
67
|
+
_hashCode = 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public static implicit operator Guid(KGuid guid)
|
|
71
|
+
{
|
|
72
|
+
return new Guid(guid._a, guid._b, guid._c, guid._d, guid._e, guid._f, guid._g, guid._h, guid._i, guid._j, guid._k);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public static implicit operator KGuid(Guid guid)
|
|
76
|
+
{
|
|
77
|
+
return new KGuid(guid);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public static bool operator ==(KGuid lhs, KGuid rhs)
|
|
81
|
+
{
|
|
82
|
+
return lhs.Equals(rhs);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public static bool operator !=(KGuid lhs, KGuid rhs)
|
|
86
|
+
{
|
|
87
|
+
return !lhs.Equals(rhs);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public bool Equals(KGuid other)
|
|
91
|
+
{
|
|
92
|
+
if (GetHashCode() != other.GetHashCode())
|
|
93
|
+
{
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (_a != other._a)
|
|
98
|
+
{
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (_b != other._b)
|
|
103
|
+
{
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (_c != other._c)
|
|
108
|
+
{
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (_d != other._d)
|
|
113
|
+
{
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (_e != other._e)
|
|
118
|
+
{
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (_f != other._f)
|
|
123
|
+
{
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (_g != other._g)
|
|
128
|
+
{
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (_h != other._h)
|
|
133
|
+
{
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (_i != other._i)
|
|
138
|
+
{
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (_j != other._j)
|
|
143
|
+
{
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return _k == other._k;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public bool Equals(Guid other)
|
|
151
|
+
{
|
|
152
|
+
return other.Equals(new Guid(_a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public int CompareTo(KGuid other)
|
|
156
|
+
{
|
|
157
|
+
int comparison = _a.CompareTo(other._a);
|
|
158
|
+
if (comparison != 0)
|
|
159
|
+
{
|
|
160
|
+
return comparison;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
comparison = _b.CompareTo(other._b);
|
|
164
|
+
if (comparison != 0)
|
|
165
|
+
{
|
|
166
|
+
return comparison;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
comparison = _c.CompareTo(other._c);
|
|
170
|
+
if (comparison != 0)
|
|
171
|
+
{
|
|
172
|
+
return comparison;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
comparison = _d.CompareTo(other._d);
|
|
176
|
+
if (comparison != 0)
|
|
177
|
+
{
|
|
178
|
+
return comparison;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
comparison = _e.CompareTo(other._e);
|
|
182
|
+
if (comparison != 0)
|
|
183
|
+
{
|
|
184
|
+
return comparison;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
comparison = _f.CompareTo(other._f);
|
|
188
|
+
if (comparison != 0)
|
|
189
|
+
{
|
|
190
|
+
return comparison;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
comparison = _g.CompareTo(other._g);
|
|
194
|
+
if (comparison != 0)
|
|
195
|
+
{
|
|
196
|
+
return comparison;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
comparison = _h.CompareTo(other._h);
|
|
200
|
+
if (comparison != 0)
|
|
201
|
+
{
|
|
202
|
+
return comparison;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
comparison = _i.CompareTo(other._i);
|
|
206
|
+
if (comparison != 0)
|
|
207
|
+
{
|
|
208
|
+
return comparison;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
comparison = _j.CompareTo(other._j);
|
|
212
|
+
if (comparison != 0)
|
|
213
|
+
{
|
|
214
|
+
return comparison;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return _k.CompareTo(other._k);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public override bool Equals(object other)
|
|
221
|
+
{
|
|
222
|
+
return other switch
|
|
223
|
+
{
|
|
224
|
+
KGuid otherKGuid => Equals(otherKGuid),
|
|
225
|
+
Guid otherGuid => Equals(otherGuid),
|
|
226
|
+
_ => false
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public override int GetHashCode()
|
|
231
|
+
{
|
|
232
|
+
if (_hashCode == 0)
|
|
233
|
+
{
|
|
234
|
+
_hashCode = Objects.ValueTypeHashCode(_a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return _hashCode;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
public override string ToString()
|
|
241
|
+
{
|
|
242
|
+
return Guid;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
public byte[] ToByteArray()
|
|
246
|
+
{
|
|
247
|
+
return new []
|
|
248
|
+
{
|
|
249
|
+
(byte) _a,
|
|
250
|
+
(byte) (_a >> 8),
|
|
251
|
+
(byte) (_a >> 16),
|
|
252
|
+
(byte) (_a >> 24),
|
|
253
|
+
(byte) _b,
|
|
254
|
+
(byte) ((uint) _b >> 8),
|
|
255
|
+
(byte) _c,
|
|
256
|
+
(byte) ((uint) _c >> 8),
|
|
257
|
+
_d,
|
|
258
|
+
_e,
|
|
259
|
+
_f,
|
|
260
|
+
_g,
|
|
261
|
+
_h,
|
|
262
|
+
_i,
|
|
263
|
+
_j,
|
|
264
|
+
_k
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
[ProtoAfterDeserialization]
|
|
269
|
+
private void AfterDeserialize()
|
|
270
|
+
{
|
|
271
|
+
_hashCode = 0;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure.Adapters
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Runtime.Serialization;
|
|
5
|
+
using Helper;
|
|
6
|
+
using ProtoBuf;
|
|
7
|
+
using UnityEngine;
|
|
8
|
+
|
|
9
|
+
[Serializable]
|
|
10
|
+
[DataContract]
|
|
11
|
+
[ProtoContract]
|
|
12
|
+
public struct KVector2 : IEquatable<KVector2>, IEquatable<Vector2>
|
|
13
|
+
{
|
|
14
|
+
[DataMember]
|
|
15
|
+
[ProtoMember(1)]
|
|
16
|
+
public float x;
|
|
17
|
+
[DataMember]
|
|
18
|
+
[ProtoMember(2)]
|
|
19
|
+
public float y;
|
|
20
|
+
|
|
21
|
+
public float Magnitude => (float)Math.Sqrt(x * (double)x + y * (double)y);
|
|
22
|
+
|
|
23
|
+
public KVector2(float x, float y)
|
|
24
|
+
{
|
|
25
|
+
this.x = x;
|
|
26
|
+
this.y = y;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public KVector2(Vector2 vector)
|
|
30
|
+
{
|
|
31
|
+
x = vector.x;
|
|
32
|
+
y = vector.y;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static implicit operator Vector2(KVector2 vector)
|
|
36
|
+
{
|
|
37
|
+
return new Vector2(vector.x, vector.y);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static implicit operator KVector2(Vector2 vector)
|
|
41
|
+
{
|
|
42
|
+
return new KVector2(vector);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public bool Equals(Vector2 vector)
|
|
46
|
+
{
|
|
47
|
+
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
48
|
+
if (x != vector.x)
|
|
49
|
+
{
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
54
|
+
return y == vector.y;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public bool Equals(KVector2 vector)
|
|
58
|
+
{
|
|
59
|
+
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
60
|
+
if (x != vector.x)
|
|
61
|
+
{
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
|
66
|
+
return y == vector.y;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public override bool Equals(object obj)
|
|
70
|
+
{
|
|
71
|
+
return obj is KVector2 vector && Equals(vector);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public override int GetHashCode()
|
|
75
|
+
{
|
|
76
|
+
return Objects.ValueTypeHashCode(x, y);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using Extension;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
|
|
7
|
+
public readonly struct Circle
|
|
8
|
+
{
|
|
9
|
+
public readonly Vector2 center;
|
|
10
|
+
public readonly float radius;
|
|
11
|
+
private readonly float _radiusSquared;
|
|
12
|
+
|
|
13
|
+
public Circle(Vector2 center, float radius)
|
|
14
|
+
{
|
|
15
|
+
this.center = center;
|
|
16
|
+
this.radius = radius;
|
|
17
|
+
_radiusSquared = radius * radius;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public bool Contains(Vector2 point)
|
|
21
|
+
{
|
|
22
|
+
return (center - point).sqrMagnitude <= _radiusSquared;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public bool Intersects(Bounds bounds)
|
|
26
|
+
{
|
|
27
|
+
return Intersects(bounds.Rect());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// https://www.geeksforgeeks.org/check-if-any-point-overlaps-the-given-circle-and-rectangle/
|
|
31
|
+
public bool Intersects(Rect rectangle)
|
|
32
|
+
{
|
|
33
|
+
float xN = Math.Max(center.x, rectangle.x);
|
|
34
|
+
float yN = Math.Max(center.y, rectangle.y);
|
|
35
|
+
float dX = xN - center.x;
|
|
36
|
+
float dY = yN - center.y;
|
|
37
|
+
return (dX * dX + dY * dY) <= _radiusSquared;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public bool Overlaps(Bounds bounds)
|
|
41
|
+
{
|
|
42
|
+
return Overlaps(bounds.Rect());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public bool Overlaps(Rect rectangle)
|
|
46
|
+
{
|
|
47
|
+
return Contains(rectangle.min) && Contains(rectangle.max);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure
|
|
2
|
+
{
|
|
3
|
+
using Helper;
|
|
4
|
+
using System;
|
|
5
|
+
using System.Collections;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using System.ComponentModel;
|
|
8
|
+
|
|
9
|
+
public enum BufferAddMethod
|
|
10
|
+
{
|
|
11
|
+
Prepend,
|
|
12
|
+
Append
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
[Serializable]
|
|
16
|
+
public sealed class CyclicBuffer<T> : IEnumerable<T>
|
|
17
|
+
{
|
|
18
|
+
private readonly T[] _buffer;
|
|
19
|
+
|
|
20
|
+
private int _position;
|
|
21
|
+
|
|
22
|
+
public readonly BufferAddMethod AddMethod;
|
|
23
|
+
|
|
24
|
+
public readonly int Capacity;
|
|
25
|
+
|
|
26
|
+
public int Count { get; private set; }
|
|
27
|
+
|
|
28
|
+
public readonly bool IsReadOnly;
|
|
29
|
+
|
|
30
|
+
public T this[int index]
|
|
31
|
+
{
|
|
32
|
+
get
|
|
33
|
+
{
|
|
34
|
+
BoundsCheck(index);
|
|
35
|
+
return _buffer[AdjustedIndexFor(index)];
|
|
36
|
+
}
|
|
37
|
+
set
|
|
38
|
+
{
|
|
39
|
+
BoundsCheck(index);
|
|
40
|
+
_buffer[AdjustedIndexFor(index)] = value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public CyclicBuffer(int capacity, BufferAddMethod addMethod = BufferAddMethod.Prepend)
|
|
45
|
+
{
|
|
46
|
+
if (capacity < 0)
|
|
47
|
+
{
|
|
48
|
+
throw new ArgumentException(nameof(capacity));
|
|
49
|
+
}
|
|
50
|
+
AddMethod = addMethod;
|
|
51
|
+
Capacity = capacity;
|
|
52
|
+
_position = 0;
|
|
53
|
+
_buffer = new T[capacity];
|
|
54
|
+
IsReadOnly = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public IEnumerator<T> GetEnumerator()
|
|
58
|
+
{
|
|
59
|
+
for (int i = 0; i < Count; ++i)
|
|
60
|
+
{
|
|
61
|
+
yield return this[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
IEnumerator IEnumerable.GetEnumerator()
|
|
66
|
+
{
|
|
67
|
+
return GetEnumerator();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public void Add(T item)
|
|
71
|
+
{
|
|
72
|
+
_buffer[_position] = item;
|
|
73
|
+
_position = WallMath.WrappedIncrement(_position, Capacity);
|
|
74
|
+
if (Count < Capacity)
|
|
75
|
+
{
|
|
76
|
+
++Count;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public void Clear()
|
|
81
|
+
{
|
|
82
|
+
/* Simply reset state */
|
|
83
|
+
Count = 0;
|
|
84
|
+
_position = 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public bool Peek(out T value)
|
|
88
|
+
{
|
|
89
|
+
if (InBounds(0))
|
|
90
|
+
{
|
|
91
|
+
value = this[0];
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
value = default(T);
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private int AdjustedIndexFor(int index)
|
|
99
|
+
{
|
|
100
|
+
switch (AddMethod)
|
|
101
|
+
{
|
|
102
|
+
case BufferAddMethod.Prepend:
|
|
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
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private void BoundsCheck(int index)
|
|
118
|
+
{
|
|
119
|
+
if (!InBounds(index))
|
|
120
|
+
{
|
|
121
|
+
throw new IndexOutOfRangeException($"{index} is outside of bounds [0, {Count})");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private bool InBounds(int index)
|
|
126
|
+
{
|
|
127
|
+
return !(Count <= index || index < 0);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
namespace UnityHelpers.Core.DataStructure
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using System.Linq;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
public interface ISpatialTree<T>
|
|
9
|
+
{
|
|
10
|
+
Bounds Boundary { get; }
|
|
11
|
+
Func<T, Vector2> ElementTransformer { get; }
|
|
12
|
+
|
|
13
|
+
IEnumerable<T> GetElementsInRange(Vector2 position, float range, float minimumRange = 0f)
|
|
14
|
+
{
|
|
15
|
+
Circle area = new(position, range);
|
|
16
|
+
Func<T, Vector2> elementTransformer = ElementTransformer;
|
|
17
|
+
if (0 < minimumRange)
|
|
18
|
+
{
|
|
19
|
+
Circle minimumArea = new(position, minimumRange);
|
|
20
|
+
return GetElementsInBounds(
|
|
21
|
+
new Bounds(
|
|
22
|
+
new Vector3(position.x, position.y, 0f),
|
|
23
|
+
new Vector3(range * 2f, range * 2f, 1f)))
|
|
24
|
+
.Where(
|
|
25
|
+
element =>
|
|
26
|
+
{
|
|
27
|
+
Vector2 elementPosition = elementTransformer(element);
|
|
28
|
+
if (!area.Contains(elementPosition))
|
|
29
|
+
{
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return !minimumArea.Contains(elementPosition);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return GetElementsInBounds(
|
|
38
|
+
new Bounds(
|
|
39
|
+
new Vector3(position.x, position.y, 0f),
|
|
40
|
+
new Vector3(range * 2f, range * 2f, 1f)))
|
|
41
|
+
.Where(
|
|
42
|
+
element =>
|
|
43
|
+
{
|
|
44
|
+
Vector2 elementPosition = elementTransformer(element);
|
|
45
|
+
if (!area.Contains(elementPosition))
|
|
46
|
+
{
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
IEnumerable<T> GetElementsInBounds(Bounds bounds);
|
|
55
|
+
|
|
56
|
+
void GetApproximateNearestNeighbors(Vector2 position, int count, List<T> nearestNeighbors);
|
|
57
|
+
}
|
|
58
|
+
}
|