com.wallstop-studios.unity-helpers 2.0.0-rc04 → 2.0.0-rc06

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 (121) hide show
  1. package/CHANGELOG.md.meta +7 -7
  2. package/Editor/AnimationEventEditor.cs.meta +11 -11
  3. package/Editor.meta +8 -8
  4. package/LICENSE.md.meta +7 -7
  5. package/README.md.meta +7 -7
  6. package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -11
  7. package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -11
  8. package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -11
  9. package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -11
  10. package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -11
  11. package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -11
  12. package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -11
  13. package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -11
  14. package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -11
  15. package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -11
  16. package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -11
  17. package/Runtime/Core/DataStructure/Adapters.meta +8 -8
  18. package/Runtime/Core/DataStructure/Circle.cs.meta +11 -11
  19. package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -11
  20. package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -11
  21. package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -11
  22. package/Runtime/Core/DataStructure/TimedCache.cs +4 -3
  23. package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -11
  24. package/Runtime/Core/DataStructure.meta +8 -8
  25. package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -11
  26. package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -11
  27. package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -11
  28. package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -11
  29. package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -11
  30. package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -11
  31. package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -11
  32. package/Runtime/Core/Extension/IListExtensions.cs +2 -2
  33. package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -11
  34. package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -11
  35. package/Runtime/Core/Extension/RandomExtensions.cs +23 -4
  36. package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -11
  37. package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -11
  38. package/Runtime/Core/Extension/UnityExtensions.cs +278 -90
  39. package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -11
  40. package/Runtime/Core/Extension.meta +8 -8
  41. package/Runtime/Core/Helper/ArrayConverter.cs +39 -0
  42. package/Runtime/Core/Helper/ArrayConverter.cs.meta +3 -0
  43. package/Runtime/Core/Helper/Enumerables.cs.meta +11 -11
  44. package/Runtime/Core/Helper/Geometry.cs.meta +11 -11
  45. package/Runtime/Core/Helper/Helpers.cs +209 -84
  46. package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -11
  47. package/Runtime/Core/Helper/Objects.cs.meta +11 -11
  48. package/Runtime/Core/Helper/WallMath.cs +85 -22
  49. package/Runtime/Core/Helper/WallMath.cs.meta +11 -11
  50. package/Runtime/Core/Helper.meta +8 -8
  51. package/Runtime/Core/Math/Line.cs.meta +11 -11
  52. package/Runtime/Core/Math/Parabola.cs.meta +11 -11
  53. package/Runtime/Core/Math/Range.cs.meta +11 -11
  54. package/Runtime/Core/Math.meta +8 -8
  55. package/Runtime/Core/Model/Direction.cs.meta +11 -11
  56. package/Runtime/Core/Model.meta +8 -8
  57. package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -11
  58. package/Runtime/Core/OneOf/None.cs.meta +11 -11
  59. package/Runtime/Core/OneOf.meta +8 -8
  60. package/Runtime/Core/Random/AbstractRandom.cs +34 -20
  61. package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -11
  62. package/Runtime/Core/Random/DotNetRandom.cs +52 -0
  63. package/Runtime/Core/Random/DotNetRandom.cs.meta +3 -0
  64. package/Runtime/Core/Random/IRandom.cs.meta +11 -11
  65. package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -11
  66. package/Runtime/Core/Random/PRNG.cs +7 -0
  67. package/Runtime/Core/Random/PRNG.cs.meta +3 -0
  68. package/Runtime/Core/Random/PcgRandom.cs +23 -22
  69. package/Runtime/Core/Random/PcgRandom.cs.meta +11 -11
  70. package/Runtime/Core/Random/RandomState.cs +44 -5
  71. package/Runtime/Core/Random/RandomState.cs.meta +11 -11
  72. package/Runtime/Core/Random/SquirrelRandom.cs +13 -10
  73. package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -11
  74. package/Runtime/Core/Random/SystemRandom.cs +31 -16
  75. package/Runtime/Core/Random/SystemRandom.cs.meta +11 -11
  76. package/Runtime/Core/Random/ThreadLocalRandom.cs +2 -1
  77. package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -11
  78. package/Runtime/Core/Random/UnityRandom.cs +37 -4
  79. package/Runtime/Core/Random/WyRandom.cs +121 -0
  80. package/Runtime/Core/Random/WyRandom.cs.meta +3 -0
  81. package/Runtime/Core/Random/XorShiftRandom.cs +9 -7
  82. package/Runtime/Core/Random.meta +8 -8
  83. package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -11
  84. package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -11
  85. package/Runtime/Core/Serialization/JsonConverters.meta +8 -8
  86. package/Runtime/Core/Serialization/Serializer.cs +36 -14
  87. package/Runtime/Core/Serialization/Serializer.cs.meta +11 -11
  88. package/Runtime/Core/Serialization.meta +8 -8
  89. package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -11
  90. package/Runtime/Core/Threading.meta +8 -8
  91. package/Runtime/Core.meta +8 -8
  92. package/Runtime/Protobuf-Net.meta +8 -8
  93. package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -11
  94. package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -11
  95. package/Runtime/Utils/Buffers.cs.meta +11 -11
  96. package/Runtime/Utils/CircleLineRenderer.cs +17 -5
  97. package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -11
  98. package/Runtime/Utils/Oscillator.cs.meta +11 -11
  99. package/Runtime/Utils/SetTextureImportData.cs.meta +11 -11
  100. package/Runtime/Utils.meta +8 -8
  101. package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -7
  102. package/Runtime.meta +8 -8
  103. package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +34 -10
  104. package/Tests/Runtime/Helper/ArrayConverterTests.cs +19 -0
  105. package/Tests/Runtime/Helper/ArrayConverterTests.cs.meta +3 -0
  106. package/Tests/Runtime/Helper/WallMathTests.cs +221 -0
  107. package/Tests/Runtime/Helper/WallMathTests.cs.meta +3 -0
  108. package/Tests/Runtime/Helper.meta +3 -0
  109. package/Tests/Runtime/Performance/RandomPerformanceTests.cs +18 -13
  110. package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +47 -34
  111. package/Tests/Runtime/Random/DotNetRandomTests.cs +9 -0
  112. package/Tests/Runtime/Random/DotNetRandomTests.cs.meta +3 -0
  113. package/Tests/Runtime/Random/RandomTestBase.cs +89 -15
  114. package/Tests/Runtime/Random/WyRandomTests.cs +9 -0
  115. package/Tests/Runtime/Random/WyRandomTests.cs.meta +3 -0
  116. package/Tests/Runtime/Serialization/JsonSerializationTest.cs +24 -11
  117. package/Tests/Runtime/Utils/SpriteRendererMetadataTests.cs +21 -17
  118. package/Tests.meta +8 -8
  119. package/Third Party Notices.md.meta +7 -7
  120. package/package.json +1 -1
  121. package/package.json.meta +7 -7
@@ -1,21 +1,21 @@
1
1
  namespace UnityHelpers.Core.Helper
2
2
  {
3
- using Extension;
4
3
  using System;
5
4
  using System.Collections;
6
5
  using System.Collections.Generic;
7
6
  using System.Linq;
8
7
  using System.Reflection;
9
8
  using DataStructure.Adapters;
9
+ using Extension;
10
10
  using Random;
11
- #if UNITY_EDITOR
12
- using UnityEditor;
13
- using UnityEditor.SceneManagement;
14
- #endif
15
11
  using UnityEngine;
16
12
  using UnityEngine.SceneManagement;
17
13
  using Utils;
18
14
  using Object = UnityEngine.Object;
15
+ #if UNITY_EDITOR
16
+ using UnityEditor;
17
+ using UnityEditor.SceneManagement;
18
+ #endif
19
19
 
20
20
  public static class Helpers
21
21
  {
@@ -24,7 +24,8 @@
24
24
  private static readonly Object LogObject = new();
25
25
  private static readonly Dictionary<string, Object> ObjectsByTag = new();
26
26
 
27
- public static T Find<T>(this Object component, string tag, bool log = true) where T : Object
27
+ public static T Find<T>(this Object component, string tag, bool log = true)
28
+ where T : Object
28
29
  {
29
30
  if (ObjectsByTag.TryGetValue(tag, out Object value))
30
31
  {
@@ -56,14 +57,19 @@
56
57
  if (log)
57
58
  {
58
59
  component.LogWarn(
59
- "Failed to find {0} on {1} (name: {2}), id [{3}].", typeof(T).Name, tag, gameObject.name,
60
- gameObject.GetInstanceID());
60
+ "Failed to find {0} on {1} (name: {2}), id [{3}].",
61
+ typeof(T).Name,
62
+ tag,
63
+ gameObject.name,
64
+ gameObject.GetInstanceID()
65
+ );
61
66
  }
62
67
 
63
68
  return default;
64
69
  }
65
70
 
66
- public static T Find<T>(string tag, bool log = true) where T : MonoBehaviour
71
+ public static T Find<T>(string tag, bool log = true)
72
+ where T : MonoBehaviour
67
73
  {
68
74
  if (ObjectsByTag.TryGetValue(tag, out Object value))
69
75
  {
@@ -100,12 +106,14 @@
100
106
  return default;
101
107
  }
102
108
 
103
- public static void SetInstance<T>(string tag, T instance) where T : MonoBehaviour
109
+ public static void SetInstance<T>(string tag, T instance)
110
+ where T : MonoBehaviour
104
111
  {
105
112
  ObjectsByTag[tag] = instance;
106
113
  }
107
114
 
108
- public static void ClearInstance<T>(string tag, T instance) where T : MonoBehaviour
115
+ public static void ClearInstance<T>(string tag, T instance)
116
+ where T : MonoBehaviour
109
117
  {
110
118
  if (ObjectsByTag.TryGetValue(tag, out Object existing) && existing == instance)
111
119
  {
@@ -113,22 +121,25 @@
113
121
  }
114
122
  }
115
123
 
116
- public static bool HasComponent<T>(this Object unityObject) where T : Object
124
+ public static bool HasComponent<T>(this Object unityObject)
125
+ where T : Object
117
126
  {
118
127
  return unityObject switch
119
128
  {
120
129
  GameObject go => go.HasComponent<T>(),
121
130
  Component component => component.HasComponent<T>(),
122
- _ => false
131
+ _ => false,
123
132
  };
124
133
  }
125
134
 
126
- public static bool HasComponent<T>(this Component component) where T : Object
135
+ public static bool HasComponent<T>(this Component component)
136
+ where T : Object
127
137
  {
128
138
  return component.TryGetComponent<T>(out _);
129
139
  }
130
140
 
131
- public static bool HasComponent<T>(this GameObject gameObject) where T : Object
141
+ public static bool HasComponent<T>(this GameObject gameObject)
142
+ where T : Object
132
143
  {
133
144
  return gameObject.TryGetComponent<T>(out _);
134
145
  }
@@ -143,7 +154,9 @@
143
154
  component.LogWarn("{0} not found.", name);
144
155
  }
145
156
 
146
- public static IEnumerable<GameObject> IterateOverChildGameObjects(this GameObject gameObject)
157
+ public static IEnumerable<GameObject> IterateOverChildGameObjects(
158
+ this GameObject gameObject
159
+ )
147
160
  {
148
161
  for (int i = 0; i < gameObject.transform.childCount; i++)
149
162
  {
@@ -151,7 +164,9 @@
151
164
  }
152
165
  }
153
166
 
154
- public static IEnumerable<GameObject> IterateOverChildGameObjectsRecursively(this GameObject gameObject)
167
+ public static IEnumerable<GameObject> IterateOverChildGameObjectsRecursively(
168
+ this GameObject gameObject
169
+ )
155
170
  {
156
171
  for (int i = 0; i < gameObject.transform.childCount; i++)
157
172
  {
@@ -165,21 +180,26 @@
165
180
  }
166
181
 
167
182
  public static IEnumerable<GameObject> IterateOverChildGameObjectsRecursivelyIncludingSelf(
168
- this GameObject gameObject)
183
+ this GameObject gameObject
184
+ )
169
185
  {
170
186
  yield return gameObject;
171
187
 
172
188
  for (int i = 0; i < gameObject.transform.childCount; ++i)
173
189
  {
174
190
  GameObject child = gameObject.transform.GetChild(i).gameObject;
175
- foreach (GameObject c in child.IterateOverChildGameObjectsRecursivelyIncludingSelf())
191
+ foreach (
192
+ GameObject c in child.IterateOverChildGameObjectsRecursivelyIncludingSelf()
193
+ )
176
194
  {
177
195
  yield return c;
178
196
  }
179
197
  }
180
198
  }
181
199
 
182
- public static IEnumerable<GameObject> IterateOverParentGameObjects(this GameObject gameObject)
200
+ public static IEnumerable<GameObject> IterateOverParentGameObjects(
201
+ this GameObject gameObject
202
+ )
183
203
  {
184
204
  Transform currentTransform = gameObject.transform.parent;
185
205
  while (currentTransform != null)
@@ -190,7 +210,8 @@
190
210
  }
191
211
 
192
212
  public static IEnumerable<GameObject> IterateOverParentGameObjectsRecursivelyIncludingSelf(
193
- this GameObject gameObject)
213
+ this GameObject gameObject
214
+ )
194
215
  {
195
216
  yield return gameObject;
196
217
 
@@ -200,7 +221,11 @@
200
221
  }
201
222
  }
202
223
 
203
- public static void EnableRecursively<T>(this Component component, bool enabled, Func<T, bool> exclude = null)
224
+ public static void EnableRecursively<T>(
225
+ this Component component,
226
+ bool enabled,
227
+ Func<T, bool> exclude = null
228
+ )
204
229
  where T : Behaviour
205
230
  {
206
231
  if (component == null)
@@ -230,8 +255,11 @@
230
255
  }
231
256
 
232
257
  public static void EnableRendererRecursively<T>(
233
- this Component component, bool enabled,
234
- Func<T, bool> exclude = null) where T : Renderer
258
+ this Component component,
259
+ bool enabled,
260
+ Func<T, bool> exclude = null
261
+ )
262
+ where T : Renderer
235
263
  {
236
264
  if (component == null)
237
265
  {
@@ -257,7 +285,9 @@
257
285
  }
258
286
  }
259
287
 
260
- public static IEnumerable<T> IterateOverAllChildComponentsRecursively<T>(this Component component)
288
+ public static IEnumerable<T> IterateOverAllChildComponentsRecursively<T>(
289
+ this Component component
290
+ )
261
291
  {
262
292
  if (component == null)
263
293
  {
@@ -308,7 +338,9 @@
308
338
  }
309
339
  }
310
340
 
311
- public static IEnumerable<Transform> IterateOverAllParentsIncludingSelf(this Component component)
341
+ public static IEnumerable<Transform> IterateOverAllParentsIncludingSelf(
342
+ this Component component
343
+ )
312
344
  {
313
345
  if (component == null)
314
346
  {
@@ -323,7 +355,9 @@
323
355
  }
324
356
  }
325
357
 
326
- public static IEnumerable<Transform> IterateOverAllChildrenRecursively(this Component component)
358
+ public static IEnumerable<Transform> IterateOverAllChildrenRecursively(
359
+ this Component component
360
+ )
327
361
  {
328
362
  if (component == null)
329
363
  {
@@ -334,7 +368,9 @@
334
368
  {
335
369
  Transform childTransform = component.transform.GetChild(i);
336
370
  yield return childTransform;
337
- foreach (Transform childChildTransform in childTransform.IterateOverAllChildrenRecursively())
371
+ foreach (
372
+ Transform childChildTransform in childTransform.IterateOverAllChildrenRecursively()
373
+ )
338
374
  {
339
375
  yield return childChildTransform;
340
376
  }
@@ -366,7 +402,8 @@
366
402
  }
367
403
  }
368
404
 
369
- public static void DestroyAllComponentsOfType<T>(this GameObject gameObject) where T : Component
405
+ public static void DestroyAllComponentsOfType<T>(this GameObject gameObject)
406
+ where T : Component
370
407
  {
371
408
  foreach (T component in gameObject.GetComponents<T>())
372
409
  {
@@ -395,10 +432,12 @@
395
432
 
396
433
  public static void DestroyAllChildrenGameObjectsImmediatelyConditionally(
397
434
  this GameObject gameObject,
398
- Func<GameObject, bool> acceptancePredicate)
435
+ Func<GameObject, bool> acceptancePredicate
436
+ )
399
437
  {
400
438
  InternalDestroyAllChildrenGameObjects(
401
- gameObject, toDestroy =>
439
+ gameObject,
440
+ toDestroy =>
402
441
  {
403
442
  if (!acceptancePredicate(toDestroy))
404
443
  {
@@ -406,15 +445,18 @@
406
445
  }
407
446
 
408
447
  Object.DestroyImmediate(toDestroy);
409
- });
448
+ }
449
+ );
410
450
  }
411
451
 
412
452
  public static void DestroyAllChildGameObjectsConditionally(
413
453
  this GameObject gameObject,
414
- Func<GameObject, bool> acceptancePredicate)
454
+ Func<GameObject, bool> acceptancePredicate
455
+ )
415
456
  {
416
457
  InternalDestroyAllChildrenGameObjects(
417
- gameObject, toDestroy =>
458
+ gameObject,
459
+ toDestroy =>
418
460
  {
419
461
  if (!acceptancePredicate(toDestroy))
420
462
  {
@@ -422,7 +464,8 @@
422
464
  }
423
465
 
424
466
  toDestroy.Destroy();
425
- });
467
+ }
468
+ );
426
469
  }
427
470
 
428
471
  public static void DestroyAllChildrenGameObjectsImmediately(this GameObject gameObject) =>
@@ -436,7 +479,8 @@
436
479
 
437
480
  private static void InternalDestroyAllChildrenGameObjects(
438
481
  this GameObject gameObject,
439
- Action<GameObject> destroyFunction)
482
+ Action<GameObject> destroyFunction
483
+ )
440
484
  {
441
485
  for (int i = gameObject.transform.childCount - 1; 0 <= i; --i)
442
486
  {
@@ -479,7 +523,8 @@
479
523
  return RadianToVector2(degree * Mathf.Deg2Rad);
480
524
  }
481
525
 
482
- public static T GetOrAddComponent<T>(this GameObject unityObject) where T : Component
526
+ public static T GetOrAddComponent<T>(this GameObject unityObject)
527
+ where T : Component
483
528
  {
484
529
  if (!unityObject.TryGetComponent(out T instance))
485
530
  {
@@ -536,8 +581,12 @@
536
581
 
537
582
  // https://gamedevelopment.tutsplus.com/tutorials/unity-solution-for-hitting-moving-targets--cms-29633
538
583
  public static Vector2 PredictCurrentTarget(
539
- this GameObject currentTarget, Vector2 launchLocation, float projectileSpeed, bool predictiveFiring,
540
- Vector2 targetVelocity)
584
+ this GameObject currentTarget,
585
+ Vector2 launchLocation,
586
+ float projectileSpeed,
587
+ bool predictiveFiring,
588
+ Vector2 targetVelocity
589
+ )
541
590
  {
542
591
  Vector2 target = currentTarget.transform.position;
543
592
 
@@ -551,17 +600,21 @@
551
600
  return target;
552
601
  }
553
602
 
554
- float a = (targetVelocity.x * targetVelocity.x) + (targetVelocity.y * targetVelocity.y) -
555
- (projectileSpeed * projectileSpeed);
603
+ float a =
604
+ (targetVelocity.x * targetVelocity.x)
605
+ + (targetVelocity.y * targetVelocity.y)
606
+ - (projectileSpeed * projectileSpeed);
556
607
 
557
- float b = 2 * (targetVelocity.x * (target.x - launchLocation.x) +
558
- targetVelocity.y * (target.y - launchLocation.y));
608
+ float b =
609
+ 2
610
+ * (
611
+ targetVelocity.x * (target.x - launchLocation.x)
612
+ + targetVelocity.y * (target.y - launchLocation.y)
613
+ );
559
614
 
560
615
  float c =
561
- ((target.x - launchLocation.x) *
562
- (target.x - launchLocation.x)) +
563
- ((target.y - launchLocation.y) *
564
- (target.y - launchLocation.y));
616
+ ((target.x - launchLocation.x) * (target.x - launchLocation.x))
617
+ + ((target.y - launchLocation.y) * (target.y - launchLocation.y));
565
618
 
566
619
  float disc = b * b - (4 * a * c);
567
620
  if (disc < 0)
@@ -615,7 +668,7 @@
615
668
  {
616
669
  GameObject go => go,
617
670
  Component c => c.gameObject,
618
- _ => null
671
+ _ => null,
619
672
  };
620
673
  }
621
674
 
@@ -632,12 +685,18 @@
632
685
 
633
686
  public static GameObject FindChildGameObjectWithTag(this GameObject gameObject, string tag)
634
687
  {
635
- return gameObject.IterateOverChildGameObjectsRecursivelyIncludingSelf()
688
+ return gameObject
689
+ .IterateOverChildGameObjectsRecursivelyIncludingSelf()
636
690
  .FirstOrDefault(child => child.CompareTag(tag));
637
691
  }
638
692
 
639
693
  public static bool HasLineOfSight(
640
- Vector2 initialLocation, Vector2 direction, Transform transform, float totalDistance, float delta)
694
+ Vector2 initialLocation,
695
+ Vector2 direction,
696
+ Transform transform,
697
+ float totalDistance,
698
+ float delta
699
+ )
641
700
  {
642
701
  int hits = Physics2D.RaycastNonAlloc(initialLocation, direction, Buffers.RaycastHits);
643
702
  for (int i = 0; i < hits; ++i)
@@ -659,13 +718,24 @@
659
718
  }
660
719
 
661
720
  public static Coroutine StartFunctionAsCoroutine(
662
- this MonoBehaviour monoBehaviour, Action action, float updateRate, bool useJitter = false,
663
- bool waitBefore = false)
721
+ this MonoBehaviour monoBehaviour,
722
+ Action action,
723
+ float updateRate,
724
+ bool useJitter = false,
725
+ bool waitBefore = false
726
+ )
664
727
  {
665
- return monoBehaviour.StartCoroutine(FunctionAsCoroutine(action, updateRate, useJitter, waitBefore));
728
+ return monoBehaviour.StartCoroutine(
729
+ FunctionAsCoroutine(action, updateRate, useJitter, waitBefore)
730
+ );
666
731
  }
667
732
 
668
- private static IEnumerator FunctionAsCoroutine(Action action, float updateRate, bool useJitter, bool waitBefore)
733
+ private static IEnumerator FunctionAsCoroutine(
734
+ Action action,
735
+ float updateRate,
736
+ bool useJitter,
737
+ bool waitBefore
738
+ )
669
739
  {
670
740
  bool usedJitter = false;
671
741
  while (true)
@@ -675,7 +745,7 @@
675
745
  {
676
746
  if (useJitter && !usedJitter)
677
747
  {
678
- float delay = PcgRandom.Instance.NextFloat(updateRate);
748
+ float delay = PRNG.Instance.NextFloat(updateRate);
679
749
  startTime = Time.time;
680
750
  while (!HasEnoughTimePassed(startTime, delay))
681
751
  {
@@ -698,7 +768,7 @@
698
768
  {
699
769
  if (useJitter && !usedJitter)
700
770
  {
701
- float delay = PcgRandom.Instance.NextFloat(updateRate);
771
+ float delay = PRNG.Instance.NextFloat(updateRate);
702
772
  startTime = Time.time;
703
773
  while (!HasEnoughTimePassed(startTime, delay))
704
774
  {
@@ -717,22 +787,37 @@
717
787
  }
718
788
  }
719
789
 
720
- public static Coroutine ExecuteFunctionAfterDelay(this MonoBehaviour monoBehaviour, Action action, float delay)
790
+ public static Coroutine ExecuteFunctionAfterDelay(
791
+ this MonoBehaviour monoBehaviour,
792
+ Action action,
793
+ float delay
794
+ )
721
795
  {
722
796
  return monoBehaviour.StartCoroutine(FunctionDelayAsCoroutine(action, delay));
723
797
  }
724
798
 
725
- public static Coroutine ExecuteFunctionNextFrame(this MonoBehaviour monoBehaviour, Action action)
799
+ public static Coroutine ExecuteFunctionNextFrame(
800
+ this MonoBehaviour monoBehaviour,
801
+ Action action
802
+ )
726
803
  {
727
804
  return monoBehaviour.ExecuteFunctionAfterDelay(action, 0f);
728
805
  }
729
806
 
730
- public static Coroutine ExecuteFunctionAfterFrame(this MonoBehaviour monoBehaviour, Action action)
807
+ public static Coroutine ExecuteFunctionAfterFrame(
808
+ this MonoBehaviour monoBehaviour,
809
+ Action action
810
+ )
731
811
  {
732
812
  return monoBehaviour.StartCoroutine(FunctionAfterFrame(action));
733
813
  }
734
814
 
735
- public static IEnumerator ExecuteOverTime(Action action, int totalCount, float duration, bool delay = true)
815
+ public static IEnumerator ExecuteOverTime(
816
+ Action action,
817
+ int totalCount,
818
+ float duration,
819
+ bool delay = true
820
+ )
736
821
  {
737
822
  if (action == null)
738
823
  {
@@ -750,7 +835,10 @@
750
835
  {
751
836
  float percent = (Time.time - startTime) / duration;
752
837
  // optional delay execution from happening on 0, 1, 2, ... n-1 to 1, 2, ... n
753
- if (totalExecuted < totalCount && ((totalExecuted + (delay ? 1f : 0f)) / totalCount) <= percent)
838
+ if (
839
+ totalExecuted < totalCount
840
+ && ((totalExecuted + (delay ? 1f : 0f)) / totalCount) <= percent
841
+ )
754
842
  {
755
843
  action();
756
844
  ++totalExecuted;
@@ -759,7 +847,7 @@
759
847
  yield return null;
760
848
  }
761
849
 
762
- for (; totalExecuted < totalCount;)
850
+ for (; totalExecuted < totalCount; )
763
851
  {
764
852
  action();
765
853
  ++totalExecuted;
@@ -828,7 +916,11 @@
828
916
 
829
917
  public static Vector3Int AsVector3Int(this Vector3 vector)
830
918
  {
831
- return new Vector3Int((int)Math.Round(vector.x), (int)Math.Round(vector.y), (int)Math.Round(vector.z));
919
+ return new Vector3Int(
920
+ (int)Math.Round(vector.x),
921
+ (int)Math.Round(vector.y),
922
+ (int)Math.Round(vector.z)
923
+ );
832
924
  }
833
925
 
834
926
  public static Vector3 AsVector3(this (uint x, uint y, uint z) vector)
@@ -856,7 +948,8 @@
856
948
  return new Vector3Int(vector.x, vector.y);
857
949
  }
858
950
 
859
- public static T CopyTo<T>(this T original, GameObject destination) where T : Component
951
+ public static T CopyTo<T>(this T original, GameObject destination)
952
+ where T : Component
860
953
  {
861
954
  Type type = original.GetType();
862
955
  T copied = destination.GetComponent(type) as T;
@@ -877,8 +970,10 @@
877
970
  }
878
971
  }
879
972
 
880
- foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
881
- .Where(field => Attribute.IsDefined(field, typeof(SerializeField))))
973
+ foreach (
974
+ FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)
975
+ .Where(field => Attribute.IsDefined(field, typeof(SerializeField)))
976
+ )
882
977
  {
883
978
  try
884
979
  {
@@ -915,30 +1010,46 @@
915
1010
  return new Rect(bounds.x, bounds.y, bounds.size.x, bounds.size.y);
916
1011
  }
917
1012
 
918
- public static Vector3 GetRandomPointInCircle(Vector2 center, float radius, IRandom random = null)
1013
+ public static Vector2 GetRandomPointInCircle(
1014
+ Vector2 center,
1015
+ float radius,
1016
+ IRandom random = null
1017
+ )
919
1018
  {
920
- random ??= PcgRandom.Instance;
921
- float r = radius * Mathf.Sqrt(random.NextFloat());
922
- float theta = random.NextFloat() * 2 * Mathf.PI;
923
- return new Vector3(center.x + r * Mathf.Cos(theta), center.y + r * Mathf.Sin(theta), 0.0f);
1019
+ random ??= PRNG.Instance;
1020
+ double r = radius * Math.Sqrt(random.NextDouble());
1021
+ double theta = random.NextDouble() * 2 * Math.PI;
1022
+ return new Vector2(
1023
+ center.x + (float)(r * Math.Cos(theta)),
1024
+ center.y + (float)(r * Math.Sin(theta))
1025
+ );
924
1026
  }
925
1027
 
926
- public static GameObject GetPlayerObjectInChildHierarchy(this GameObject gameObject)
1028
+ public static GameObject GetPlayerObjectInChildHierarchy(
1029
+ this GameObject gameObject,
1030
+ string playerTag = "Player"
1031
+ )
927
1032
  {
928
- return gameObject.GetTagObjectInChildHierarchy("Player");
1033
+ return gameObject.GetTagObjectInChildHierarchy(playerTag);
929
1034
  }
930
1035
 
931
- public static GameObject GetTagObjectInChildHierarchy(this GameObject gameObject, string tag)
1036
+ public static GameObject GetTagObjectInChildHierarchy(
1037
+ this GameObject gameObject,
1038
+ string tag
1039
+ )
932
1040
  {
933
- return gameObject.IterateOverChildGameObjectsRecursivelyIncludingSelf()
1041
+ return gameObject
1042
+ .IterateOverChildGameObjectsRecursivelyIncludingSelf()
934
1043
  .FirstOrDefault(go => go.CompareTag(tag));
935
1044
  }
936
1045
 
937
1046
  //https://answers.unity.com/questions/722748/refreshing-the-polygon-collider-2d-upon-sprite-cha.html
938
1047
  public static void UpdateShapeToSprite(this Component component)
939
1048
  {
940
- if (!component.TryGetComponent(out SpriteRenderer spriteRenderer) ||
941
- component.TryGetComponent(out PolygonCollider2D collider))
1049
+ if (
1050
+ !component.TryGetComponent(out SpriteRenderer spriteRenderer)
1051
+ || component.TryGetComponent(out PolygonCollider2D collider)
1052
+ )
942
1053
  {
943
1054
  return;
944
1055
  }
@@ -973,7 +1084,9 @@
973
1084
  return new Vector3Int(x, y, z);
974
1085
  }
975
1086
 
976
- public static GameObject TryGetClosestParentWithComponentIncludingSelf<T>(this GameObject current)
1087
+ public static GameObject TryGetClosestParentWithComponentIncludingSelf<T>(
1088
+ this GameObject current
1089
+ )
977
1090
  where T : Component
978
1091
  {
979
1092
  while (current != null)
@@ -991,7 +1104,9 @@
991
1104
  }
992
1105
 
993
1106
  #if UNITY_EDITOR
994
- public static IEnumerable<GameObject> EnumeratePrefabs(IEnumerable<string> assetPaths = null)
1107
+ public static IEnumerable<GameObject> EnumeratePrefabs(
1108
+ IEnumerable<string> assetPaths = null
1109
+ )
995
1110
  {
996
1111
  assetPaths ??= new[] { "Assets/Prefabs", "Assets/Resources" };
997
1112
 
@@ -1011,7 +1126,9 @@
1011
1126
  {
1012
1127
  assetPaths ??= new[] { "Assets/Prefabs", "Assets/Resources", "Assets/TileMaps" };
1013
1128
 
1014
- foreach (string assetGuid in AssetDatabase.FindAssets("t:" + typeof(T).Name, assetPaths))
1129
+ foreach (
1130
+ string assetGuid in AssetDatabase.FindAssets("t:" + typeof(T).Name, assetPaths)
1131
+ )
1015
1132
  {
1016
1133
  string path = AssetDatabase.GUIDToAssetPath(assetGuid);
1017
1134
  T so = AssetDatabase.LoadAssetAtPath<T>(path);
@@ -1093,8 +1210,12 @@
1093
1210
  {
1094
1211
  MethodInfo awakeInfo = AwakeMethodsByType.GetOrAdd(
1095
1212
  script.GetType(),
1096
- type => type.GetMethod(
1097
- "Awake", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
1213
+ type =>
1214
+ type.GetMethod(
1215
+ "Awake",
1216
+ BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
1217
+ )
1218
+ );
1098
1219
  if (awakeInfo != null)
1099
1220
  {
1100
1221
  _ = awakeInfo.Invoke(script, null);
@@ -1102,7 +1223,11 @@
1102
1223
  }
1103
1224
  }
1104
1225
 
1105
- public static Vector2 GetAngleWithSpeed(Vector2 targetDirection, Vector2 currentDirection, float rotationSpeed)
1226
+ public static Vector2 GetAngleWithSpeed(
1227
+ Vector2 targetDirection,
1228
+ Vector2 currentDirection,
1229
+ float rotationSpeed
1230
+ )
1106
1231
  {
1107
1232
  if (targetDirection == Vector2.zero)
1108
1233
  {
@@ -1149,4 +1274,4 @@
1149
1274
  }
1150
1275
  }
1151
1276
  }
1152
- }
1277
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: ea2fd993d32f4de99c8470019c604060
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: ea2fd993d32f4de99c8470019c604060
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: e6d050e096f57ea43a3defcb90b1d538
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: e6d050e096f57ea43a3defcb90b1d538
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: