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,210 @@
1
+ namespace UnityHelpers.Core.Extension
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using Helper;
7
+ using Model;
8
+ using UnityEngine;
9
+
10
+ public static class DirectionExtensions
11
+ {
12
+ private static readonly List<Direction> Directions = Enum.GetValues(typeof(Direction)).OfType<Direction>().Except(Enumerables.Of(Direction.None)).ToList();
13
+
14
+ public static Direction Opposite(this Direction direction)
15
+ {
16
+ switch (direction)
17
+ {
18
+ case Direction.North:
19
+ return Direction.South;
20
+ case Direction.NorthEast:
21
+ return Direction.SouthWest;
22
+ case Direction.East:
23
+ return Direction.West;
24
+ case Direction.SouthEast:
25
+ return Direction.NorthWest;
26
+ case Direction.South:
27
+ return Direction.North;
28
+ case Direction.SouthWest:
29
+ return Direction.NorthEast;
30
+ case Direction.West:
31
+ return Direction.East;
32
+ case Direction.NorthWest:
33
+ return Direction.SouthEast;
34
+ case Direction.None:
35
+ return Direction.None;
36
+ default:
37
+ throw new ArgumentException($"Unknown direction {direction}.");
38
+ }
39
+ }
40
+
41
+ public static Vector2Int AsVector2Int(this Direction direction)
42
+ {
43
+ switch (direction)
44
+ {
45
+ case Direction.None:
46
+ return Vector2Int.zero;
47
+ case Direction.North:
48
+ return Vector2Int.up;
49
+ case Direction.NorthEast:
50
+ return new Vector2Int(1, 1);
51
+ case Direction.East:
52
+ return Vector2Int.right;
53
+ case Direction.SouthEast:
54
+ return new Vector2Int(1, -1);
55
+ case Direction.South:
56
+ return Vector2Int.down;
57
+ case Direction.SouthWest:
58
+ return new Vector2Int(-1, -1);
59
+ case Direction.West:
60
+ return Vector2Int.left;
61
+ case Direction.NorthWest:
62
+ return new Vector2Int(-1, 1);
63
+ default:
64
+ throw new ArgumentException($"Unknown direction {direction}.");
65
+ }
66
+ }
67
+
68
+ public static Vector2 AsVector2(this Direction direction)
69
+ {
70
+ return direction.AsVector2Int();
71
+ }
72
+
73
+ public static Direction AsDirection(this Vector3 vector3)
74
+ {
75
+ return AsDirection((Vector2)vector3);
76
+ }
77
+
78
+ public static IEnumerable<Direction> Split(this Direction direction)
79
+ {
80
+ bool foundAny = false;
81
+ foreach (Direction singleDirection in Directions)
82
+ {
83
+ if (direction.HasFlag(singleDirection))
84
+ {
85
+ foundAny = true;
86
+ yield return singleDirection;
87
+ }
88
+ }
89
+
90
+ if (!foundAny)
91
+ {
92
+ yield return Direction.None;
93
+ }
94
+ }
95
+
96
+ public static Direction Combine(this IEnumerable<Direction> directions)
97
+ {
98
+ Direction combined = Direction.None;
99
+ foreach (Direction direction in directions)
100
+ {
101
+ combined |= direction;
102
+ }
103
+
104
+ return combined;
105
+ }
106
+
107
+ public static Direction AsDirection(this Vector2 vector, bool preferAngles = false)
108
+ {
109
+ if (vector.x == 0 && vector.y == 0)
110
+ {
111
+ return Direction.None;
112
+ }
113
+
114
+ float angle;
115
+ if (vector.x < 0)
116
+ {
117
+ angle = 360 - Mathf.Atan2(vector.x, vector.y) * Mathf.Rad2Deg * -1;
118
+ }
119
+ else
120
+ {
121
+ angle = Mathf.Atan2(vector.x, vector.y) * Mathf.Rad2Deg;
122
+ }
123
+
124
+ if (preferAngles)
125
+ {
126
+ if (345 <= angle || angle < 15)
127
+ {
128
+ return Direction.North;
129
+ }
130
+
131
+ if (15 <= angle && angle < 75)
132
+ {
133
+ return Direction.NorthEast;
134
+ }
135
+
136
+ if (75 <= angle && angle < 105)
137
+ {
138
+ return Direction.East;
139
+ }
140
+
141
+ if (105 <= angle && angle < 165)
142
+ {
143
+ return Direction.SouthEast;
144
+ }
145
+
146
+ if (165 <= angle && angle < 195)
147
+ {
148
+ return Direction.South;
149
+ }
150
+
151
+ if (195 <= angle && angle < 255)
152
+ {
153
+ return Direction.SouthWest;
154
+ }
155
+
156
+ if (255 <= angle && angle < 285)
157
+ {
158
+ return Direction.West;
159
+ }
160
+
161
+ if (285 <= angle && angle < 345)
162
+ {
163
+ return Direction.NorthWest;
164
+ }
165
+ }
166
+
167
+ if (337.5 <= angle || angle < 22.5)
168
+ {
169
+ return Direction.North;
170
+ }
171
+
172
+ if (22.5 <= angle && angle < 67.5)
173
+ {
174
+ return Direction.NorthEast;
175
+ }
176
+
177
+ if (67.5 <= angle && angle < 112.5)
178
+ {
179
+ return Direction.East;
180
+ }
181
+
182
+ if (112.5 <= angle && angle < 157.5)
183
+ {
184
+ return Direction.SouthEast;
185
+ }
186
+
187
+ if (157.5 <= angle && angle < 202.5)
188
+ {
189
+ return Direction.South;
190
+ }
191
+
192
+ if (202.5 <= angle && angle < 247.5)
193
+ {
194
+ return Direction.SouthWest;
195
+ }
196
+
197
+ if (247.5 <= angle && angle < 292.5)
198
+ {
199
+ return Direction.West;
200
+ }
201
+
202
+ if (292.5 <= angle && angle < 337.5)
203
+ {
204
+ return Direction.NorthWest;
205
+ }
206
+
207
+ return Direction.None;
208
+ }
209
+ }
210
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 88db97f1499b1fd42a345e6a4f61f670
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,12 @@
1
+ namespace UnityHelpers.Core.Extension
2
+ {
3
+ using System.Collections.Generic;
4
+
5
+ public static class HashSetExtensions
6
+ {
7
+ public static void AddRange<T>(this HashSet<T> set, IEnumerable<T> elements)
8
+ {
9
+ set.UnionWith(elements);
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 939a365a8996b7e4aa2b9618b22f0bf6
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,109 @@
1
+ namespace UnityHelpers.Core.Extension
2
+ {
3
+ using Random;
4
+ using System;
5
+ using System.Collections.Concurrent;
6
+ using System.Collections.Generic;
7
+ using System.Linq;
8
+
9
+ public static class IEnumerableExtensions
10
+ {
11
+ private static readonly ConcurrentDictionary<object, object> ComparerCache = new();
12
+
13
+ public static IList<T> AsList<T>(this IEnumerable<T> enumeration)
14
+ {
15
+ if (enumeration is IList<T> list)
16
+ {
17
+ return list;
18
+ }
19
+
20
+ return enumeration.ToList();
21
+ }
22
+
23
+ public static IEnumerable<T> OrderBy<T>(this IEnumerable<T> enumeration, Func<T, T, int> comparer)
24
+ {
25
+ FuncBasedComparer<T> comparerObject = (FuncBasedComparer<T>) ComparerCache.GetOrAdd(comparer, () => new FuncBasedComparer<T>(comparer));
26
+ return enumeration.OrderBy(_ => _, comparerObject);
27
+ }
28
+
29
+ public static IEnumerable<T> Ordered<T>(this IEnumerable<T> enumerable) where T : IComparable
30
+ {
31
+ return enumerable.OrderBy(_ => _);
32
+ }
33
+
34
+ public static IEnumerable<T> Shuffled<T>(this IEnumerable<T> enumerable, IRandom random = null)
35
+ {
36
+ random = random ?? ThreadLocalRandom<PcgRandom>.Instance;
37
+ return enumerable.OrderBy(_ => random.Next());
38
+ }
39
+
40
+ public static IEnumerable<T> Infinite<T>(this IEnumerable<T> enumerable)
41
+ {
42
+ ICollection<T> collection = enumerable as ICollection<T> ?? enumerable.ToList();
43
+ if (collection.Count == 0)
44
+ {
45
+ yield break;
46
+ }
47
+
48
+ while (true)
49
+ {
50
+ foreach (T element in collection)
51
+ {
52
+ yield return element;
53
+ }
54
+ }
55
+ }
56
+
57
+ public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)
58
+ {
59
+ foreach (T item in enumerable)
60
+ {
61
+ action(item);
62
+ }
63
+ }
64
+
65
+ public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> items, int size)
66
+ {
67
+ using var enumerator = items.GetEnumerator();
68
+ bool hasNext = enumerator.MoveNext();
69
+
70
+ IEnumerable<T> NextPartitionOf()
71
+ {
72
+ int remainingCountForPartition = size;
73
+ while (remainingCountForPartition-- > 0 && hasNext)
74
+ {
75
+ yield return enumerator.Current;
76
+ hasNext = enumerator.MoveNext();
77
+ }
78
+ }
79
+
80
+ while (hasNext)
81
+ {
82
+ yield return NextPartitionOf().ToList();
83
+ }
84
+ }
85
+
86
+ public static List<T> ToList<T>(this IEnumerable<T> enumerable, int count)
87
+ {
88
+ List<T> list = new(count);
89
+ list.AddRange(enumerable);
90
+ return list;
91
+ }
92
+
93
+
94
+ private class FuncBasedComparer<T> : IComparer<T>
95
+ {
96
+ private readonly Func<T, T, int> _comparer;
97
+
98
+ public FuncBasedComparer(Func<T, T, int> comparer)
99
+ {
100
+ _comparer = comparer ?? throw new ArgumentNullException(nameof(comparer));
101
+ }
102
+
103
+ public int Compare(T lhs, T rhs)
104
+ {
105
+ return _comparer(lhs, rhs);
106
+ }
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 3470cf3d28c05ad4a8c63bcaa168b4a0
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,49 @@
1
+ namespace UnityHelpers.Core.Extension
2
+ {
3
+ using Random;
4
+ using System.Collections.Generic;
5
+
6
+ public static class IListExtensions
7
+ {
8
+ public static void Shuffle<T>(this IList<T> list, IRandom random = null)
9
+ {
10
+ if (list is not { Count: > 1 })
11
+ {
12
+ return;
13
+ }
14
+
15
+ random ??= PcgRandom.Instance;
16
+
17
+ int length = list.Count;
18
+ for (int i = 0; i < length - 1; ++i)
19
+ {
20
+ int nextIndex = random.Next(i, length);
21
+ if (nextIndex == i)
22
+ {
23
+ continue;
24
+ }
25
+ (list[i], list[nextIndex]) = (list[nextIndex], list[i]);
26
+ }
27
+ }
28
+
29
+ public static void RemoveAtSwapBack<T>(this IList<T> list, int index)
30
+ {
31
+ if (list.Count <= 1)
32
+ {
33
+ list.Clear();
34
+ return;
35
+ }
36
+
37
+ int lastIndex = list.Count - 1;
38
+ if (index == lastIndex)
39
+ {
40
+ list.RemoveAt(index);
41
+ return;
42
+ }
43
+
44
+ T last = list[lastIndex];
45
+ list[index] = last;
46
+ list.RemoveAt(lastIndex);
47
+ }
48
+ }
49
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: cc0fd5f65729462428811e55928b5bd2
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,196 @@
1
+ #if !ENABLE_UBERLOGGING && (DEVELOPMENT_BUILD || DEBUG || UNITY_EDITOR)
2
+ #define ENABLE_UBERLOGGING
3
+ #endif
4
+
5
+ namespace UnityHelpers.Core.Extension
6
+ {
7
+ using System;
8
+ using System.Diagnostics;
9
+ using System.Threading;
10
+ using Helper;
11
+ using JetBrains.Annotations;
12
+ using UnityEngine;
13
+ using Debug = UnityEngine.Debug;
14
+
15
+ public static class LoggingExtensions
16
+ {
17
+ private static readonly Thread UnityMainThread;
18
+
19
+ private static bool LoggingEnabled = true;
20
+
21
+ static LoggingExtensions()
22
+ {
23
+ #if ENABLE_UBERLOGGING
24
+ /*
25
+ Unity throws exceptions if you try to log on something that isn't the main thread.
26
+ Sometimes, it's nice to log in async Tasks. Assume that the first initialization of
27
+ this class will be done by the Unity main thread, and then check every time we log.
28
+ If the logging thread is not the unity main thread, then do nothing
29
+ (instead of throwing...)
30
+ */
31
+ UnityMainThread = Thread.CurrentThread;
32
+ #endif
33
+ }
34
+
35
+ public static void EnableLogging(this UnityEngine.Object component)
36
+ {
37
+ LoggingEnabled = true;
38
+ }
39
+
40
+ public static void DisableLogging(this UnityEngine.Object component)
41
+ {
42
+ LoggingEnabled = false;
43
+ }
44
+
45
+
46
+ [StringFormatMethod("message")]
47
+ public static void Log(this UnityEngine.Object component, string message, params object[] args)
48
+ {
49
+ #if ENABLE_UBERLOGGING
50
+ if (!LoggingEnabled)
51
+ {
52
+ return;
53
+ }
54
+ LogDebug(component, message, args);
55
+ #endif
56
+ }
57
+
58
+
59
+ [StringFormatMethod("message")]
60
+ public static void LogMethod(this UnityEngine.Object component)
61
+ {
62
+ #if ENABLE_UBERLOGGING
63
+ StackTrace stackTrace = new StackTrace();
64
+ string methodName = stackTrace.GetFrame(1).GetMethod().Name;
65
+ LogDebug(component, methodName);
66
+ #endif
67
+ }
68
+
69
+
70
+ [StringFormatMethod("message")]
71
+ public static void LogDebug(this UnityEngine.Object component, string message, params object[] args)
72
+ {
73
+ #if ENABLE_UBERLOGGING
74
+ if (!LoggingEnabled)
75
+ {
76
+ return;
77
+ }
78
+ LogDebug(component, message, null, args);
79
+ #endif
80
+ }
81
+
82
+
83
+ [StringFormatMethod("message")]
84
+ public static void LogWarn(this UnityEngine.Object component, string message, params object[] args)
85
+ {
86
+ #if ENABLE_UBERLOGGING
87
+ if (!LoggingEnabled)
88
+ {
89
+ return;
90
+ }
91
+ LogWarn(component, message, null, args);
92
+ #endif
93
+ }
94
+
95
+
96
+ [StringFormatMethod("message")]
97
+ public static void LogError(this UnityEngine.Object component, string message, params object[] args)
98
+ {
99
+ #if ENABLE_UBERLOGGING
100
+ if (!LoggingEnabled)
101
+ {
102
+ return;
103
+ }
104
+ LogError(component, message, null, args);
105
+ #endif
106
+ }
107
+
108
+
109
+ [StringFormatMethod("message")]
110
+ public static void Log(this UnityEngine.Object component, string message, Exception e, params object[] args)
111
+ {
112
+ #if ENABLE_UBERLOGGING
113
+ if (!LoggingEnabled)
114
+ {
115
+ return;
116
+ }
117
+ LogDebug(component, message, e, args);
118
+ #endif
119
+ }
120
+
121
+
122
+ [StringFormatMethod("message")]
123
+ public static void LogDebug(this UnityEngine.Object component, string message, Exception e, params object[] args)
124
+ {
125
+ #if ENABLE_UBERLOGGING
126
+ if (!LoggingEnabled)
127
+ {
128
+ return;
129
+ }
130
+ if (Equals(Thread.CurrentThread, UnityMainThread))
131
+ {
132
+ Debug.Log(Wrap(component, string.Format(message, args), e));
133
+ }
134
+ #endif
135
+ }
136
+
137
+
138
+ [StringFormatMethod("message")]
139
+ public static void LogWarn(this UnityEngine.Object component, string message, Exception e, params object[] args)
140
+ {
141
+ #if ENABLE_UBERLOGGING
142
+ if (!LoggingEnabled)
143
+ {
144
+ return;
145
+ }
146
+ if (Equals(Thread.CurrentThread, UnityMainThread))
147
+ {
148
+ Debug.LogWarning(Wrap(component, string.Format(message, args), e));
149
+ }
150
+ #endif
151
+ }
152
+
153
+
154
+ [StringFormatMethod("message")]
155
+ public static void LogError(this UnityEngine.Object component, string message, Exception e, params object[] args)
156
+ {
157
+ #if ENABLE_UBERLOGGING
158
+ if (!LoggingEnabled)
159
+ {
160
+ return;
161
+ }
162
+ if (Equals(Thread.CurrentThread, UnityMainThread))
163
+ {
164
+ Debug.LogError(Wrap(component, string.Format(message, args), e));
165
+ }
166
+ #endif
167
+ }
168
+
169
+ private static string Wrap(UnityEngine.Object component, string message, Exception e)
170
+ {
171
+ #if ENABLE_UBERLOGGING
172
+ float now = Time.time;
173
+ string componentType = component == null ? "NO_TYPE" : component.GetType().Name;
174
+ string gameObjectName = "NO_NAME";
175
+ if (component != null)
176
+ {
177
+ GameObject owner = component.GetGameObject();
178
+ if (owner != null)
179
+ {
180
+ gameObjectName = owner.name;
181
+ }
182
+ }
183
+
184
+ string prepend = string.Format("{0}|{2}[{1}]|", now, componentType, gameObjectName);
185
+ if (e != null)
186
+ {
187
+ return prepend + message + "\n " + e;
188
+ }
189
+
190
+ return prepend + message;
191
+ #else
192
+ return string.Empty;
193
+ #endif
194
+ }
195
+ }
196
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 9f2ac4106848eb345bcd57352a716d54
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: