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.
- package/.gitattributes +63 -0
- package/CHANGELOG.md +0 -0
- package/CHANGELOG.md.meta +7 -0
- package/Editor/AnimationCreator.cs +218 -0
- package/Editor/AnimationCreator.cs.meta +11 -0
- package/Editor/AnimationEventEditor.cs +742 -0
- package/Editor/AnimationEventEditor.cs.meta +11 -0
- package/Editor/PrefabCheckWizard.cs +140 -0
- package/Editor/PrefabCheckWizard.cs.meta +11 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef +16 -0
- package/Editor/WallstopStudios.UnityHelpers.Editor.asmdef.meta +7 -0
- package/Editor.meta +8 -0
- package/LICENSE +21 -0
- package/LICENSE.md +7 -0
- package/LICENSE.md.meta +7 -0
- package/LICENSE.meta +7 -0
- package/README.md +2 -0
- package/README.md.meta +7 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs +102 -0
- package/Runtime/Core/Attributes/AnimationEventAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs +43 -0
- package/Runtime/Core/Attributes/AutomaticallyFindAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs +85 -0
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs +23 -0
- package/Runtime/Core/Attributes/KSerializableAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs +33 -0
- package/Runtime/Core/Attributes/NotNullAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ParentComponent.cs +85 -0
- package/Runtime/Core/Attributes/ParentComponent.cs.meta +11 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +8 -0
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs +14 -0
- package/Runtime/Core/Attributes/RelationalComponentExtensions.cs.meta +11 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +89 -0
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs +66 -0
- package/Runtime/Core/Attributes/ValidateAssignmentAttribute.cs.meta +11 -0
- package/Runtime/Core/Attributes.meta +8 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs +91 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector2Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs +180 -0
- package/Runtime/Core/DataStructure/Adapters/FastVector3Int.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs +274 -0
- package/Runtime/Core/DataStructure/Adapters/KGuid.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs +79 -0
- package/Runtime/Core/DataStructure/Adapters/KVector2.cs.meta +11 -0
- package/Runtime/Core/DataStructure/Adapters.meta +8 -0
- package/Runtime/Core/DataStructure/Circle.cs +50 -0
- package/Runtime/Core/DataStructure/Circle.cs.meta +11 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs +130 -0
- package/Runtime/Core/DataStructure/CyclicBuffer.cs.meta +11 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs +58 -0
- package/Runtime/Core/DataStructure/ISpatialTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/KDTree.cs +186 -0
- package/Runtime/Core/DataStructure/KDTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/QuadTree.cs +184 -0
- package/Runtime/Core/DataStructure/QuadTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/RTree.cs +247 -0
- package/Runtime/Core/DataStructure/RTree.cs.meta +11 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs +90 -0
- package/Runtime/Core/DataStructure/StringWrapper.cs.meta +11 -0
- package/Runtime/Core/DataStructure/TimedCache.cs +50 -0
- package/Runtime/Core/DataStructure/TimedCache.cs.meta +11 -0
- package/Runtime/Core/DataStructure.meta +8 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs +25 -0
- package/Runtime/Core/Extension/AnimatorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/CircleExtensions.cs +25 -0
- package/Runtime/Core/Extension/CircleExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/ColorExtensions.cs +72 -0
- package/Runtime/Core/Extension/ColorExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs +173 -0
- package/Runtime/Core/Extension/DictionaryExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs +210 -0
- package/Runtime/Core/Extension/DirectionExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs +12 -0
- package/Runtime/Core/Extension/HashSetExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs +109 -0
- package/Runtime/Core/Extension/IEnumerableExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/IListExtensions.cs +49 -0
- package/Runtime/Core/Extension/IListExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs +196 -0
- package/Runtime/Core/Extension/LoggingExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/RandomExtensions.cs +110 -0
- package/Runtime/Core/Extension/RandomExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/StringExtensions.cs +76 -0
- package/Runtime/Core/Extension/StringExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension/UnityExtensions.cs +1409 -0
- package/Runtime/Core/Extension/UnityExtensions.cs.meta +11 -0
- package/Runtime/Core/Extension.meta +8 -0
- package/Runtime/Core/Helper/AssignUtilities.cs +14 -0
- package/Runtime/Core/Helper/AssignUtilities.cs.meta +11 -0
- package/Runtime/Core/Helper/Enumerables.cs +17 -0
- package/Runtime/Core/Helper/Enumerables.cs.meta +11 -0
- package/Runtime/Core/Helper/Geometry.cs +26 -0
- package/Runtime/Core/Helper/Geometry.cs.meta +11 -0
- package/Runtime/Core/Helper/Helpers.cs +1092 -0
- package/Runtime/Core/Helper/Helpers.cs.meta +11 -0
- package/Runtime/Core/Helper/IterationHelpers.cs +32 -0
- package/Runtime/Core/Helper/IterationHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs +12 -0
- package/Runtime/Core/Helper/LifetimeHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/Objects.cs +447 -0
- package/Runtime/Core/Helper/Objects.cs.meta +11 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs +53 -0
- package/Runtime/Core/Helper/SpriteHelpers.cs.meta +11 -0
- package/Runtime/Core/Helper/StringInList.cs +31 -0
- package/Runtime/Core/Helper/StringInList.cs.meta +11 -0
- package/Runtime/Core/Helper/WallMath.cs +75 -0
- package/Runtime/Core/Helper/WallMath.cs.meta +11 -0
- package/Runtime/Core/Helper.meta +8 -0
- package/Runtime/Core/Math/Line.cs +51 -0
- package/Runtime/Core/Math/Line.cs.meta +11 -0
- package/Runtime/Core/Math/Parabola.cs +44 -0
- package/Runtime/Core/Math/Parabola.cs.meta +11 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs +25 -0
- package/Runtime/Core/Math/PointPolygonCheck.cs.meta +11 -0
- package/Runtime/Core/Math/Range.cs +56 -0
- package/Runtime/Core/Math/Range.cs.meta +11 -0
- package/Runtime/Core/Math/XXHash.cs +308 -0
- package/Runtime/Core/Math/XXHash.cs.meta +11 -0
- package/Runtime/Core/Math.meta +8 -0
- package/Runtime/Core/Model/Direction.cs +26 -0
- package/Runtime/Core/Model/Direction.cs.meta +11 -0
- package/Runtime/Core/Model.meta +8 -0
- package/Runtime/Core/OneOf/FastOneOf.cs +145 -0
- package/Runtime/Core/OneOf/FastOneOf.cs.meta +11 -0
- package/Runtime/Core/OneOf/None.cs +6 -0
- package/Runtime/Core/OneOf/None.cs.meta +11 -0
- package/Runtime/Core/OneOf.meta +8 -0
- package/Runtime/Core/Random/AbstractRandom.cs +537 -0
- package/Runtime/Core/Random/AbstractRandom.cs.meta +11 -0
- package/Runtime/Core/Random/IRandom.cs +141 -0
- package/Runtime/Core/Random/IRandom.cs.meta +11 -0
- package/Runtime/Core/Random/NativePcgRandom.cs +97 -0
- package/Runtime/Core/Random/NativePcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/PcgRandom.cs +142 -0
- package/Runtime/Core/Random/PcgRandom.cs.meta +11 -0
- package/Runtime/Core/Random/RandomState.cs +92 -0
- package/Runtime/Core/Random/RandomState.cs.meta +11 -0
- package/Runtime/Core/Random/RandomUtilities.cs +26 -0
- package/Runtime/Core/Random/RandomUtilities.cs.meta +11 -0
- package/Runtime/Core/Random/SquirrelRandom.cs +82 -0
- package/Runtime/Core/Random/SquirrelRandom.cs.meta +11 -0
- package/Runtime/Core/Random/SystemRandom.cs +110 -0
- package/Runtime/Core/Random/SystemRandom.cs.meta +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs +11 -0
- package/Runtime/Core/Random/ThreadLocalRandom.cs.meta +11 -0
- package/Runtime/Core/Random/UnityRandom.cs +24 -0
- package/Runtime/Core/Random/UnityRandom.cs.meta +11 -0
- package/Runtime/Core/Random/XorShiftRandom.cs +45 -0
- package/Runtime/Core/Random/XorShiftRandom.cs.meta +11 -0
- package/Runtime/Core/Random.meta +8 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector2Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs +32 -0
- package/Runtime/Core/Serialization/JsonConverters/Vector3Converter.cs.meta +11 -0
- package/Runtime/Core/Serialization/JsonConverters.meta +8 -0
- package/Runtime/Core/Serialization/Serializer.cs +125 -0
- package/Runtime/Core/Serialization/Serializer.cs.meta +11 -0
- package/Runtime/Core/Serialization.meta +8 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs +102 -0
- package/Runtime/Core/Threading/SingleThreadedThreadPool.cs.meta +11 -0
- package/Runtime/Core/Threading.meta +8 -0
- package/Runtime/Core.meta +8 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll +0 -0
- package/Runtime/Protobuf-Net/System.Buffers.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll +0 -0
- package/Runtime/Protobuf-Net/System.Collections.Immutable.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll +0 -0
- package/Runtime/Protobuf-Net/System.Numerics.Vectors.dll.meta +33 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/Runtime/Protobuf-Net/System.Runtime.CompilerServices.Unsafe.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.Core.dll.meta +33 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll +0 -0
- package/Runtime/Protobuf-Net/protobuf-net.dll.meta +33 -0
- package/Runtime/Protobuf-Net.meta +8 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs +149 -0
- package/Runtime/Utils/AnimationEventEqualityComparer.cs.meta +11 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs +80 -0
- package/Runtime/Utils/AnimatorEnumStateMachine.cs.meta +11 -0
- package/Runtime/Utils/Buffers.cs +32 -0
- package/Runtime/Utils/Buffers.cs.meta +11 -0
- package/Runtime/Utils/CircleLineRenderer.cs +122 -0
- package/Runtime/Utils/CircleLineRenderer.cs.meta +11 -0
- package/Runtime/Utils/Oscillator.cs +25 -0
- package/Runtime/Utils/Oscillator.cs.meta +11 -0
- package/Runtime/Utils/SetTextureImportData.cs +67 -0
- package/Runtime/Utils/SetTextureImportData.cs.meta +11 -0
- package/Runtime/Utils.meta +8 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef +14 -0
- package/Runtime/WallstopStudios.UnityHelpers.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef +17 -0
- package/Tests/Editor/WallstopStudios.UnityHelpers.Tests.Editor.asmdef.meta +7 -0
- package/Tests/Editor.meta +8 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/BalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/QuadTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs +106 -0
- package/Tests/Runtime/DataStructures/SpatialTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/DataStructures/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/DataStructures.meta +8 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/KDTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs +14 -0
- package/Tests/Runtime/Performance/QuadTreePerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +76 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs +141 -0
- package/Tests/Runtime/Performance/SpatialTreePerformanceTest.cs.meta +11 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs +14 -0
- package/Tests/Runtime/Performance/UnbalancedKDTreeTests.cs.meta +11 -0
- package/Tests/Runtime/Performance.meta +8 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs +9 -0
- package/Tests/Runtime/Random/PcgRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/RandomTestBase.cs +117 -0
- package/Tests/Runtime/Random/RandomTestBase.cs.meta +11 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs +9 -0
- package/Tests/Runtime/Random/SquirrelRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs +10 -0
- package/Tests/Runtime/Random/SystemRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs +9 -0
- package/Tests/Runtime/Random/UnityRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs +9 -0
- package/Tests/Runtime/Random/XorShiftRandomTests.cs.meta +11 -0
- package/Tests/Runtime/Random.meta +8 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef +22 -0
- package/Tests/Runtime/WallstopStudios.UnityHelpers.Tests.Runtime.asmdef.meta +7 -0
- package/Tests/Runtime.meta +8 -0
- package/Tests.meta +8 -0
- package/Third Party Notices.md +1 -0
- package/Third Party Notices.md.meta +7 -0
- package/package.json +35 -0
- 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,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,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,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,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,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
|
+
}
|