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,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 0dc67c07c6dd5754eb9244c315c898fa
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,140 @@
1
+ namespace UnityHelpers.Editor
2
+ {
3
+ using System;
4
+ using System.Collections;
5
+ using System.Collections.Generic;
6
+ using System.Linq;
7
+ using System.Reflection;
8
+ using Core.Attributes;
9
+ using UnityEditor;
10
+ using UnityEngine;
11
+ using Core.Extension;
12
+ using Core.Helper;
13
+ using Utils;
14
+ using Object = UnityEngine.Object;
15
+
16
+ public sealed class PrefabCheckWizard : ScriptableWizard
17
+ {
18
+ private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
19
+
20
+ [Tooltip("Drag a folder from Unity here to validate all prefabs under it. Defaults to Assets/Prefabs and Assets/Resources if none specified.")]
21
+ public List<Object> assetPaths;
22
+
23
+ [MenuItem("Tools/Unity Helpers/Prefab Check Wizard")]
24
+ public static void CreatePrefabCheckWizard()
25
+ {
26
+ _ = DisplayWizard<PrefabCheckWizard>("Prefab sanity check", "Run");
27
+ }
28
+
29
+ private void OnWizardCreate()
30
+ {
31
+ List<string> parsedAssetPaths;
32
+ if (assetPaths is { Count: > 0 })
33
+ {
34
+ parsedAssetPaths = assetPaths.Select(AssetDatabase.GetAssetPath).ToList();
35
+ parsedAssetPaths.RemoveAll(string.IsNullOrEmpty);
36
+ if (parsedAssetPaths.Count <= 0)
37
+ {
38
+ parsedAssetPaths = null;
39
+ }
40
+ }
41
+ else
42
+ {
43
+ parsedAssetPaths = null;
44
+ }
45
+
46
+ foreach (GameObject prefab in Helpers.EnumeratePrefabs(parsedAssetPaths))
47
+ {
48
+ List<MonoBehaviour> componentBuffer = Buffers<MonoBehaviour>.List;
49
+ prefab.GetComponentsInChildren(true, componentBuffer);
50
+ foreach (MonoBehaviour script in componentBuffer)
51
+ {
52
+ if (!script)
53
+ {
54
+ Type scriptType = script?.GetType();
55
+ if (scriptType == null)
56
+ {
57
+ prefab.LogError("Detected missing script.");
58
+ }
59
+ else
60
+ {
61
+ prefab.LogError("Detected missing script for script type {0}.", scriptType);
62
+ }
63
+
64
+ continue;
65
+ }
66
+ ValidateNoNullsInLists(script);
67
+ }
68
+ }
69
+ }
70
+
71
+ private static void ValidateNoNullsInLists(Object component)
72
+ {
73
+ foreach (FieldInfo field in FieldsByType.GetOrAdd(
74
+ component.GetType(), type => type
75
+ .GetFields(BindingFlags.Instance | BindingFlags.Public)
76
+ .Concat(
77
+ type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic).Where(
78
+ field => field.GetCustomAttributes(typeof(SerializeField)).Any() ||
79
+ field.GetCustomAttributes(typeof(ValidateAssignmentAttribute)).Any()))
80
+ .Where(field => typeof(IEnumerable).IsAssignableFrom(field.FieldType) || field.FieldType.IsArray)
81
+ .Where(field => !typeof(Transform).IsAssignableFrom(field.FieldType))
82
+ .Where(field => !typeof(Object).IsAssignableFrom(field.FieldType))
83
+ .ToList()))
84
+ {
85
+ bool LogIfNull(object thing, int? position = null)
86
+ {
87
+ if (thing == null || (thing is Object unityThing && !unityThing))
88
+ {
89
+ if (position == null)
90
+ {
91
+ component.LogError("Field {0} has a null element in it.", field.Name);
92
+ }
93
+ else
94
+ {
95
+ component.LogError("Field {0} has a null element at position {1}.", field.Name, position);
96
+ }
97
+
98
+ return true;
99
+ }
100
+
101
+ return false;
102
+ }
103
+
104
+ object fieldValue = field.GetValue(component);
105
+
106
+ if (field.FieldType.IsArray)
107
+ {
108
+ if (fieldValue == null)
109
+ {
110
+ component.LogError("Field {0} (array) was null.", field.Name);
111
+ continue;
112
+ }
113
+
114
+ Array array = (Array)fieldValue;
115
+ foreach (object thing in array)
116
+ {
117
+ bool nullElement = LogIfNull(thing);
118
+ if (nullElement)
119
+ {
120
+ break;
121
+ }
122
+ }
123
+
124
+ continue;
125
+ }
126
+
127
+ if (fieldValue is not IEnumerable list)
128
+ {
129
+ continue;
130
+ }
131
+
132
+ int position = 0;
133
+ foreach (object thing in list)
134
+ {
135
+ _ = LogIfNull(thing, position++);
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 25cf013a07239b04fa262ee9db2860ec
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,16 @@
1
+ {
2
+ "name": "WallstopStudios.UnityHelpers.Editor",
3
+ "rootNamespace": "",
4
+ "references": [
5
+ "WallstopStudios.UnityHelpers"
6
+ ],
7
+ "includePlatforms": [],
8
+ "excludePlatforms": [],
9
+ "allowUnsafeCode": false,
10
+ "overrideReferences": false,
11
+ "precompiledReferences": [],
12
+ "autoReferenced": true,
13
+ "defineConstraints": [],
14
+ "versionDefines": [],
15
+ "noEngineReferences": false
16
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: de86e2706cb173041874cadb20669cb0
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/Editor.meta ADDED
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 09b16dc9463deb7499043e86335b41b8
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Eli Pinkerton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Eli Pinkerton
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 8977dc43976e68c47948b5891b0db297
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/LICENSE.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: a6e47b47847d6be4ba31a4de140b068d
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # A Grab-Bag
2
+ Various Unity Helpers. Includes deterministic randoms including a PCGRandom implementation,
package/README.md.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: d8a337245154754488809b2728b8931a
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,102 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Reflection;
7
+ using UnityEngine;
8
+
9
+ [AttributeUsage(AttributeTargets.Method)]
10
+ public sealed class AnimationEventAttribute : Attribute
11
+ {
12
+ public bool ignoreDerived = true;
13
+ }
14
+
15
+ public static class AnimationEventHelpers
16
+ {
17
+ public static readonly IReadOnlyDictionary<Type, IReadOnlyList<MethodInfo>> TypesToMethods;
18
+
19
+ static AnimationEventHelpers()
20
+ {
21
+ List<(Type, string)> ignoreDerived = new();
22
+ Dictionary<Type, List<MethodInfo>> typesToMethods = AppDomain.CurrentDomain.GetAssemblies()
23
+ .SelectMany(assembly => assembly.GetTypes())
24
+ .Where(type => type.IsClass)
25
+ .Where(type => typeof(MonoBehaviour).IsAssignableFrom(type))
26
+ .ToDictionary(
27
+ type => type,
28
+ type =>
29
+ {
30
+ List<MethodInfo> definedMethods = GetPossibleAnimatorEventsForType(type)
31
+ .Where(method => Attribute.IsDefined(method, typeof(AnimationEventAttribute), true)).ToList();
32
+ foreach (MethodInfo definedMethod in definedMethods)
33
+ {
34
+ // Only consider attributes on our specific method
35
+ if (!Attribute.IsDefined(definedMethod, typeof(AnimationEventAttribute), false))
36
+ {
37
+ continue;
38
+ }
39
+
40
+ if (definedMethod.GetCustomAttributes(typeof(AnimationEventAttribute), false)[0] is
41
+ AnimationEventAttribute { ignoreDerived: true })
42
+ {
43
+ ignoreDerived.Add((type, definedMethod.Name));
44
+ }
45
+ }
46
+
47
+ return definedMethods;
48
+ });
49
+
50
+ foreach (KeyValuePair<Type, List<MethodInfo>> entry in typesToMethods.ToList())
51
+ {
52
+ if (entry.Value.Count <= 0)
53
+ {
54
+ _ = typesToMethods.Remove(entry.Key);
55
+ }
56
+
57
+ Type key = entry.Key;
58
+ foreach ((Type type, string methodName) in ignoreDerived)
59
+ {
60
+ if (key == type)
61
+ {
62
+ continue;
63
+ }
64
+
65
+ if (!key.IsSubclassOf(type))
66
+ {
67
+ continue;
68
+ }
69
+
70
+ entry.Value.RemoveAll(method => method.Name == methodName);
71
+ if (entry.Value.Count <= 0)
72
+ {
73
+ _ = typesToMethods.Remove(entry.Key);
74
+ break;
75
+ }
76
+ }
77
+ }
78
+
79
+ TypesToMethods = typesToMethods.ToDictionary(kvp => kvp.Key, kvp => (IReadOnlyList<MethodInfo>)kvp.Value);
80
+ }
81
+
82
+ public static List<MethodInfo> GetPossibleAnimatorEventsForType(this Type type)
83
+ {
84
+ return type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where
85
+ (
86
+ p =>
87
+ p.ReturnType == typeof(void) &&
88
+ (p.GetParameters().Select(q => q.ParameterType).SequenceEqual(new Type[] { }) ||
89
+ p.GetParameters().Select(q => q.ParameterType)
90
+ .SequenceEqual(new Type[] { typeof(int) }) ||
91
+ p.GetParameters().Select(q => q.ParameterType.BaseType)
92
+ .SequenceEqual(new Type[] { typeof(Enum) }) ||
93
+ p.GetParameters().Select(q => q.ParameterType)
94
+ .SequenceEqual(new Type[] { typeof(float) }) ||
95
+ p.GetParameters().Select(q => q.ParameterType)
96
+ .SequenceEqual(new Type[] { typeof(string) }) ||
97
+ p.GetParameters().Select(q => q.ParameterType)
98
+ .SequenceEqual(new Type[] { typeof(UnityEngine.Object) }))
99
+ ).OrderBy(method => method.Name).ToList();
100
+ }
101
+ }
102
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 813e6dba6f6598740b2950ce37ef1570
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,43 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+ using System.Linq;
5
+ using System.Reflection;
6
+ using JetBrains.Annotations;
7
+ using UnityEngine;
8
+
9
+ [AttributeUsage(AttributeTargets.Field)]
10
+ [MeansImplicitUse]
11
+ public sealed class AutomaticallyFindAttribute : Attribute
12
+ {
13
+ public readonly string Tag = string.Empty;
14
+ }
15
+
16
+ public static class AutomaticallyFindExtensions
17
+ {
18
+ public static void AutomaticallyFind(this Component component)
19
+ {
20
+ var properties = component
21
+ .GetType()
22
+ .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
23
+ .Where(prop => Attribute.IsDefined(prop, typeof(AutomaticallyFindAttribute)));
24
+
25
+ foreach (FieldInfo field in properties)
26
+ {
27
+ Type fieldType = field.FieldType;
28
+ Type type = fieldType.IsArray ? fieldType.GetElementType() : fieldType;
29
+
30
+ if (type == typeof(GameObject))
31
+ {
32
+ var attribute = field.GetCustomAttributes(typeof(AutomaticallyFindAttribute), false)[0] as AutomaticallyFindAttribute;
33
+ GameObject gameObject = GameObject.FindWithTag(attribute.Tag);
34
+ field.SetValue(component, gameObject);
35
+ return;
36
+ }
37
+
38
+ object foundObject = type.GetMethod("Find", BindingFlags.Public | BindingFlags.Static).Invoke(null, null);
39
+ field.SetValue(component, foundObject);
40
+ }
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 26082413782e4f3e800873e5495f494b
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,85 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+ using System.Collections;
5
+ using System.Collections.Generic;
6
+ using System.Linq;
7
+ using System.Reflection;
8
+ using Extension;
9
+ using JetBrains.Annotations;
10
+ using UnityEngine;
11
+
12
+ [AttributeUsage(AttributeTargets.Field)]
13
+ [MeansImplicitUse]
14
+ public sealed class ChildComponentAttribute : Attribute
15
+ {
16
+ public bool optional = false;
17
+ }
18
+
19
+ public static class ChildComponentExtensions
20
+ {
21
+ private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
22
+
23
+ public static void AssignChildComponents(this Component component)
24
+ {
25
+ Type componentType = component.GetType();
26
+ List<FieldInfo> fields = FieldsByType.GetOrAdd(componentType, type =>
27
+ {
28
+ FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
29
+ return fields
30
+ .Where(prop => Attribute.IsDefined(prop, typeof(ChildComponentAttribute)))
31
+ .ToList();
32
+ });
33
+
34
+ foreach (FieldInfo field in fields)
35
+ {
36
+ Type fieldType = field.FieldType;
37
+ bool isArray = fieldType.IsArray;
38
+ Type childComponentType = isArray ? fieldType.GetElementType() : fieldType;
39
+
40
+ bool foundChild;
41
+ if (isArray)
42
+ {
43
+ Component[] childComponents = component.GetComponentsInChildren(childComponentType, true);
44
+ foundChild = 0 < childComponents.Length;
45
+
46
+ Array correctTypedArray = Array.CreateInstance(childComponentType, childComponents.Length);
47
+ Array.Copy(childComponents, correctTypedArray, childComponents.Length);
48
+ field.SetValue(component, correctTypedArray);
49
+ }
50
+ else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
51
+ {
52
+ childComponentType = fieldType.GenericTypeArguments[0];
53
+ Type constructedListType = typeof(List<>).MakeGenericType(childComponentType);
54
+ IList instance = (IList) Activator.CreateInstance(constructedListType);
55
+
56
+ foundChild = false;
57
+ foreach (Component childComponent in component.GetComponentsInChildren(childComponentType, true))
58
+ {
59
+ instance.Add(childComponent);
60
+ foundChild = true;
61
+ }
62
+
63
+ field.SetValue(component, instance);
64
+ }
65
+ else
66
+ {
67
+ Component childComponent = component.GetComponentInChildren(childComponentType, true);
68
+ foundChild = childComponent != null;
69
+ if (foundChild)
70
+ {
71
+ field.SetValue(component, childComponent);
72
+ }
73
+ }
74
+
75
+ if (!foundChild)
76
+ {
77
+ if (field.GetCustomAttributes(typeof(ChildComponentAttribute), false)[0] is ChildComponentAttribute { optional: false } _)
78
+ {
79
+ component.LogError($"Unable to find child component of type {fieldType}");
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 2944db3ec3c23a34d94063750dca2739
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,23 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+
5
+ /// <summary>
6
+ /// If specified on a field or property, will automatically attempt to serialize that property
7
+ /// on MonoBehaviors when SerializedWorld is being constructed.
8
+ /// If specified on a class, will automatically attempt to serialize all fields and properties.
9
+ /// </summary>
10
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class)]
11
+ public sealed class KSerializableAttribute : Attribute
12
+ {
13
+ }
14
+
15
+ /// <summary>
16
+ /// For classes where KSerializableAttribute is used, specifying this on fields or properties
17
+ /// will ignore them for the purpose of serialization into SerializedWorld.
18
+ /// </summary>
19
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
20
+ public sealed class KNonSerializableAttribute : Attribute
21
+ {
22
+ }
23
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 6ebdc43388637b440aa75f5f9c92a4de
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,33 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Reflection;
7
+
8
+ [AttributeUsage(AttributeTargets.Field)]
9
+ public sealed class NotNullAttribute : Attribute
10
+ {
11
+ }
12
+
13
+ public static class NotNullAttributeExtensions
14
+ {
15
+ public static void CheckForNulls(this object o)
16
+ {
17
+ #if UNITY_EDITOR
18
+ IEnumerable<FieldInfo> properties = o.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
19
+ .Where(prop => Attribute.IsDefined(prop, typeof(NotNullAttribute)));
20
+
21
+ foreach (FieldInfo field in properties)
22
+ {
23
+ object fieldValue = field.GetValue(o);
24
+
25
+ if (fieldValue == null)
26
+ {
27
+ throw new ArgumentNullException(field.Name);
28
+ }
29
+ }
30
+ #endif
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 3e6951fbb938059438d1637f3873a7bc
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: