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.
Files changed (238) hide show
  1. package/.gitattributes +63 -0
  2. package/CHANGELOG.md +0 -0
  3. package/CHANGELOG.md.meta +7 -0
  4. package/Editor/AnimationCreator.cs +218 -0
  5. package/Editor/AnimationCreator.cs.meta +11 -0
  6. package/Editor/AnimationEventEditor.cs +742 -0
  7. package/Editor/AnimationEventEditor.cs.meta +11 -0
  8. package/Editor/PrefabCheckWizard.cs +140 -0
  9. package/Editor/PrefabCheckWizard.cs.meta +11 -0
  10. package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +16 -0
  11. package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef.meta +7 -0
  12. package/Editor.meta +8 -0
  13. package/LICENSE +21 -0
  14. package/LICENSE.md +7 -0
  15. package/LICENSE.md.meta +7 -0
  16. package/LICENSE.meta +7 -0
  17. package/README.md +2 -0
  18. package/README.md.meta +7 -0
  19. package/Runtime/Core/Attributes/AnimationEventAttribute.cs +102 -0
  20. package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -0
  21. package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs +43 -0
  22. package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs.meta +11 -0
  23. package/Runtime/Core/Attributes/ChildComponentAttribute.cs +85 -0
  24. package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -0
  25. package/Runtime/Core/Attributes/KSerializableAttribute.cs +23 -0
  26. package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -0
  27. package/Runtime/Core/Attributes/NotNullAttribute.cs +33 -0
  28. package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -0
  29. package/Runtime/Core/Attributes/ParentComponent.cs +85 -0
  30. package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -0
  31. package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +8 -0
  32. package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -0
  33. package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +14 -0
  34. package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -0
  35. package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +89 -0
  36. package/Runtime/Core/Attributes/SiblingComponentAttribute.cs.meta +11 -0
  37. package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +66 -0
  38. package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs.meta +11 -0
  39. package/Runtime/Core/Attributes.meta +8 -0
  40. package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +91 -0
  41. package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -0
  42. package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +180 -0
  43. package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -0
  44. package/Runtime/Core/DataStructure/Adapters/KGuid.cs +274 -0
  45. package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -0
  46. package/Runtime/Core/DataStructure/Adapters/KVector2.cs +79 -0
  47. package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -0
  48. package/Runtime/Core/DataStructure/Adapters.meta +8 -0
  49. package/Runtime/Core/DataStructure/Circle.cs +50 -0
  50. package/Runtime/Core/DataStructure/Circle.cs.meta +11 -0
  51. package/Runtime/Core/DataStructure/CyclicBuffer.cs +130 -0
  52. package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -0
  53. package/Runtime/Core/DataStructure/ISpatialTree.cs +58 -0
  54. package/Runtime/Core/DataStructure/ISpatialTree.cs.meta +11 -0
  55. package/Runtime/Core/DataStructure/KDTree.cs +186 -0
  56. package/Runtime/Core/DataStructure/KDTree.cs.meta +11 -0
  57. package/Runtime/Core/DataStructure/QuadTree.cs +184 -0
  58. package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -0
  59. package/Runtime/Core/DataStructure/RTree.cs +247 -0
  60. package/Runtime/Core/DataStructure/RTree.cs.meta +11 -0
  61. package/Runtime/Core/DataStructure/StringWrapper.cs +90 -0
  62. package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -0
  63. package/Runtime/Core/DataStructure/TimedCache.cs +50 -0
  64. package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -0
  65. package/Runtime/Core/DataStructure.meta +8 -0
  66. package/Runtime/Core/Extension/AnimatorExtensions.cs +25 -0
  67. package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -0
  68. package/Runtime/Core/Extension/CircleExtensions.cs +25 -0
  69. package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -0
  70. package/Runtime/Core/Extension/ColorExtensions.cs +72 -0
  71. package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -0
  72. package/Runtime/Core/Extension/DictionaryExtensions.cs +173 -0
  73. package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -0
  74. package/Runtime/Core/Extension/DirectionExtensions.cs +210 -0
  75. package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -0
  76. package/Runtime/Core/Extension/HashSetExtensions.cs +12 -0
  77. package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -0
  78. package/Runtime/Core/Extension/IEnumerableExtensions.cs +109 -0
  79. package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -0
  80. package/Runtime/Core/Extension/IListExtensions.cs +49 -0
  81. package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -0
  82. package/Runtime/Core/Extension/LoggingExtensions.cs +196 -0
  83. package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -0
  84. package/Runtime/Core/Extension/RandomExtensions.cs +110 -0
  85. package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -0
  86. package/Runtime/Core/Extension/StringExtensions.cs +76 -0
  87. package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -0
  88. package/Runtime/Core/Extension/UnityExtensions.cs +1409 -0
  89. package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -0
  90. package/Runtime/Core/Extension.meta +8 -0
  91. package/Runtime/Core/Helper/AssignUtilities.cs +14 -0
  92. package/Runtime/Core/Helper/AssignUtilities.cs.meta +11 -0
  93. package/Runtime/Core/Helper/Enumerables.cs +17 -0
  94. package/Runtime/Core/Helper/Enumerables.cs.meta +11 -0
  95. package/Runtime/Core/Helper/Geometry.cs +26 -0
  96. package/Runtime/Core/Helper/Geometry.cs.meta +11 -0
  97. package/Runtime/Core/Helper/Helpers.cs +1092 -0
  98. package/Runtime/Core/Helper/Helpers.cs.meta +11 -0
  99. package/Runtime/Core/Helper/IterationHelpers.cs +32 -0
  100. package/Runtime/Core/Helper/IterationHelpers.cs.meta +11 -0
  101. package/Runtime/Core/Helper/LifetimeHelpers.cs +12 -0
  102. package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -0
  103. package/Runtime/Core/Helper/Objects.cs +447 -0
  104. package/Runtime/Core/Helper/Objects.cs.meta +11 -0
  105. package/Runtime/Core/Helper/SpriteHelpers.cs +53 -0
  106. package/Runtime/Core/Helper/SpriteHelpers.cs.meta +11 -0
  107. package/Runtime/Core/Helper/StringInList.cs +31 -0
  108. package/Runtime/Core/Helper/StringInList.cs.meta +11 -0
  109. package/Runtime/Core/Helper/WallMath.cs +75 -0
  110. package/Runtime/Core/Helper/WallMath.cs.meta +11 -0
  111. package/Runtime/Core/Helper.meta +8 -0
  112. package/Runtime/Core/Math/Line.cs +51 -0
  113. package/Runtime/Core/Math/Line.cs.meta +11 -0
  114. package/Runtime/Core/Math/Parabola.cs +44 -0
  115. package/Runtime/Core/Math/Parabola.cs.meta +11 -0
  116. package/Runtime/Core/Math/PointPolygonCheck.cs +25 -0
  117. package/Runtime/Core/Math/PointPolygonCheck.cs.meta +11 -0
  118. package/Runtime/Core/Math/Range.cs +56 -0
  119. package/Runtime/Core/Math/Range.cs.meta +11 -0
  120. package/Runtime/Core/Math/XXHash.cs +308 -0
  121. package/Runtime/Core/Math/XXHash.cs.meta +11 -0
  122. package/Runtime/Core/Math.meta +8 -0
  123. package/Runtime/Core/Model/Direction.cs +26 -0
  124. package/Runtime/Core/Model/Direction.cs.meta +11 -0
  125. package/Runtime/Core/Model.meta +8 -0
  126. package/Runtime/Core/OneOf/FastOneOf.cs +145 -0
  127. package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -0
  128. package/Runtime/Core/OneOf/None.cs +6 -0
  129. package/Runtime/Core/OneOf/None.cs.meta +11 -0
  130. package/Runtime/Core/OneOf.meta +8 -0
  131. package/Runtime/Core/Random/AbstractRandom.cs +537 -0
  132. package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -0
  133. package/Runtime/Core/Random/IRandom.cs +141 -0
  134. package/Runtime/Core/Random/IRandom.cs.meta +11 -0
  135. package/Runtime/Core/Random/NativePcgRandom.cs +97 -0
  136. package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -0
  137. package/Runtime/Core/Random/PcgRandom.cs +142 -0
  138. package/Runtime/Core/Random/PcgRandom.cs.meta +11 -0
  139. package/Runtime/Core/Random/RandomState.cs +92 -0
  140. package/Runtime/Core/Random/RandomState.cs.meta +11 -0
  141. package/Runtime/Core/Random/RandomUtilities.cs +26 -0
  142. package/Runtime/Core/Random/RandomUtilities.cs.meta +11 -0
  143. package/Runtime/Core/Random/SquirrelRandom.cs +82 -0
  144. package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -0
  145. package/Runtime/Core/Random/SystemRandom.cs +110 -0
  146. package/Runtime/Core/Random/SystemRandom.cs.meta +11 -0
  147. package/Runtime/Core/Random/ThreadLocalRandom.cs +11 -0
  148. package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -0
  149. package/Runtime/Core/Random/UnityRandom.cs +24 -0
  150. package/Runtime/Core/Random/UnityRandom.cs.meta +11 -0
  151. package/Runtime/Core/Random/XorShiftRandom.cs +45 -0
  152. package/Runtime/Core/Random/XorShiftRandom.cs.meta +11 -0
  153. package/Runtime/Core/Random.meta +8 -0
  154. package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +32 -0
  155. package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -0
  156. package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +32 -0
  157. package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -0
  158. package/Runtime/Core/Serialization/JsonConverters.meta +8 -0
  159. package/Runtime/Core/Serialization/Serializer.cs +125 -0
  160. package/Runtime/Core/Serialization/Serializer.cs.meta +11 -0
  161. package/Runtime/Core/Serialization.meta +8 -0
  162. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +102 -0
  163. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -0
  164. package/Runtime/Core/Threading.meta +8 -0
  165. package/Runtime/Core.meta +8 -0
  166. package/Runtime/Protobuf-Net/System.Buffers.dll +0 -0
  167. package/Runtime/Protobuf-Net/System.Buffers.dll.meta +33 -0
  168. package/Runtime/Protobuf-Net/System.Collections.Immutable.dll +0 -0
  169. package/Runtime/Protobuf-Net/System.Collections.Immutable.dll.meta +33 -0
  170. package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll +0 -0
  171. package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll.meta +33 -0
  172. package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll +0 -0
  173. package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll.meta +33 -0
  174. package/Runtime/Protobuf-Net/protobuf-net.Core.dll +0 -0
  175. package/Runtime/Protobuf-Net/protobuf-net.Core.dll.meta +33 -0
  176. package/Runtime/Protobuf-Net/protobuf-net.dll +0 -0
  177. package/Runtime/Protobuf-Net/protobuf-net.dll.meta +33 -0
  178. package/Runtime/Protobuf-Net.meta +8 -0
  179. package/Runtime/Utils/AnimationEventEqualityComparer.cs +149 -0
  180. package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -0
  181. package/Runtime/Utils/AnimatorEnumStateMachine.cs +80 -0
  182. package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -0
  183. package/Runtime/Utils/Buffers.cs +32 -0
  184. package/Runtime/Utils/Buffers.cs.meta +11 -0
  185. package/Runtime/Utils/CircleLineRenderer.cs +122 -0
  186. package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -0
  187. package/Runtime/Utils/Oscillator.cs +25 -0
  188. package/Runtime/Utils/Oscillator.cs.meta +11 -0
  189. package/Runtime/Utils/SetTextureImportData.cs +67 -0
  190. package/Runtime/Utils/SetTextureImportData.cs.meta +11 -0
  191. package/Runtime/Utils.meta +8 -0
  192. package/Runtime/WallstopStudios.UnityHelpers.asmdef +14 -0
  193. package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -0
  194. package/Runtime.meta +8 -0
  195. package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef +17 -0
  196. package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef.meta +7 -0
  197. package/Tests/Editor.meta +8 -0
  198. package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +14 -0
  199. package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs.meta +11 -0
  200. package/Tests/Runtime/DataStructures/QuadTreeTests.cs +14 -0
  201. package/Tests/Runtime/DataStructures/QuadTreeTests.cs.meta +11 -0
  202. package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +106 -0
  203. package/Tests/Runtime/DataStructures/SpatialTreeTests.cs.meta +11 -0
  204. package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +14 -0
  205. package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs.meta +11 -0
  206. package/Tests/Runtime/DataStructures.meta +8 -0
  207. package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +14 -0
  208. package/Tests/Runtime/Performance/KDTreePerformanceTests.cs.meta +11 -0
  209. package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +14 -0
  210. package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs.meta +11 -0
  211. package/Tests/Runtime/Performance/RandomPerformanceTests.cs +76 -0
  212. package/Tests/Runtime/Performance/RandomPerformanceTests.cs.meta +11 -0
  213. package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +141 -0
  214. package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs.meta +11 -0
  215. package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +14 -0
  216. package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs.meta +11 -0
  217. package/Tests/Runtime/Performance.meta +8 -0
  218. package/Tests/Runtime/Random/PcgRandomTests.cs +9 -0
  219. package/Tests/Runtime/Random/PcgRandomTests.cs.meta +11 -0
  220. package/Tests/Runtime/Random/RandomTestBase.cs +117 -0
  221. package/Tests/Runtime/Random/RandomTestBase.cs.meta +11 -0
  222. package/Tests/Runtime/Random/SquirrelRandomTests.cs +9 -0
  223. package/Tests/Runtime/Random/SquirrelRandomTests.cs.meta +11 -0
  224. package/Tests/Runtime/Random/SystemRandomTests.cs +10 -0
  225. package/Tests/Runtime/Random/SystemRandomTests.cs.meta +11 -0
  226. package/Tests/Runtime/Random/UnityRandomTests.cs +9 -0
  227. package/Tests/Runtime/Random/UnityRandomTests.cs.meta +11 -0
  228. package/Tests/Runtime/Random/XorShiftRandomTests.cs +9 -0
  229. package/Tests/Runtime/Random/XorShiftRandomTests.cs.meta +11 -0
  230. package/Tests/Runtime/Random.meta +8 -0
  231. package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef +22 -0
  232. package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef.meta +7 -0
  233. package/Tests/Runtime.meta +8 -0
  234. package/Tests.meta +8 -0
  235. package/Third Party Notices.md +1 -0
  236. package/Third Party Notices.md.meta +7 -0
  237. package/package.json +35 -0
  238. package/package.json.meta +7 -0
@@ -0,0 +1,75 @@
1
+ namespace UnityHelpers.Core.Helper
2
+ {
3
+ using System;
4
+ using UnityEngine;
5
+
6
+ public static class WallMath
7
+ {
8
+ /**
9
+ http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/util/concurrent/ThreadLocalRandom.java#356
10
+ <summary>
11
+ BoundedDouble borrowed from Java's ThreadLocalRandom
12
+ </summary>
13
+ */
14
+
15
+ public static double BoundedDouble(double max, double value)
16
+ {
17
+ return value < max ? value : BitConverter.Int64BitsToDouble(BitConverter.DoubleToInt64Bits(value) - 1);
18
+ }
19
+
20
+ public static float BoundedFloat(float max, float value)
21
+ {
22
+ return value < max
23
+ ? value
24
+ : BitConverter.ToSingle(
25
+ BitConverter.GetBytes(BitConverter.ToInt32(BitConverter.GetBytes(value), 0) - 1), 0);
26
+ }
27
+
28
+ public static int WrappedAdd(int value, int increment, int max)
29
+ {
30
+ WrappedAdd(ref value, increment, max);
31
+ return value;
32
+ }
33
+
34
+ public static void WrappedAdd(ref int value, int increment, int max)
35
+ {
36
+ value = value + increment;
37
+ if (value < max)
38
+ {
39
+ return;
40
+ }
41
+ value %= max;
42
+ }
43
+
44
+ public static int WrappedIncrement(int value, int max)
45
+ {
46
+ return WrappedAdd(value, 1, max);
47
+ }
48
+
49
+ public static void WrappedIncrement(ref int value, int max)
50
+ {
51
+ WrappedAdd(ref value, 1, max);
52
+ }
53
+
54
+ public static void Clamp(this Rect bounds, ref Vector2 point)
55
+ {
56
+ if (!bounds.Contains(point))
57
+ {
58
+ Vector2 xClamp = bounds.width < 0 ?
59
+ new Vector2(bounds.x + bounds.width, bounds.x) :
60
+ new Vector2(bounds.x, bounds.x + bounds.width);
61
+ Vector2 yClamp = bounds.height < 0 ?
62
+ new Vector2(bounds.y + bounds.height, bounds.y) :
63
+ new Vector2(bounds.y, bounds.y + bounds.height);
64
+
65
+ point.x = Mathf.Clamp(point.x, xClamp.x, xClamp.y);
66
+ point.y = Mathf.Clamp(point.y, yClamp.x, yClamp.y);
67
+ }
68
+ }
69
+
70
+ public static bool Approximately(float lhs, float rhs, float tolerance = 0.045f)
71
+ {
72
+ return Math.Abs(lhs - rhs) <= tolerance;
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: e3e4af682073d054489c5cb1fe1c5b5a
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 63459188a950ba74db1e2d843839f821
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,51 @@
1
+ namespace UnityHelpers.Core.Math
2
+ {
3
+ using Extension;
4
+ using UnityEngine;
5
+
6
+ // https://pastebin.com/iQDhQTFN
7
+ public readonly struct Line
8
+ {
9
+ public readonly Vector2 from;
10
+ public readonly Vector2 to;
11
+
12
+ private readonly float _a;
13
+ private readonly float _b;
14
+ private readonly float _c;
15
+
16
+ public Line(Vector2 from, Vector2 to)
17
+ {
18
+ this.from = from;
19
+ this.to = to;
20
+ _a = to.y - from.y;
21
+ _b = from.x - to.x;
22
+ _c = _a * from.x + _b * from.y;
23
+ }
24
+
25
+ public bool Intersects(Line other)
26
+ {
27
+ return UnityExtensions.Intersects(from, to, other.from, other.to);
28
+ }
29
+
30
+ public bool TryGetIntersectionPoint(Line other, out Vector2 intersection)
31
+ {
32
+ if (!Intersects(other))
33
+ {
34
+ intersection = default;
35
+ return false;
36
+ }
37
+
38
+ float determinant = _a * other._b - other._a * _b;
39
+ if (Mathf.Approximately(determinant, 0))
40
+ {
41
+ intersection = default;
42
+ return false;
43
+ }
44
+
45
+ float x = (other._b * _c - _b * other._c) / determinant;
46
+ float y = (_a * other._c - other._a * _c) / determinant;
47
+ intersection = new Vector2(x, y);
48
+ return true;
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 806e572a2d471104f8b68b9ecc4bd919
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,44 @@
1
+ namespace UnityHelpers.Core.Math
2
+ {
3
+ using System;
4
+ using System.Runtime.Serialization;
5
+
6
+ [DataContract]
7
+ [Serializable]
8
+ public sealed class Parabola
9
+ {
10
+ public readonly float Length;
11
+
12
+ public readonly float A;
13
+ public readonly float B;
14
+
15
+ /// <summary>
16
+ /// Creates a Parabola that reaches a max height and has a specified length.
17
+ /// </summary>
18
+ /// <param name="max">Max height of parabola.</param>
19
+ /// <param name="length">Length of parabola (between x intercepts).</param>
20
+ public Parabola(float max, float length)
21
+ {
22
+ if (length <= 0)
23
+ {
24
+ throw new ArgumentException($"Expected a length greater than 0, but found: {length:0.00}.");
25
+ }
26
+ Length = length;
27
+
28
+ A = -4 * max / (length * length);
29
+ B = -A * length;
30
+ }
31
+
32
+ public bool ValueAt(float x, out float y)
33
+ {
34
+ if (x < 0 || Length < x)
35
+ {
36
+ y = float.NaN;
37
+ return false;
38
+ }
39
+
40
+ y = A * (x * x) + B * x;
41
+ return true;
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 378ba2f7355b4b148986cd42bc9813df
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,25 @@
1
+ namespace UnityHelpers.Core.Math
2
+ {
3
+ using UnityEngine;
4
+
5
+ public static class PointPolygonCheck
6
+ {
7
+ public static bool IsPointInsidePolygon(Vector2 point, Vector2[] polygon)
8
+ {
9
+ bool result = false;
10
+ int j = polygon.Length - 1;
11
+ for (int i = 0; i < polygon.Length; i++)
12
+ {
13
+ if (polygon[i].y < point.y && polygon[j].y >= point.y || polygon[j].y < point.y && polygon[i].y >= point.y)
14
+ {
15
+ if (polygon[i].x + (point.y - polygon[i].y) / (polygon[j].y - polygon[i].y) * (polygon[j].x - polygon[i].x) < point.x)
16
+ {
17
+ result = !result;
18
+ }
19
+ }
20
+ j = i;
21
+ }
22
+ return result;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 86a5649a88ff43b5b7fa38319ac8c796
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,56 @@
1
+ namespace UnityHelpers.Core.Math
2
+ {
3
+ using Extension;
4
+ using Helper;
5
+ using System;
6
+ using System.Runtime.Serialization;
7
+
8
+ /// <summary>
9
+ /// Inclusive Range [min,max]
10
+ /// </summary>
11
+ [Serializable]
12
+ [DataContract]
13
+ public struct Range<T> : IEquatable<Range<T>> where T: IEquatable<T>, IComparable<T>
14
+ {
15
+ [DataMember]
16
+ public T min;
17
+ [DataMember]
18
+ public T max;
19
+
20
+ public Range(T min, T max)
21
+ {
22
+ this.min = min;
23
+ this.max = max;
24
+ }
25
+
26
+ public bool Equals(Range<T> other)
27
+ {
28
+ return Equals(min, other.min) && Equals(max, other.max);
29
+ }
30
+
31
+ public override bool Equals(object obj)
32
+ {
33
+ return obj is Range<T> other && Equals(other);
34
+ }
35
+
36
+ public override int GetHashCode()
37
+ {
38
+ return Objects.HashCode(min, max);
39
+ }
40
+
41
+ public override string ToString()
42
+ {
43
+ return this.ToJson();
44
+ }
45
+
46
+ public bool WithinRange(T value)
47
+ {
48
+ if (value.CompareTo(min) < 0)
49
+ {
50
+ return false;
51
+ }
52
+
53
+ return value.CompareTo(max) <= 0;
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: d0976d7d8aebfeb4db8f058c5e803057
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,308 @@
1
+ namespace UnityHelpers.Core.Math
2
+ {
3
+ using System.Runtime.CompilerServices;
4
+ using System.Text;
5
+
6
+ internal static class XXHash
7
+ {
8
+ private const ulong k_Prime64v1 = 11400714785074694791ul;
9
+ private const ulong k_Prime64v2 = 14029467366897019727ul;
10
+ private const ulong k_Prime64v3 = 1609587929392839161ul;
11
+ private const ulong k_Prime64v4 = 9650029242287828579ul;
12
+ private const ulong k_Prime64v5 = 2870177450012600261ul;
13
+
14
+ private const uint k_Prime32v1 = 2654435761u;
15
+ private const uint k_Prime32v2 = 2246822519u;
16
+ private const uint k_Prime32v3 = 3266489917u;
17
+ private const uint k_Prime32v4 = 668265263u;
18
+ private const uint k_Prime32v5 = 374761393u;
19
+
20
+ public static uint Hash32(string text) => Hash32(text, Encoding.UTF8);
21
+ public static uint Hash32(string text, Encoding encoding) => Hash32(encoding.GetBytes(text));
22
+ public static uint Hash32(byte[] buffer)
23
+ {
24
+ unsafe
25
+ {
26
+ fixed (byte* ptr = buffer)
27
+ {
28
+ return Hash32(ptr, buffer.Length);
29
+ }
30
+ }
31
+ }
32
+
33
+ /// <summary>
34
+ /// Generate a 32-bit xxHash value.
35
+ /// </summary>
36
+ /// <param name="buffer">Input buffer.</param>
37
+ /// <param name="bufferLength">Input buffer length.</param>
38
+ /// <param name="seed">Optional seed.</param>
39
+ /// <returns>32-bit hash value.</returns>
40
+ public static unsafe uint Hash32(byte* buffer, int bufferLength, uint seed = 0)
41
+ {
42
+ const int stripeLength = 16;
43
+
44
+ int len = bufferLength;
45
+ int remainingLen = len;
46
+ uint acc;
47
+
48
+ byte* pInput = buffer;
49
+ if (len >= stripeLength)
50
+ {
51
+ uint acc1 = seed + k_Prime32v1 + k_Prime32v2;
52
+ uint acc2 = seed + k_Prime32v2;
53
+ uint acc3 = seed;
54
+ uint acc4 = seed - k_Prime32v1;
55
+
56
+ do
57
+ {
58
+ acc = processStripe32(ref pInput, ref acc1, ref acc2, ref acc3, ref acc4);
59
+ remainingLen -= stripeLength;
60
+ } while (remainingLen >= stripeLength);
61
+ }
62
+ else
63
+ {
64
+ acc = seed + k_Prime32v5;
65
+ }
66
+
67
+ acc += (uint)len;
68
+ acc = processRemaining32(pInput, acc, remainingLen);
69
+
70
+ return avalanche32(acc);
71
+ }
72
+
73
+ public static ulong Hash64(string text) => Hash64(text, Encoding.UTF8);
74
+ public static ulong Hash64(string text, Encoding encoding) => Hash64(encoding.GetBytes(text));
75
+ public static ulong Hash64(byte[] buffer)
76
+ {
77
+ unsafe
78
+ {
79
+ fixed (byte* ptr = buffer)
80
+ {
81
+ return Hash64(ptr, buffer.Length);
82
+ }
83
+ }
84
+ }
85
+
86
+ /// <summary>
87
+ /// Generate a 64-bit xxHash value.
88
+ /// </summary>
89
+ /// <param name="buffer">Input buffer.</param>
90
+ /// <param name="bufferLength">Input buffer length.</param>
91
+ /// <param name="seed">Optional seed.</param>
92
+ /// <returns>Computed 64-bit hash value.</returns>
93
+ public static unsafe ulong Hash64(byte* buffer, int bufferLength, ulong seed = 0)
94
+ {
95
+ const int stripeLength = 32;
96
+
97
+ int len = bufferLength;
98
+ int remainingLen = len;
99
+ ulong acc;
100
+
101
+ byte* pInput = buffer;
102
+ if (len >= stripeLength)
103
+ {
104
+ ulong acc1 = seed + k_Prime64v1 + k_Prime64v2;
105
+ ulong acc2 = seed + k_Prime64v2;
106
+ ulong acc3 = seed;
107
+ ulong acc4 = seed - k_Prime64v1;
108
+
109
+ do
110
+ {
111
+ acc = processStripe64(ref pInput, ref acc1, ref acc2, ref acc3, ref acc4);
112
+ remainingLen -= stripeLength;
113
+ } while (remainingLen >= stripeLength);
114
+ }
115
+ else
116
+ {
117
+ acc = seed + k_Prime64v5;
118
+ }
119
+
120
+ acc += (ulong)len;
121
+ acc = processRemaining64(pInput, acc, remainingLen);
122
+
123
+
124
+ return avalanche64(acc);
125
+ }
126
+
127
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
128
+ private static unsafe ulong processStripe64(
129
+ ref byte* pInput,
130
+ ref ulong acc1,
131
+ ref ulong acc2,
132
+ ref ulong acc3,
133
+ ref ulong acc4)
134
+ {
135
+ processLane64(ref acc1, ref pInput);
136
+ processLane64(ref acc2, ref pInput);
137
+ processLane64(ref acc3, ref pInput);
138
+ processLane64(ref acc4, ref pInput);
139
+
140
+ ulong acc = Bits.RotateLeft(acc1, 1)
141
+ + Bits.RotateLeft(acc2, 7)
142
+ + Bits.RotateLeft(acc3, 12)
143
+ + Bits.RotateLeft(acc4, 18);
144
+
145
+ mergeAccumulator64(ref acc, acc1);
146
+ mergeAccumulator64(ref acc, acc2);
147
+ mergeAccumulator64(ref acc, acc3);
148
+ mergeAccumulator64(ref acc, acc4);
149
+ return acc;
150
+ }
151
+
152
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
153
+ private static unsafe void processLane64(ref ulong accn, ref byte* pInput)
154
+ {
155
+ ulong lane = *(ulong*)pInput;
156
+ accn = round64(accn, lane);
157
+ pInput += 8;
158
+ }
159
+
160
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
161
+ private static unsafe ulong processRemaining64(
162
+ byte* pInput,
163
+ ulong acc,
164
+ int remainingLen)
165
+ {
166
+ for (ulong lane; remainingLen >= 8; remainingLen -= 8, pInput += 8)
167
+ {
168
+ lane = *(ulong*)pInput;
169
+
170
+ acc ^= round64(0, lane);
171
+ acc = Bits.RotateLeft(acc, 27) * k_Prime64v1;
172
+ acc += k_Prime64v4;
173
+ }
174
+
175
+ for (uint lane32; remainingLen >= 4; remainingLen -= 4, pInput += 4)
176
+ {
177
+ lane32 = *(uint*)pInput;
178
+
179
+ acc ^= lane32 * k_Prime64v1;
180
+ acc = Bits.RotateLeft(acc, 23) * k_Prime64v2;
181
+ acc += k_Prime64v3;
182
+ }
183
+
184
+ for (byte lane8; remainingLen >= 1; remainingLen--, pInput++)
185
+ {
186
+ lane8 = *pInput;
187
+ acc ^= lane8 * k_Prime64v5;
188
+ acc = Bits.RotateLeft(acc, 11) * k_Prime64v1;
189
+ }
190
+
191
+ return acc;
192
+ }
193
+
194
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
195
+ private static ulong avalanche64(ulong acc)
196
+ {
197
+ acc ^= acc >> 33;
198
+ acc *= k_Prime64v2;
199
+ acc ^= acc >> 29;
200
+ acc *= k_Prime64v3;
201
+ acc ^= acc >> 32;
202
+ return acc;
203
+ }
204
+
205
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
206
+ private static ulong round64(ulong accn, ulong lane)
207
+ {
208
+ accn += lane * k_Prime64v2;
209
+ return Bits.RotateLeft(accn, 31) * k_Prime64v1;
210
+ }
211
+
212
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
213
+ private static void mergeAccumulator64(ref ulong acc, ulong accn)
214
+ {
215
+ acc ^= round64(0, accn);
216
+ acc *= k_Prime64v1;
217
+ acc += k_Prime64v4;
218
+ }
219
+
220
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
221
+ private static unsafe uint processStripe32(
222
+ ref byte* pInput,
223
+ ref uint acc1,
224
+ ref uint acc2,
225
+ ref uint acc3,
226
+ ref uint acc4)
227
+ {
228
+ processLane32(ref pInput, ref acc1);
229
+ processLane32(ref pInput, ref acc2);
230
+ processLane32(ref pInput, ref acc3);
231
+ processLane32(ref pInput, ref acc4);
232
+
233
+ return Bits.RotateLeft(acc1, 1)
234
+ + Bits.RotateLeft(acc2, 7)
235
+ + Bits.RotateLeft(acc3, 12)
236
+ + Bits.RotateLeft(acc4, 18);
237
+ }
238
+
239
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
240
+ private static unsafe void processLane32(ref byte* pInput, ref uint accn)
241
+ {
242
+ uint lane = *(uint*)pInput;
243
+ accn = round32(accn, lane);
244
+ pInput += 4;
245
+ }
246
+
247
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
248
+ private static unsafe uint processRemaining32(
249
+ byte* pInput,
250
+ uint acc,
251
+ int remainingLen)
252
+ {
253
+ for (uint lane; remainingLen >= 4; remainingLen -= 4, pInput += 4)
254
+ {
255
+ lane = *(uint*)pInput;
256
+ acc += lane * k_Prime32v3;
257
+ acc = Bits.RotateLeft(acc, 17) * k_Prime32v4;
258
+ }
259
+
260
+ for (byte lane; remainingLen >= 1; remainingLen--, pInput++)
261
+ {
262
+ lane = *pInput;
263
+ acc += lane * k_Prime32v5;
264
+ acc = Bits.RotateLeft(acc, 11) * k_Prime32v1;
265
+ }
266
+
267
+ return acc;
268
+ }
269
+
270
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
271
+ private static uint round32(uint accn, uint lane)
272
+ {
273
+ accn += lane * k_Prime32v2;
274
+ accn = Bits.RotateLeft(accn, 13);
275
+ accn *= k_Prime32v1;
276
+ return accn;
277
+ }
278
+
279
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
280
+ private static uint avalanche32(uint acc)
281
+ {
282
+ acc ^= acc >> 15;
283
+ acc *= k_Prime32v2;
284
+ acc ^= acc >> 13;
285
+ acc *= k_Prime32v3;
286
+ acc ^= acc >> 16;
287
+ return acc;
288
+ }
289
+
290
+ /// <summary>
291
+ /// Bit operations.
292
+ /// </summary>
293
+ private static class Bits
294
+ {
295
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
296
+ internal static ulong RotateLeft(ulong value, int bits)
297
+ {
298
+ return (value << bits) | (value >> (64 - bits));
299
+ }
300
+
301
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
302
+ internal static uint RotateLeft(uint value, int bits)
303
+ {
304
+ return (value << bits) | (value >> (32 - bits));
305
+ }
306
+ }
307
+ }
308
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 738dc5ff60564d13991fb4400501ad73
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: adcccded420bef24ab8fd609fb00feb0
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,26 @@
1
+ namespace UnityHelpers.Core.Model
2
+ {
3
+ using System;
4
+ using System.Runtime.Serialization;
5
+
6
+ [Flags]
7
+ [Serializable]
8
+ public enum Direction : short
9
+ {
10
+ [EnumMember] None = 0,
11
+ [EnumMember] North = 1,
12
+ [EnumMember] NorthEast = 2,
13
+ [EnumMember] East = 4,
14
+ [EnumMember] SouthEast = 8,
15
+ [EnumMember] South = 16,
16
+ [EnumMember] SouthWest = 32,
17
+ [EnumMember] West = 64,
18
+ [EnumMember] NorthWest = 128
19
+ }
20
+
21
+ public static class DirectionConstants
22
+ {
23
+ public const int NumDirections = 4;
24
+ public const int AllDirections = 8;
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 09b76f49035ddaf40948ba4cc4ebf959
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: