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,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 ParentComponentAttribute : Attribute
15
+ {
16
+ public bool optional = false;
17
+ }
18
+
19
+ public static class ParentComponentExtensions
20
+ {
21
+ private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
22
+
23
+ public static void AssignParentComponents(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(ParentComponentAttribute)))
31
+ .ToList();
32
+ });
33
+
34
+ foreach (FieldInfo field in fields)
35
+ {
36
+ Type fieldType = field.FieldType;
37
+ bool isArray = fieldType.IsArray;
38
+ Type parentComponentType = isArray ? fieldType.GetElementType() : fieldType;
39
+
40
+ bool foundParent;
41
+ if (isArray)
42
+ {
43
+ Component[] parentComponents = component.GetComponentsInParent(parentComponentType, true);
44
+ foundParent = 0 < parentComponents.Length;
45
+
46
+ Array correctTypedArray = Array.CreateInstance(parentComponentType, parentComponents.Length);
47
+ Array.Copy(parentComponents, correctTypedArray, parentComponents.Length);
48
+ field.SetValue(component, correctTypedArray);
49
+ }
50
+ else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
51
+ {
52
+ parentComponentType = fieldType.GenericTypeArguments[0];
53
+ Type constructedListType = typeof(List<>).MakeGenericType(parentComponentType);
54
+ IList instance = (IList) Activator.CreateInstance(constructedListType);
55
+
56
+ foundParent = false;
57
+ foreach (Component parentComponent in component.GetComponentsInParent(parentComponentType, true))
58
+ {
59
+ instance.Add(parentComponent);
60
+ foundParent = true;
61
+ }
62
+
63
+ field.SetValue(component, instance);
64
+ }
65
+ else
66
+ {
67
+ Component childComponent = component.GetComponentInParent(parentComponentType, true);
68
+ foundParent = childComponent != null;
69
+ if (foundParent)
70
+ {
71
+ field.SetValue(component, childComponent);
72
+ }
73
+ }
74
+
75
+ if (!foundParent)
76
+ {
77
+ if (field.GetCustomAttributes(typeof(ParentComponentAttribute), false)[0] is ParentComponentAttribute { optional: false } _)
78
+ {
79
+ component.LogError($"Unable to find parent component of type {fieldType}");
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 9072f528d7f8db841a61fd0b90a86143
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ using PropertyAttribute = UnityEngine.PropertyAttribute;
2
+
3
+ namespace UnityHelpers.Core.Attributes
4
+ {
5
+ public sealed class ReadOnlyAttribute : PropertyAttribute
6
+ {
7
+ }
8
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 247a8c9698297f04290d6235f7aebf62
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,14 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using UnityEngine;
4
+
5
+ public static class RelationalComponentExtensions
6
+ {
7
+ public static void AssignRelationalComponents(this Component component)
8
+ {
9
+ component.AssignParentComponents();
10
+ component.AssignSiblingComponents();
11
+ component.AssignChildComponents();
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: f028f737f3af2064fb0279b37ab37707
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,89 @@
1
+ namespace UnityHelpers.Core.Attributes
2
+ {
3
+ using Extension;
4
+ using JetBrains.Annotations;
5
+ using System;
6
+ using System.Collections;
7
+ using System.Collections.Generic;
8
+ using System.Linq;
9
+ using System.Reflection;
10
+ using UnityEngine;
11
+
12
+ [AttributeUsage(AttributeTargets.Field)]
13
+ [MeansImplicitUse]
14
+ public sealed class SiblingComponentAttribute : Attribute
15
+ {
16
+ public bool optional = false;
17
+ }
18
+
19
+ public static class SiblingComponentExtensions
20
+ {
21
+ private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
22
+
23
+ public static void AssignSiblingComponents(this Component component)
24
+ {
25
+ Type componentType = component.GetType();
26
+ List<FieldInfo> fields = FieldsByType.GetOrAdd(componentType,
27
+ type =>
28
+ {
29
+ FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
30
+ return fields
31
+ .Where(prop => Attribute.IsDefined(prop, typeof(SiblingComponentAttribute)))
32
+ .ToList();
33
+ });
34
+
35
+ foreach (FieldInfo field in fields)
36
+ {
37
+ Type fieldType = field.FieldType;
38
+ bool isArray = fieldType.IsArray;
39
+ Type siblingComponentType = isArray ? fieldType.GetElementType() : fieldType;
40
+
41
+ bool foundSibling;
42
+ if (isArray)
43
+ {
44
+ Component[] siblingComponents = component.GetComponents(siblingComponentType);
45
+ foundSibling = 0 < siblingComponents.Length;
46
+
47
+ Array correctTypedArray = Array.CreateInstance(siblingComponentType, siblingComponents.Length);
48
+ Array.Copy(siblingComponents, correctTypedArray, siblingComponents.Length);
49
+ field.SetValue(component, correctTypedArray);
50
+ }
51
+ else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(List<>))
52
+ {
53
+ siblingComponentType = fieldType.GenericTypeArguments[0];
54
+ Type constructedListType = typeof(List<>).MakeGenericType(siblingComponentType);
55
+ IList instance = (IList) Activator.CreateInstance(constructedListType);
56
+
57
+ foundSibling = false;
58
+ foreach (Component siblingComponent in component.GetComponents(siblingComponentType))
59
+ {
60
+ instance.Add(siblingComponent);
61
+ foundSibling = true;
62
+ }
63
+
64
+ field.SetValue(component, instance);
65
+ }
66
+ else
67
+ {
68
+ if (component.TryGetComponent(siblingComponentType, out Component siblingComponent))
69
+ {
70
+ foundSibling = true;
71
+ field.SetValue(component, siblingComponent);
72
+ }
73
+ else
74
+ {
75
+ foundSibling = false;
76
+ }
77
+ }
78
+
79
+ if (!foundSibling)
80
+ {
81
+ if (field.GetCustomAttributes(typeof(SiblingComponentAttribute), false)[0] is SiblingComponentAttribute {optional: false} _)
82
+ {
83
+ component.LogError($"Unable to find sibling component of type {fieldType}");
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 9c1d4c3207014d1ba52bd8f19428ceed
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,66 @@
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 Helper;
10
+ using JetBrains.Annotations;
11
+ using Object = UnityEngine.Object;
12
+
13
+ [AttributeUsage(AttributeTargets.Field)]
14
+ [MeansImplicitUse]
15
+ public sealed class ValidateAssignmentAttribute : Attribute
16
+ {
17
+ }
18
+
19
+ public static class ValidateAssignmentExtensions
20
+ {
21
+ private static readonly Dictionary<Type, List<FieldInfo>> FieldsByType = new();
22
+
23
+ public static void ValidateAssignments(this Object o)
24
+ {
25
+ #if UNITY_EDITOR
26
+ Type objectType = o.GetType();
27
+ List<FieldInfo> fields = FieldsByType.GetOrAdd(objectType, type => type
28
+ .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
29
+ .Where(prop => Attribute.IsDefined(prop, typeof(ValidateAssignmentAttribute))).ToList());
30
+
31
+ foreach (FieldInfo field in fields)
32
+ {
33
+ bool logNotAssigned = IsFieldInvalid(field, o);
34
+
35
+ if (logNotAssigned)
36
+ {
37
+ o.LogNotAssigned(field.Name);
38
+ }
39
+ }
40
+ #endif
41
+ }
42
+
43
+ public static bool AreAnyAssignmentsInvalid(this Object o)
44
+ {
45
+ Type objectType = o.GetType();
46
+ List<FieldInfo> fields = FieldsByType.GetOrAdd(objectType, type => type
47
+ .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
48
+ .Where(prop => Attribute.IsDefined(prop, typeof(ValidateAssignmentAttribute))).ToList());
49
+
50
+ return fields.Any(field => IsFieldInvalid(field, o));
51
+ }
52
+
53
+ private static bool IsFieldInvalid(FieldInfo field, Object o)
54
+ {
55
+ object fieldValue = field.GetValue(o);
56
+ return fieldValue switch
57
+ {
58
+ IList list => list.Count <= 0,
59
+ ICollection collection => collection.Count <= 0,
60
+ Object unityObject => !unityObject,
61
+ string stringValue => string.IsNullOrWhiteSpace(stringValue),
62
+ _ => fieldValue == null
63
+ };
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: b7257e9c0b064297b84ba827599da046
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 139606485fde4f4ea168e7a8cf721a8a
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,91 @@
1
+ namespace UnityHelpers.Core.DataStructure.Adapters
2
+ {
3
+ using System;
4
+ using System.Runtime.CompilerServices;
5
+ using Helper;
6
+ using ProtoBuf;
7
+ using UnityEngine;
8
+
9
+ [Serializable]
10
+ [ProtoContract]
11
+ public struct FastVector2Int : IEquatable<FastVector2Int>
12
+ {
13
+ [ProtoMember(1)]
14
+ public int x;
15
+ [ProtoMember(2)]
16
+ public int y;
17
+
18
+ private int _hash;
19
+
20
+ public FastVector2Int(int x, int y)
21
+ {
22
+ this.x = x;
23
+ this.y = y;
24
+
25
+ _hash = Objects.ValueTypeHashCode(x, y);
26
+ }
27
+
28
+ public static implicit operator Vector2Int(FastVector2Int vector)
29
+ {
30
+ return new Vector2Int(vector.x, vector.y);
31
+ }
32
+
33
+ public static implicit operator FastVector2Int(FastVector3Int vector)
34
+ {
35
+ return new FastVector2Int(vector.x, vector.y);
36
+ }
37
+
38
+ public static implicit operator FastVector2Int(Vector2Int vector)
39
+ {
40
+ return new FastVector2Int(vector.x, vector.y);
41
+ }
42
+
43
+ public static FastVector2Int operator +(FastVector2Int lhs, FastVector2Int rhs)
44
+ {
45
+ return new FastVector2Int(lhs.x + rhs.x, lhs.y + rhs.y);
46
+ }
47
+
48
+ public static FastVector2Int operator -(FastVector2Int lhs, FastVector2Int rhs)
49
+ {
50
+ return new FastVector2Int(lhs.x - rhs.x, lhs.y - rhs.y);
51
+ }
52
+
53
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
54
+ public bool Equals(FastVector2Int other)
55
+ {
56
+ return GetHashCode() == other.GetHashCode() && x == other.x && y == other.y;
57
+ }
58
+
59
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
60
+ public override bool Equals(object obj)
61
+ {
62
+ return obj is FastVector2Int other && Equals(other);
63
+ }
64
+
65
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
66
+ public override int GetHashCode()
67
+ {
68
+ if (_hash == 0)
69
+ {
70
+ _hash = Objects.ValueTypeHashCode(x, y);
71
+ }
72
+ return _hash;
73
+ }
74
+
75
+ public override string ToString()
76
+ {
77
+ return $"({x}, {y})";
78
+ }
79
+
80
+ [ProtoAfterDeserialization]
81
+ private void AfterDeserialize()
82
+ {
83
+ _hash = Objects.ValueTypeHashCode(x, y);
84
+ }
85
+
86
+ public readonly FastVector3Int AsFastVector3Int()
87
+ {
88
+ return new FastVector3Int(x, y);
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 71ec9bb7a199b0046a717079f9ad42f9
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,180 @@
1
+ namespace UnityHelpers.Core.DataStructure.Adapters
2
+ {
3
+ using System;
4
+ using System.Runtime.CompilerServices;
5
+ using Helper;
6
+ using ProtoBuf;
7
+ using UnityEngine;
8
+
9
+ [Serializable]
10
+ [ProtoContract]
11
+ public struct FastVector3Int : IEquatable<FastVector3Int>, IComparable<FastVector3Int>, IComparable
12
+ {
13
+ public static readonly FastVector3Int zero = new(0, 0, 0);
14
+
15
+ [ProtoMember(1)]
16
+ public int x;
17
+ [ProtoMember(2)]
18
+ public int y;
19
+ [ProtoMember(3)]
20
+ public int z;
21
+
22
+ private int _hash;
23
+
24
+ public FastVector3Int(int x, int y, int z)
25
+ {
26
+ this.x = x;
27
+ this.y = y;
28
+ this.z = z;
29
+ _hash = Objects.ValueTypeHashCode(x, y, z);
30
+ }
31
+
32
+ public FastVector3Int(Vector3Int vector)
33
+ : this(vector.x, vector.y, vector.z)
34
+ {
35
+ }
36
+
37
+ public FastVector3Int(int x, int y) : this(x, y, 0)
38
+ {
39
+ }
40
+
41
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
42
+ public static bool operator ==(FastVector3Int lhs, FastVector3Int rhs)
43
+ {
44
+ return lhs.Equals(rhs);
45
+ }
46
+
47
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
48
+ public static bool operator !=(FastVector3Int lhs, FastVector3Int rhs)
49
+ {
50
+ return !lhs.Equals(rhs);
51
+ }
52
+
53
+ public static FastVector3Int operator +(FastVector3Int lhs, FastVector3Int rhs)
54
+ {
55
+ return new FastVector3Int(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
56
+ }
57
+
58
+ public static FastVector3Int operator +(FastVector3Int lhs, Vector3Int rhs)
59
+ {
60
+ return new FastVector3Int(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
61
+ }
62
+
63
+ public static FastVector3Int operator +(FastVector3Int lhs, Vector2Int rhs)
64
+ {
65
+ return new FastVector3Int(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z);
66
+ }
67
+
68
+ public static FastVector3Int operator +(FastVector3Int lhs, FastVector2Int rhs)
69
+ {
70
+ return new FastVector3Int(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z);
71
+ }
72
+
73
+ public static FastVector3Int operator -(FastVector3Int lhs, FastVector3Int rhs)
74
+ {
75
+ return new FastVector3Int(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
76
+ }
77
+
78
+ public static FastVector3Int operator -(FastVector3Int lhs, Vector3Int rhs)
79
+ {
80
+ return new FastVector3Int(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
81
+ }
82
+
83
+ public static FastVector3Int operator -(FastVector3Int lhs, FastVector2Int rhs)
84
+ {
85
+ return new FastVector3Int(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z);
86
+ }
87
+
88
+ public static FastVector3Int operator -(FastVector3Int lhs, Vector2Int rhs)
89
+ {
90
+ return new FastVector3Int(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z);
91
+ }
92
+
93
+ public static implicit operator Vector3Int(FastVector3Int vector)
94
+ {
95
+ return new Vector3Int(vector.x, vector.y, vector.z);
96
+ }
97
+
98
+ public static implicit operator FastVector3Int(Vector3Int vector)
99
+ {
100
+ return new FastVector3Int(vector.x, vector.y, vector.z);
101
+ }
102
+
103
+ public static implicit operator Vector2Int(FastVector3Int vector)
104
+ {
105
+ return new Vector2Int(vector.x, vector.y);
106
+ }
107
+
108
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
109
+ public override int GetHashCode()
110
+ {
111
+ if (_hash == 0)
112
+ {
113
+ _hash = Objects.ValueTypeHashCode(x, y, z);
114
+ }
115
+ return _hash;
116
+ }
117
+
118
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
119
+ public override bool Equals(object obj)
120
+ {
121
+ return obj is FastVector3Int other && Equals(other);
122
+ }
123
+
124
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
125
+ public bool Equals(FastVector3Int other)
126
+ {
127
+ return GetHashCode() == other.GetHashCode() && x == other.x && y == other.y && z == other.z;
128
+ }
129
+
130
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
131
+ public int CompareTo(FastVector3Int other)
132
+ {
133
+ int comparison = x.CompareTo(other.x);
134
+ if (comparison != 0)
135
+ {
136
+ return comparison;
137
+ }
138
+
139
+ comparison = y.CompareTo(other.y);
140
+ if (comparison != 0)
141
+ {
142
+ return comparison;
143
+ }
144
+
145
+ return z.CompareTo(other.z);
146
+ }
147
+
148
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
149
+ public int CompareTo(object other)
150
+ {
151
+ if (other is FastVector3Int vector)
152
+ {
153
+ return CompareTo(vector);
154
+ }
155
+
156
+ return -1;
157
+ }
158
+
159
+ public override string ToString()
160
+ {
161
+ return $"({x}, {y}, {z})";
162
+ }
163
+
164
+ [ProtoAfterDeserialization]
165
+ private void AfterDeserialize()
166
+ {
167
+ _hash = Objects.ValueTypeHashCode(x, y, z);
168
+ }
169
+
170
+ public readonly Vector2 AsVector2()
171
+ {
172
+ return new Vector2(x, y);
173
+ }
174
+
175
+ public readonly Vector3 AsVector3()
176
+ {
177
+ return new Vector3(x, y, z);
178
+ }
179
+ }
180
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 681550c1fb651694191ca6370b3f0f44
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: