com.wallstop-studios.unity-helpers 2.0.0-rc39 → 2.0.0-rc40
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/.github/workflows/npm-publish.yml +22 -26
- package/Editor/AnimationCopier.cs +25 -2
- package/Editor/AnimationCreator.cs +18 -27
- package/Editor/AnimatorControllerCopier.cs +7 -7
- package/Editor/EnsureTextureSizeWizard.cs +14 -9
- package/Editor/PrefabCheckWizard.cs +1 -1
- package/Editor/Utils/{ReadOnlyPropertyDrawer.cs → DxReadOnlyPropertyDrawer.cs} +2 -2
- package/README.md +37 -1
- package/Runtime/Core/Attributes/ChildComponentAttribute.cs +39 -19
- package/Runtime/Core/Attributes/DxReadOnlyAttribute.cs +6 -0
- package/Runtime/Core/Attributes/ParentComponent.cs +16 -15
- package/Runtime/Core/Attributes/SiblingComponentAttribute.cs +7 -9
- package/Runtime/Core/Helper/Partials/TransformHelpers.cs +26 -0
- package/Runtime/Core/Helper/ReflectionHelpers.cs +97 -22
- package/Tests/Runtime/Components/{RelationalComponentTester.cs → RelationalComponentTesterComplex.cs} +1 -1
- package/Tests/Runtime/Components/RelationalComponentsTesterSimple.cs +40 -0
- package/Tests/Runtime/Components/RelationalComponentsTesterSimple.cs.meta +3 -0
- package/Tests/Runtime/Helper/ReflectionHelperTests.cs +179 -0
- package/Tests/Runtime/Helper/ReflectionHelperTests.cs.meta +3 -0
- package/Tests/Runtime/Performance/RelationComponentPerformanceTests.cs +27 -3
- package/package.json +1 -1
- package/.github/workflows/unity-package.yml +0 -105
- package/Editor/BuildScript.cs +0 -33
- package/Editor/BuildScript.cs.meta +0 -3
- package/Editor/Scenes/SampleScene.unity +0 -221
- package/Editor/Scenes/SampleScene.unity.meta +0 -7
- package/Editor/Scenes.meta +0 -3
- package/Runtime/Core/Attributes/ReadOnlyAttribute.cs +0 -6
- /package/Editor/Utils/{ReadOnlyPropertyDrawer.cs.meta → DxReadOnlyPropertyDrawer.cs.meta} +0 -0
- /package/Runtime/Core/Attributes/{ReadOnlyAttribute.cs.meta → DxReadOnlyAttribute.cs.meta} +0 -0
- /package/Tests/Runtime/Components/{RelationalComponentTester.cs.meta → RelationalComponentTesterComplex.cs.meta} +0 -0
|
@@ -8,22 +8,20 @@
|
|
|
8
8
|
using System.Runtime.CompilerServices;
|
|
9
9
|
using Extension;
|
|
10
10
|
|
|
11
|
+
public delegate void FieldSetter<TInstance, in TValue>(ref TInstance instance, TValue value);
|
|
12
|
+
|
|
11
13
|
public static class ReflectionHelpers
|
|
12
14
|
{
|
|
13
15
|
private static readonly Dictionary<Type, Func<int, Array>> ArrayCreators = new();
|
|
14
16
|
private static readonly Dictionary<Type, Func<IList>> ListCreators = new();
|
|
15
17
|
private static readonly Dictionary<Type, Func<int, IList>> ListWithCapacityCreators = new();
|
|
16
18
|
|
|
17
|
-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
18
|
-
public static Func<int, Array> GetOrCreateArrayCreator(Type type)
|
|
19
|
-
{
|
|
20
|
-
return ArrayCreators.GetOrAdd(type, elementType => GetArrayCreator(elementType));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
24
20
|
public static Array CreateArray(Type type, int length)
|
|
25
21
|
{
|
|
26
|
-
return
|
|
22
|
+
return ArrayCreators
|
|
23
|
+
.GetOrAdd(type, elementType => GetArrayCreator(elementType))
|
|
24
|
+
.Invoke(length);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
@@ -40,32 +38,110 @@
|
|
|
40
38
|
return ListCreators.GetOrAdd(elementType, type => GetListCreator(type)).Invoke();
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
public static
|
|
41
|
+
public static Func<object, object> GetFieldGetter(FieldInfo field)
|
|
42
|
+
{
|
|
43
|
+
#if WEB_GL
|
|
44
|
+
return field.GetValue;
|
|
45
|
+
#else
|
|
46
|
+
DynamicMethod dynamicMethod = new(
|
|
47
|
+
$"Get{(field.DeclaringType?.Name ?? string.Empty)}{field.Name}",
|
|
48
|
+
typeof(object),
|
|
49
|
+
new[] { typeof(object) },
|
|
50
|
+
field.DeclaringType,
|
|
51
|
+
true
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
ILGenerator il = dynamicMethod.GetILGenerator();
|
|
55
|
+
il.Emit(OpCodes.Ldarg_0);
|
|
56
|
+
il.Emit(
|
|
57
|
+
field.DeclaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass,
|
|
58
|
+
field.DeclaringType
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
il.Emit(OpCodes.Ldfld, field);
|
|
62
|
+
|
|
63
|
+
// If the field's type is a value type, box it.
|
|
64
|
+
if (field.FieldType.IsValueType)
|
|
65
|
+
{
|
|
66
|
+
il.Emit(OpCodes.Box, field.FieldType);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
il.Emit(OpCodes.Ret);
|
|
70
|
+
|
|
71
|
+
return (Func<object, object>)dynamicMethod.CreateDelegate(typeof(Func<object, object>));
|
|
72
|
+
#endif
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public static FieldSetter<TInstance, TValue> GetFieldSetter<TInstance, TValue>(
|
|
76
|
+
FieldInfo field
|
|
77
|
+
)
|
|
78
|
+
{
|
|
79
|
+
#if WEB_GL
|
|
80
|
+
return Setter;
|
|
81
|
+
void Setter(ref TInstance instance, TValue newValue)
|
|
82
|
+
{
|
|
83
|
+
object value = instance;
|
|
84
|
+
field.SetValue(value, newValue);
|
|
85
|
+
instance = (TInstance)value;
|
|
86
|
+
}
|
|
87
|
+
#else
|
|
88
|
+
Type instanceType = field.DeclaringType;
|
|
89
|
+
Type valueType = field.FieldType;
|
|
90
|
+
|
|
91
|
+
DynamicMethod dynamicMethod = new(
|
|
92
|
+
$"SetFieldGeneric{field.DeclaringType.Name}{field.Name}",
|
|
93
|
+
MethodAttributes.Public | MethodAttributes.Static,
|
|
94
|
+
CallingConventions.Standard,
|
|
95
|
+
typeof(void),
|
|
96
|
+
new[] { instanceType.MakeByRefType(), valueType },
|
|
97
|
+
field.Module,
|
|
98
|
+
true
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
ILGenerator il = dynamicMethod.GetILGenerator();
|
|
102
|
+
il.Emit(OpCodes.Ldarg_0);
|
|
103
|
+
if (!instanceType.IsValueType)
|
|
104
|
+
{
|
|
105
|
+
il.Emit(OpCodes.Ldind_Ref);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
il.Emit(OpCodes.Ldarg_1);
|
|
109
|
+
il.Emit(OpCodes.Stfld, field);
|
|
110
|
+
il.Emit(OpCodes.Ret);
|
|
111
|
+
|
|
112
|
+
Type delegateType = typeof(FieldSetter<,>).MakeGenericType(instanceType, valueType);
|
|
113
|
+
return (FieldSetter<TInstance, TValue>)dynamicMethod.CreateDelegate(delegateType);
|
|
114
|
+
#endif
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static Action<object, object> GetFieldSetter(FieldInfo field)
|
|
44
118
|
{
|
|
45
119
|
#if WEB_GL
|
|
46
120
|
return field.SetValue;
|
|
47
121
|
#else
|
|
48
122
|
DynamicMethod dynamicMethod = new(
|
|
49
|
-
$"SetField{field.Name}",
|
|
123
|
+
$"SetField{field.DeclaringType.Name}{field.Name}",
|
|
50
124
|
null,
|
|
51
125
|
new[] { typeof(object), typeof(object) },
|
|
52
|
-
|
|
126
|
+
field.DeclaringType.Module,
|
|
53
127
|
true
|
|
54
128
|
);
|
|
55
129
|
|
|
56
130
|
ILGenerator il = dynamicMethod.GetILGenerator();
|
|
57
131
|
|
|
58
|
-
il.Emit(OpCodes.Ldarg_0);
|
|
59
|
-
il.Emit(
|
|
132
|
+
il.Emit(OpCodes.Ldarg_0);
|
|
133
|
+
il.Emit(
|
|
134
|
+
field.DeclaringType.IsValueType ? OpCodes.Unbox : OpCodes.Castclass,
|
|
135
|
+
field.DeclaringType
|
|
136
|
+
);
|
|
60
137
|
|
|
61
|
-
il.Emit(OpCodes.Ldarg_1);
|
|
138
|
+
il.Emit(OpCodes.Ldarg_1);
|
|
62
139
|
il.Emit(
|
|
63
140
|
field.FieldType.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass,
|
|
64
141
|
field.FieldType
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
il.Emit(OpCodes.
|
|
68
|
-
il.Emit(OpCodes.Ret); // Return
|
|
142
|
+
);
|
|
143
|
+
il.Emit(OpCodes.Stfld, field);
|
|
144
|
+
il.Emit(OpCodes.Ret);
|
|
69
145
|
return (Action<object, object>)
|
|
70
146
|
dynamicMethod.CreateDelegate(typeof(Action<object, object>));
|
|
71
147
|
#endif
|
|
@@ -76,9 +152,8 @@
|
|
|
76
152
|
#if WEB_GL
|
|
77
153
|
return size => Array.CreateInstance(elementType, size);
|
|
78
154
|
#else
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
$"CreateArray{elementType.Namespace}",
|
|
155
|
+
DynamicMethod dynamicMethod = new(
|
|
156
|
+
$"CreateArray{elementType.Name}",
|
|
82
157
|
typeof(Array), // Return type: Array
|
|
83
158
|
new[] { typeof(int) }, // Parameter: int (size)
|
|
84
159
|
true
|
|
@@ -98,7 +173,7 @@
|
|
|
98
173
|
#if WEB_GL
|
|
99
174
|
return () => (IList)Activator.CreateInstance(listType);
|
|
100
175
|
#else
|
|
101
|
-
DynamicMethod dynamicMethod = new
|
|
176
|
+
DynamicMethod dynamicMethod = new(
|
|
102
177
|
$"CreateList{listType.Name}",
|
|
103
178
|
typeof(IList), // Return type: IList
|
|
104
179
|
Type.EmptyTypes, // No parameters
|
|
@@ -126,7 +201,7 @@
|
|
|
126
201
|
#if WEB_GL
|
|
127
202
|
return _ => (IList)Activator.CreateInstance(listType);
|
|
128
203
|
#else
|
|
129
|
-
DynamicMethod dynamicMethod = new
|
|
204
|
+
DynamicMethod dynamicMethod = new(
|
|
130
205
|
$"CreateListWithCapacity{listType.Name}",
|
|
131
206
|
typeof(IList), // Return type: IList
|
|
132
207
|
new[] { typeof(int) }, // Parameter: int (size)
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[RequireComponent(typeof(BoxCollider2D))]
|
|
9
9
|
[RequireComponent(typeof(BoxCollider2D))]
|
|
10
10
|
[RequireComponent(typeof(PolygonCollider2D))]
|
|
11
|
-
public sealed class
|
|
11
|
+
public sealed class RelationalComponentTesterComplex : MonoBehaviour
|
|
12
12
|
{
|
|
13
13
|
[SiblingComponent]
|
|
14
14
|
internal SpriteRenderer _spriteRenderer;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
namespace UnityHelpers.Tests.Components
|
|
2
|
+
{
|
|
3
|
+
namespace UnityHelpers.Tests.Components
|
|
4
|
+
{
|
|
5
|
+
using Core.Attributes;
|
|
6
|
+
using UnityEngine;
|
|
7
|
+
|
|
8
|
+
[DisallowMultipleComponent]
|
|
9
|
+
[RequireComponent(typeof(SpriteRenderer))]
|
|
10
|
+
[RequireComponent(typeof(BoxCollider2D))]
|
|
11
|
+
[RequireComponent(typeof(BoxCollider2D))]
|
|
12
|
+
[RequireComponent(typeof(PolygonCollider2D))]
|
|
13
|
+
public sealed class RelationalComponentTesterSimple : MonoBehaviour
|
|
14
|
+
{
|
|
15
|
+
[SiblingComponent]
|
|
16
|
+
internal SpriteRenderer _spriteRenderer;
|
|
17
|
+
|
|
18
|
+
[SiblingComponent]
|
|
19
|
+
internal Transform _transform;
|
|
20
|
+
|
|
21
|
+
[SiblingComponent]
|
|
22
|
+
internal PolygonCollider2D _polygonCollider;
|
|
23
|
+
|
|
24
|
+
// [ParentComponent]
|
|
25
|
+
// internal PolygonCollider2D _polygonColliderParent;
|
|
26
|
+
|
|
27
|
+
[SiblingComponent]
|
|
28
|
+
internal BoxCollider2D _boxCollider;
|
|
29
|
+
|
|
30
|
+
// [ParentComponent]
|
|
31
|
+
// internal BoxCollider2D _boxColliderParent;
|
|
32
|
+
//
|
|
33
|
+
// [ChildComponent]
|
|
34
|
+
// internal BoxCollider2D _boxColliderChild;
|
|
35
|
+
//
|
|
36
|
+
// [ChildComponent]
|
|
37
|
+
// internal BoxCollider2D _boxColliderParentChild;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
namespace UnityHelpers.Tests.Tests.Runtime.Helper
|
|
2
|
+
{
|
|
3
|
+
using System;
|
|
4
|
+
using System.Collections;
|
|
5
|
+
using System.Collections.Generic;
|
|
6
|
+
using Core.Helper;
|
|
7
|
+
using NUnit.Framework;
|
|
8
|
+
|
|
9
|
+
public struct TestStruct
|
|
10
|
+
{
|
|
11
|
+
public int intValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public sealed class TestClass
|
|
15
|
+
{
|
|
16
|
+
public int intValue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public sealed class ReflectionHelperTests
|
|
20
|
+
{
|
|
21
|
+
internal const int NumTries = 1_000;
|
|
22
|
+
|
|
23
|
+
private readonly Random _random = new();
|
|
24
|
+
|
|
25
|
+
[Test]
|
|
26
|
+
public void GetFieldGetterClass()
|
|
27
|
+
{
|
|
28
|
+
TestClass testClass = new();
|
|
29
|
+
Func<object, object> classGetter = ReflectionHelpers.GetFieldGetter(
|
|
30
|
+
typeof(TestClass).GetField(nameof(TestClass.intValue))
|
|
31
|
+
);
|
|
32
|
+
Assert.AreEqual(testClass.intValue, classGetter(testClass));
|
|
33
|
+
for (int i = 0; i < NumTries; ++i)
|
|
34
|
+
{
|
|
35
|
+
testClass.intValue = _random.Next(int.MinValue, int.MaxValue);
|
|
36
|
+
Assert.AreEqual(testClass.intValue, classGetter(testClass));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
[Test]
|
|
41
|
+
public void GetFieldGetterStruct()
|
|
42
|
+
{
|
|
43
|
+
TestStruct testStruct = new();
|
|
44
|
+
Func<object, object> structGetter = ReflectionHelpers.GetFieldGetter(
|
|
45
|
+
typeof(TestStruct).GetField(nameof(TestStruct.intValue))
|
|
46
|
+
);
|
|
47
|
+
Assert.AreEqual(testStruct.intValue, structGetter(testStruct));
|
|
48
|
+
for (int i = 0; i < NumTries; ++i)
|
|
49
|
+
{
|
|
50
|
+
testStruct.intValue = _random.Next(int.MinValue, int.MaxValue);
|
|
51
|
+
Assert.AreEqual(testStruct.intValue, structGetter(testStruct));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
[Test]
|
|
56
|
+
public void GetFieldSetterClass()
|
|
57
|
+
{
|
|
58
|
+
TestClass testClass = new();
|
|
59
|
+
Action<object, object> structSetter = ReflectionHelpers.GetFieldSetter(
|
|
60
|
+
typeof(TestClass).GetField(nameof(TestClass.intValue))
|
|
61
|
+
);
|
|
62
|
+
for (int i = 0; i < NumTries; ++i)
|
|
63
|
+
{
|
|
64
|
+
int expected = _random.Next(int.MinValue, int.MaxValue);
|
|
65
|
+
structSetter(testClass, expected);
|
|
66
|
+
Assert.AreEqual(expected, testClass.intValue);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
[Test]
|
|
71
|
+
public void GetFieldSetterStruct()
|
|
72
|
+
{
|
|
73
|
+
// Need boxing
|
|
74
|
+
object testStruct = new TestStruct();
|
|
75
|
+
Action<object, object> structSetter = ReflectionHelpers.GetFieldSetter(
|
|
76
|
+
typeof(TestStruct).GetField(nameof(TestStruct.intValue))
|
|
77
|
+
);
|
|
78
|
+
for (int i = 0; i < NumTries; ++i)
|
|
79
|
+
{
|
|
80
|
+
int expected = _random.Next(int.MinValue, int.MaxValue);
|
|
81
|
+
structSetter(testStruct, expected);
|
|
82
|
+
Assert.AreEqual(expected, ((TestStruct)testStruct).intValue);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
[Test]
|
|
87
|
+
public void GetFieldSetterClassGeneric()
|
|
88
|
+
{
|
|
89
|
+
TestClass testClass = new();
|
|
90
|
+
FieldSetter<TestClass, int> structSetter = ReflectionHelpers.GetFieldSetter<
|
|
91
|
+
TestClass,
|
|
92
|
+
int
|
|
93
|
+
>(typeof(TestClass).GetField(nameof(TestClass.intValue)));
|
|
94
|
+
for (int i = 0; i < NumTries; ++i)
|
|
95
|
+
{
|
|
96
|
+
int expected = _random.Next(int.MinValue, int.MaxValue);
|
|
97
|
+
structSetter(ref testClass, expected);
|
|
98
|
+
Assert.AreEqual(expected, testClass.intValue);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[Test]
|
|
103
|
+
public void GetFieldSetterStructGeneric()
|
|
104
|
+
{
|
|
105
|
+
TestStruct testStruct = new();
|
|
106
|
+
FieldSetter<TestStruct, int> structSetter = ReflectionHelpers.GetFieldSetter<
|
|
107
|
+
TestStruct,
|
|
108
|
+
int
|
|
109
|
+
>(typeof(TestStruct).GetField(nameof(TestStruct.intValue)));
|
|
110
|
+
for (int i = 0; i < NumTries; ++i)
|
|
111
|
+
{
|
|
112
|
+
int expected = _random.Next(int.MinValue, int.MaxValue);
|
|
113
|
+
structSetter(ref testStruct, expected);
|
|
114
|
+
Assert.AreEqual(expected, testStruct.intValue);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[Test]
|
|
119
|
+
public void ArrayCreator()
|
|
120
|
+
{
|
|
121
|
+
for (int i = 0; i < NumTries; ++i)
|
|
122
|
+
{
|
|
123
|
+
int count = _random.Next(1_000);
|
|
124
|
+
Array created = ReflectionHelpers.CreateArray(typeof(int), count);
|
|
125
|
+
Assert.AreEqual(count, created.Length);
|
|
126
|
+
Assert.IsTrue(created is int[]);
|
|
127
|
+
int[] typed = (int[])created;
|
|
128
|
+
Assert.AreEqual(count, typed.Length);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
[Test]
|
|
133
|
+
public void ListCreator()
|
|
134
|
+
{
|
|
135
|
+
for (int i = 0; i < NumTries; ++i)
|
|
136
|
+
{
|
|
137
|
+
IList created = ReflectionHelpers.CreateList(typeof(int));
|
|
138
|
+
Assert.AreEqual(0, created.Count);
|
|
139
|
+
Assert.IsTrue(created is List<int>);
|
|
140
|
+
List<int> typedCreated = (List<int>)created;
|
|
141
|
+
int count = _random.Next(50);
|
|
142
|
+
List<int> expected = new();
|
|
143
|
+
for (int j = 0; j < count; ++j)
|
|
144
|
+
{
|
|
145
|
+
int element = _random.Next();
|
|
146
|
+
created.Add(element);
|
|
147
|
+
expected.Add(element);
|
|
148
|
+
Assert.AreEqual(j + 1, created.Count);
|
|
149
|
+
Assert.That(expected, Is.EqualTo(typedCreated));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
[Test]
|
|
155
|
+
public void ListWithSizeCreator()
|
|
156
|
+
{
|
|
157
|
+
for (int i = 0; i < NumTries; ++i)
|
|
158
|
+
{
|
|
159
|
+
int capacity = _random.Next(1_000);
|
|
160
|
+
IList created = ReflectionHelpers.CreateList(typeof(int), capacity);
|
|
161
|
+
Assert.AreEqual(0, created.Count);
|
|
162
|
+
Assert.IsTrue(created is List<int>);
|
|
163
|
+
List<int> typedCreated = (List<int>)created;
|
|
164
|
+
Assert.AreEqual(capacity, typedCreated.Capacity);
|
|
165
|
+
|
|
166
|
+
int count = _random.Next(50);
|
|
167
|
+
List<int> expected = new();
|
|
168
|
+
for (int j = 0; j < count; ++j)
|
|
169
|
+
{
|
|
170
|
+
int element = _random.Next();
|
|
171
|
+
created.Add(element);
|
|
172
|
+
expected.Add(element);
|
|
173
|
+
Assert.AreEqual(j + 1, created.Count);
|
|
174
|
+
Assert.That(expected, Is.EqualTo(typedCreated));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
using System;
|
|
4
4
|
using System.Diagnostics;
|
|
5
5
|
using Components;
|
|
6
|
+
using Components.UnityHelpers.Tests.Components;
|
|
6
7
|
using Core.Attributes;
|
|
7
8
|
using NUnit.Framework;
|
|
8
9
|
using UnityEngine;
|
|
@@ -10,12 +11,13 @@
|
|
|
10
11
|
public sealed class RelationComponentPerformanceTests
|
|
11
12
|
{
|
|
12
13
|
[Test]
|
|
13
|
-
public void
|
|
14
|
+
public void RelationalPerformanceComplexTest()
|
|
14
15
|
{
|
|
15
16
|
int count = 0;
|
|
16
17
|
|
|
17
|
-
GameObject go = new("Test", typeof(
|
|
18
|
-
|
|
18
|
+
GameObject go = new("Test", typeof(RelationalComponentTesterComplex));
|
|
19
|
+
RelationalComponentTesterComplex tester =
|
|
20
|
+
go.GetComponent<RelationalComponentTesterComplex>();
|
|
19
21
|
// Pre-warm
|
|
20
22
|
tester.AssignRelationalComponents();
|
|
21
23
|
|
|
@@ -33,5 +35,27 @@
|
|
|
33
35
|
Assert.AreNotEqual(0, tester._parentColliders.Length);
|
|
34
36
|
Assert.AreNotEqual(0, tester._siblingColliders.Length);
|
|
35
37
|
}
|
|
38
|
+
|
|
39
|
+
[Test]
|
|
40
|
+
public void RelationalPerformanceSimpleTest()
|
|
41
|
+
{
|
|
42
|
+
int count = 0;
|
|
43
|
+
|
|
44
|
+
GameObject go = new("Test", typeof(RelationalComponentTesterSimple));
|
|
45
|
+
RelationalComponentTesterSimple tester =
|
|
46
|
+
go.GetComponent<RelationalComponentTesterSimple>();
|
|
47
|
+
// Pre-warm
|
|
48
|
+
tester.AssignRelationalComponents();
|
|
49
|
+
|
|
50
|
+
TimeSpan timeout = TimeSpan.FromSeconds(10);
|
|
51
|
+
Stopwatch timer = Stopwatch.StartNew();
|
|
52
|
+
do
|
|
53
|
+
{
|
|
54
|
+
tester.AssignRelationalComponents();
|
|
55
|
+
++count;
|
|
56
|
+
} while (timer.Elapsed < timeout);
|
|
57
|
+
|
|
58
|
+
UnityEngine.Debug.Log($"Averaged {count / timeout.TotalSeconds} operations / second.");
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
}
|
package/package.json
CHANGED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
name: Export and Release Unity Package
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
workflow_run:
|
|
5
|
-
workflows: ["Unity Tests"]
|
|
6
|
-
types:
|
|
7
|
-
- completed
|
|
8
|
-
workflow_dispatch:
|
|
9
|
-
inputs:
|
|
10
|
-
logLevel:
|
|
11
|
-
description: 'Log level'
|
|
12
|
-
required: true
|
|
13
|
-
default: 'warning'
|
|
14
|
-
environment:
|
|
15
|
-
description: 'Environment to deploy'
|
|
16
|
-
required: false
|
|
17
|
-
default: 'staging'
|
|
18
|
-
|
|
19
|
-
env:
|
|
20
|
-
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
|
21
|
-
|
|
22
|
-
jobs:
|
|
23
|
-
package_unity:
|
|
24
|
-
runs-on: ubuntu-latest
|
|
25
|
-
|
|
26
|
-
steps:
|
|
27
|
-
- name: Checkout Repository
|
|
28
|
-
uses: actions/checkout@v4
|
|
29
|
-
with:
|
|
30
|
-
fetch-depth: 0 # Ensure full commit history for version comparison
|
|
31
|
-
|
|
32
|
-
- name: Set up Node.js
|
|
33
|
-
uses: actions/setup-node@v4
|
|
34
|
-
with:
|
|
35
|
-
node-version: 18
|
|
36
|
-
|
|
37
|
-
- name: Check if version changed
|
|
38
|
-
id: version_check
|
|
39
|
-
run: |
|
|
40
|
-
PREV_VERSION=$(git show HEAD~1:package.json | jq -r '.version' || echo "0.0.0")
|
|
41
|
-
NEW_VERSION=$(jq -r '.version' package.json)
|
|
42
|
-
echo "Previous version: $PREV_VERSION"
|
|
43
|
-
echo "New version: $NEW_VERSION"
|
|
44
|
-
|
|
45
|
-
if [ "$PREV_VERSION" != "$NEW_VERSION" ]; then
|
|
46
|
-
echo "Version changed, proceeding..."
|
|
47
|
-
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
|
|
48
|
-
echo "should_build=true" >> $GITHUB_ENV
|
|
49
|
-
|
|
50
|
-
# Check for pre-release versions
|
|
51
|
-
if [[ "$NEW_VERSION" == *"rc"* ]]; then
|
|
52
|
-
echo "This is a pre-release (next tag)."
|
|
53
|
-
echo "IS_PRERELEASE=true" >> $GITHUB_ENV
|
|
54
|
-
else
|
|
55
|
-
echo "This is a stable release."
|
|
56
|
-
echo "IS_PRERELEASE=false" >> $GITHUB_ENV
|
|
57
|
-
fi
|
|
58
|
-
else
|
|
59
|
-
echo "Version did not change, skipping..."
|
|
60
|
-
echo "should_build=false" >> $GITHUB_ENV
|
|
61
|
-
fi
|
|
62
|
-
|
|
63
|
-
- name: Set up Unity
|
|
64
|
-
if: env.should_build == 'true'
|
|
65
|
-
uses: game-ci/unity-builder@v4
|
|
66
|
-
env:
|
|
67
|
-
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
|
68
|
-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
|
|
69
|
-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
|
|
70
|
-
with:
|
|
71
|
-
unityVersion: 2022.3.5f1
|
|
72
|
-
targetPlatform: StandaloneLinux64
|
|
73
|
-
buildMethod: BuildScript.BuildLinux
|
|
74
|
-
projectPath: .
|
|
75
|
-
|
|
76
|
-
- name: Export Unity Package
|
|
77
|
-
if: env.should_build == 'true'
|
|
78
|
-
run: |
|
|
79
|
-
EXPORT_DIR="UnityHelpers"
|
|
80
|
-
PACKAGE_NAME="WallstopStudios.UnityHelpers.unitypackage"
|
|
81
|
-
|
|
82
|
-
mkdir -p $EXPORT_DIR
|
|
83
|
-
|
|
84
|
-
echo "Exporting package: $EXPORT_DIR/$PACKAGE_NAME"
|
|
85
|
-
|
|
86
|
-
/opt/unity/Editor/Unity \
|
|
87
|
-
-batchmode -quit \
|
|
88
|
-
-projectPath "$(pwd)" \
|
|
89
|
-
-exportPackage "Assets" "$EXPORT_DIR/$PACKAGE_NAME"
|
|
90
|
-
|
|
91
|
-
echo "PACKAGE_PATH=$EXPORT_DIR/$PACKAGE_NAME" >> $GITHUB_ENV
|
|
92
|
-
|
|
93
|
-
- name: Create GitHub Release
|
|
94
|
-
if: env.should_build == 'true'
|
|
95
|
-
id: create_release
|
|
96
|
-
uses: softprops/action-gh-release@v2
|
|
97
|
-
with:
|
|
98
|
-
tag_name: v${{ env.NEW_VERSION }}
|
|
99
|
-
release_name: "Unity Helpers v${{ env.NEW_VERSION }}"
|
|
100
|
-
body: "Automatically generated release for version ${{ env.NEW_VERSION }}."
|
|
101
|
-
draft: false
|
|
102
|
-
prerelease: ${{ env.IS_PRERELEASE == 'true' }}
|
|
103
|
-
files: ${{ env.PACKAGE_PATH }}
|
|
104
|
-
env:
|
|
105
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
package/Editor/BuildScript.cs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
namespace UnityHelpers.Editor
|
|
2
|
-
{
|
|
3
|
-
#if UNITY_EDITOR
|
|
4
|
-
using UnityEditor;
|
|
5
|
-
using System.IO;
|
|
6
|
-
using UnityEngine;
|
|
7
|
-
|
|
8
|
-
// Needed for build
|
|
9
|
-
public static class BuildScript
|
|
10
|
-
{
|
|
11
|
-
[MenuItem("Build/Build Unity Package")]
|
|
12
|
-
public static void BuildLinux()
|
|
13
|
-
{
|
|
14
|
-
Debug.Log($"Project Path: {Application.dataPath}");
|
|
15
|
-
|
|
16
|
-
string[] scenes = { "Editor/Scenes/SampleScene.unity" };
|
|
17
|
-
|
|
18
|
-
const string buildPath = "Builds/UnityHelpers";
|
|
19
|
-
if (!Directory.Exists(buildPath))
|
|
20
|
-
{
|
|
21
|
-
Directory.CreateDirectory(buildPath);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
BuildPipeline.BuildPlayer(
|
|
25
|
-
scenes,
|
|
26
|
-
buildPath + "/UnityHelpers.x86_64",
|
|
27
|
-
BuildTarget.StandaloneLinux64,
|
|
28
|
-
BuildOptions.None
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
#endif
|
|
33
|
-
}
|