com.wallstop-studios.unity-helpers 2.0.4 → 2.1.1
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/Docs/DATA_STRUCTURES.md +7 -7
- package/Docs/EFFECTS_SYSTEM.md +836 -8
- package/Docs/EFFECTS_SYSTEM_TUTORIAL.md +77 -18
- package/Docs/HULLS.md +2 -2
- package/Docs/ILIST_SORTING_PERFORMANCE.md +92 -0
- package/Docs/ILIST_SORTING_PERFORMANCE.md.meta +7 -0
- package/Docs/INDEX.md +10 -1
- package/Docs/Images/random_generators.svg +7 -7
- package/Docs/RANDOM_PERFORMANCE.md +18 -15
- package/Docs/REFLECTION_HELPERS.md +1 -1
- package/Docs/RELATIONAL_COMPONENTS.md +51 -6
- package/Docs/SERIALIZATION.md +1 -1
- package/Docs/SINGLETONS.md +2 -2
- package/Docs/SPATIAL_TREES_2D_GUIDE.md +3 -3
- package/Docs/SPATIAL_TREES_3D_GUIDE.md +3 -3
- package/Docs/SPATIAL_TREE_2D_PERFORMANCE.md +64 -64
- package/Docs/SPATIAL_TREE_3D_PERFORMANCE.md +64 -64
- package/Docs/SPATIAL_TREE_SEMANTICS.md +7 -7
- package/Editor/Core/Helper/AnimationEventHelpers.cs +1 -1
- package/Editor/CustomDrawers/WShowIfPropertyDrawer.cs +131 -41
- package/Editor/Utils/ScriptableObjectSingletonCreator.cs +175 -18
- package/README.md +42 -18
- package/Runtime/Core/Extension/IListExtensions.cs +720 -12
- package/Runtime/Core/Helper/UnityMainThreadDispatcher.cs +2 -3
- package/Runtime/Core/Random/AbstractRandom.cs +52 -5
- package/Runtime/Core/Random/DotNetRandom.cs +3 -3
- package/Runtime/Core/Random/FlurryBurstRandom.cs +285 -0
- package/Runtime/Core/Random/FlurryBurstRandom.cs.meta +3 -0
- package/Runtime/Core/Random/IllusionFlow.cs +3 -3
- package/Runtime/Core/Random/LinearCongruentialGenerator.cs +3 -3
- package/Runtime/Core/Random/PcgRandom.cs +6 -6
- package/Runtime/Core/Random/PhotonSpinRandom.cs +387 -0
- package/Runtime/Core/Random/PhotonSpinRandom.cs.meta +3 -0
- package/Runtime/Core/Random/RomuDuo.cs +3 -3
- package/Runtime/Core/Random/SplitMix64.cs +3 -3
- package/Runtime/Core/Random/SquirrelRandom.cs +6 -4
- package/Runtime/Core/Random/StormDropRandom.cs +271 -0
- package/Runtime/Core/Random/StormDropRandom.cs.meta +3 -0
- package/Runtime/Core/Random/UnityRandom.cs +3 -3
- package/Runtime/Core/Random/WyRandom.cs +6 -4
- package/Runtime/Core/Random/XorShiftRandom.cs +3 -3
- package/Runtime/Core/Random/XoroShiroRandom.cs +3 -3
- package/Runtime/Tags/Attribute.cs +144 -24
- package/Runtime/Tags/AttributeEffect.cs +119 -16
- package/Runtime/Tags/AttributeMetadataCache.cs +312 -3
- package/Runtime/Tags/AttributeModification.cs +59 -29
- package/Runtime/Tags/AttributesComponent.cs +20 -0
- package/Runtime/Tags/EffectBehavior.cs +171 -0
- package/Runtime/Tags/EffectBehavior.cs.meta +4 -0
- package/Runtime/Tags/EffectHandle.cs +5 -0
- package/Runtime/Tags/EffectHandler.cs +385 -39
- package/Runtime/Tags/EffectStackKey.cs +79 -0
- package/Runtime/Tags/EffectStackKey.cs.meta +4 -0
- package/Runtime/Tags/PeriodicEffectDefinition.cs +102 -0
- package/Runtime/Tags/PeriodicEffectDefinition.cs.meta +4 -0
- package/Runtime/Tags/PeriodicEffectRuntimeState.cs +40 -0
- package/Runtime/Tags/PeriodicEffectRuntimeState.cs.meta +4 -0
- package/Samples~/DI - Zenject/README.md +0 -2
- package/Tests/Editor/Attributes/WShowIfPropertyDrawerTests.cs +285 -0
- package/Tests/Editor/Attributes/WShowIfPropertyDrawerTests.cs.meta +11 -0
- package/Tests/Editor/Core/Attributes/RelationalComponentAssignerTests.cs +2 -2
- package/Tests/Editor/Tags/AttributeMetadataCacheTests.cs +192 -0
- package/Tests/Editor/Tags/AttributeMetadataCacheTests.cs.meta +11 -0
- package/{node_modules.meta → Tests/Editor/Tags.meta} +1 -1
- package/Tests/Editor/Utils/ScriptableObjectSingletonTests.cs +41 -0
- package/Tests/Runtime/Extensions/IListExtensionTests.cs +187 -1
- package/Tests/Runtime/Helper/ObjectsTests.cs +3 -3
- package/Tests/Runtime/Integrations/Reflex/RelationalComponentsReflexTests.cs +2 -2
- package/Tests/Runtime/Performance/IListSortingPerformanceTests.cs +346 -0
- package/Tests/Runtime/Performance/IListSortingPerformanceTests.cs.meta +11 -0
- package/Tests/Runtime/Performance/RandomPerformanceTests.cs +3 -0
- package/Tests/Runtime/Random/FlurryBurstRandomTests.cs +12 -0
- package/Tests/Runtime/Random/FlurryBurstRandomTests.cs.meta +3 -0
- package/Tests/Runtime/Random/PhotonSpinRandomTests.cs +12 -0
- package/Tests/Runtime/Random/PhotonSpinRandomTests.cs.meta +3 -0
- package/Tests/Runtime/Random/RandomProtoSerializationTests.cs +14 -0
- package/Tests/Runtime/Random/RandomTestBase.cs +39 -4
- package/Tests/Runtime/Random/StormDropRandomTests.cs +12 -0
- package/Tests/Runtime/Random/StormDropRandomTests.cs.meta +3 -0
- package/Tests/Runtime/Serialization/JsonSerializationTest.cs +4 -3
- package/Tests/Runtime/Serialization/ProtoInterfaceResolutionEdgeTests.cs +2 -2
- package/Tests/Runtime/Serialization/ProtoRootRegistrationTests.cs +1 -1
- package/Tests/Runtime/Serialization/ProtoSerializeBehaviorTests.cs +1 -1
- package/Tests/Runtime/Tags/AttributeEffectTests.cs +135 -0
- package/Tests/Runtime/Tags/AttributeEffectTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/AttributeModificationTests.cs +137 -0
- package/Tests/Runtime/Tags/AttributeTests.cs +192 -0
- package/Tests/Runtime/Tags/AttributeTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/EffectBehaviorTests.cs +184 -0
- package/Tests/Runtime/Tags/EffectBehaviorTests.cs.meta +3 -0
- package/Tests/Runtime/Tags/EffectHandlerTests.cs +618 -0
- package/Tests/Runtime/Tags/Helpers/RecordingEffectBehavior.cs +89 -0
- package/Tests/Runtime/Tags/Helpers/RecordingEffectBehavior.cs.meta +4 -0
- package/Tests/Runtime/Tags/PeriodicEffectDefinitionSerializationTests.cs +92 -0
- package/Tests/Runtime/Tags/PeriodicEffectDefinitionSerializationTests.cs.meta +3 -0
- package/package.json +1 -1
- package/scripts/lint-doc-links.ps1 +156 -11
- package/Tests/Runtime/Tags/AttributeDataTests.cs +0 -312
- /package/Tests/Runtime/Tags/{AttributeDataTests.cs.meta → AttributeModificationTests.cs.meta} +0 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
namespace WallstopStudios.UnityHelpers.Tests.Tags
|
|
2
|
+
{
|
|
3
|
+
using System.Collections;
|
|
4
|
+
using NUnit.Framework;
|
|
5
|
+
using UnityEngine;
|
|
6
|
+
using UnityEngine.TestTools;
|
|
7
|
+
using WallstopStudios.UnityHelpers.Tags;
|
|
8
|
+
using WallstopStudios.UnityHelpers.Tests.Tags.Helpers;
|
|
9
|
+
|
|
10
|
+
[TestFixture]
|
|
11
|
+
public sealed class EffectBehaviorTests : TagsTestBase
|
|
12
|
+
{
|
|
13
|
+
[SetUp]
|
|
14
|
+
public void SetUp()
|
|
15
|
+
{
|
|
16
|
+
ResetEffectHandleId();
|
|
17
|
+
RecordingEffectBehavior.Reset();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
[UnityTest]
|
|
21
|
+
public IEnumerator LifecycleCallbacksProvideContextData()
|
|
22
|
+
{
|
|
23
|
+
(GameObject entity, EffectHandler handler, _, _) = CreateEntity();
|
|
24
|
+
|
|
25
|
+
PeriodicEffectDefinition periodicDefinition = new()
|
|
26
|
+
{
|
|
27
|
+
name = "Pulse",
|
|
28
|
+
initialDelay = 0f,
|
|
29
|
+
interval = 0.05f,
|
|
30
|
+
maxTicks = 1,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
AttributeEffect effect = CreateEffect(
|
|
34
|
+
"Lifecycle",
|
|
35
|
+
e =>
|
|
36
|
+
{
|
|
37
|
+
e.periodicEffects.Add(periodicDefinition);
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
RecordingEffectBehavior behavior = Track(
|
|
42
|
+
ScriptableObject.CreateInstance<RecordingEffectBehavior>()
|
|
43
|
+
);
|
|
44
|
+
effect.behaviors.Add(behavior);
|
|
45
|
+
|
|
46
|
+
EffectHandle handle = handler.ApplyEffect(effect).Value;
|
|
47
|
+
Assert.AreEqual(1, RecordingEffectBehavior.ApplyCount);
|
|
48
|
+
Assert.AreEqual(
|
|
49
|
+
1,
|
|
50
|
+
RecordingEffectBehavior.ApplyContexts.Count,
|
|
51
|
+
"OnApply should fire immediately."
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
yield return null;
|
|
55
|
+
yield return null;
|
|
56
|
+
|
|
57
|
+
Assert.IsNotEmpty(
|
|
58
|
+
RecordingEffectBehavior.TickContexts,
|
|
59
|
+
"OnTick should run after Update."
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
yield return new WaitForSeconds(0.08f);
|
|
63
|
+
|
|
64
|
+
Assert.AreEqual(
|
|
65
|
+
1,
|
|
66
|
+
RecordingEffectBehavior.PeriodicInvocations.Count,
|
|
67
|
+
"Expected one periodic tick."
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
int removeCountBefore = RecordingEffectBehavior.RemoveCount;
|
|
71
|
+
handler.RemoveEffect(handle);
|
|
72
|
+
Assert.AreEqual(removeCountBefore + 1, RecordingEffectBehavior.RemoveCount);
|
|
73
|
+
Assert.AreEqual(
|
|
74
|
+
1,
|
|
75
|
+
RecordingEffectBehavior.RemoveContexts.Count,
|
|
76
|
+
"OnRemove should fire once."
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
EffectBehaviorContext applyContext = RecordingEffectBehavior.ApplyContexts[0];
|
|
80
|
+
Assert.AreSame(handler, applyContext.handler);
|
|
81
|
+
Assert.AreSame(entity, applyContext.Target);
|
|
82
|
+
Assert.AreEqual(effect, applyContext.Effect);
|
|
83
|
+
Assert.AreEqual(0f, applyContext.deltaTime);
|
|
84
|
+
|
|
85
|
+
EffectBehaviorContext tickContext = RecordingEffectBehavior.TickContexts[0];
|
|
86
|
+
Assert.AreSame(handler, tickContext.handler);
|
|
87
|
+
Assert.AreSame(entity, tickContext.Target);
|
|
88
|
+
Assert.AreEqual(effect, tickContext.Effect);
|
|
89
|
+
Assert.Greater(tickContext.deltaTime, 0f);
|
|
90
|
+
|
|
91
|
+
RecordingEffectBehavior.PeriodicInvocation periodicInvocation =
|
|
92
|
+
RecordingEffectBehavior.PeriodicInvocations[0];
|
|
93
|
+
Assert.AreSame(handler, periodicInvocation.Context.handler);
|
|
94
|
+
Assert.AreSame(entity, periodicInvocation.Context.Target);
|
|
95
|
+
Assert.AreEqual(effect, periodicInvocation.Context.Effect);
|
|
96
|
+
Assert.Greater(periodicInvocation.Context.deltaTime, 0f);
|
|
97
|
+
Assert.AreSame(periodicDefinition, periodicInvocation.TickContext.definition);
|
|
98
|
+
Assert.AreEqual(1, periodicInvocation.TickContext.executedTicks);
|
|
99
|
+
Assert.GreaterOrEqual(periodicInvocation.TickContext.currentTime, 0f);
|
|
100
|
+
|
|
101
|
+
EffectBehaviorContext removeContext = RecordingEffectBehavior.RemoveContexts[0];
|
|
102
|
+
Assert.AreSame(handler, removeContext.handler);
|
|
103
|
+
Assert.AreSame(entity, removeContext.Target);
|
|
104
|
+
Assert.AreEqual(effect, removeContext.Effect);
|
|
105
|
+
Assert.AreEqual(0f, removeContext.deltaTime);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
[UnityTest]
|
|
109
|
+
public IEnumerator PeriodicTickContextTracksExecutedTicksAndTime()
|
|
110
|
+
{
|
|
111
|
+
(GameObject entity, EffectHandler handler, _, _) = CreateEntity();
|
|
112
|
+
|
|
113
|
+
PeriodicEffectDefinition periodicDefinition = new()
|
|
114
|
+
{
|
|
115
|
+
name = "Stacking Pulse",
|
|
116
|
+
initialDelay = 0f,
|
|
117
|
+
interval = 0.05f,
|
|
118
|
+
maxTicks = 3,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
AttributeEffect effect = CreateEffect(
|
|
122
|
+
"Periodic",
|
|
123
|
+
e =>
|
|
124
|
+
{
|
|
125
|
+
e.periodicEffects.Add(periodicDefinition);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
RecordingEffectBehavior behavior = Track(
|
|
130
|
+
ScriptableObject.CreateInstance<RecordingEffectBehavior>()
|
|
131
|
+
);
|
|
132
|
+
effect.behaviors.Add(behavior);
|
|
133
|
+
|
|
134
|
+
EffectHandle handle = handler.ApplyEffect(effect).Value;
|
|
135
|
+
|
|
136
|
+
yield return new WaitForSeconds(0.18f);
|
|
137
|
+
|
|
138
|
+
Assert.AreEqual(
|
|
139
|
+
3,
|
|
140
|
+
RecordingEffectBehavior.PeriodicInvocations.Count,
|
|
141
|
+
"Expected periodic callbacks for each executed tick."
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
for (int i = 0; i < RecordingEffectBehavior.PeriodicInvocations.Count; ++i)
|
|
145
|
+
{
|
|
146
|
+
RecordingEffectBehavior.PeriodicInvocation invocation =
|
|
147
|
+
RecordingEffectBehavior.PeriodicInvocations[i];
|
|
148
|
+
Assert.AreSame(periodicDefinition, invocation.TickContext.definition);
|
|
149
|
+
Assert.AreEqual(i + 1, invocation.TickContext.executedTicks);
|
|
150
|
+
Assert.Greater(invocation.Context.deltaTime, 0f);
|
|
151
|
+
|
|
152
|
+
if (i > 0)
|
|
153
|
+
{
|
|
154
|
+
float previousTime = RecordingEffectBehavior
|
|
155
|
+
.PeriodicInvocations[i - 1]
|
|
156
|
+
.TickContext
|
|
157
|
+
.currentTime;
|
|
158
|
+
Assert.GreaterOrEqual(invocation.TickContext.currentTime, previousTime);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
handler.RemoveEffect(handle);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private (
|
|
166
|
+
GameObject entity,
|
|
167
|
+
EffectHandler handler,
|
|
168
|
+
TestAttributesComponent attributes,
|
|
169
|
+
TagHandler tags
|
|
170
|
+
) CreateEntity()
|
|
171
|
+
{
|
|
172
|
+
GameObject entity = CreateTrackedGameObject(
|
|
173
|
+
"EffectBehaviorEntity",
|
|
174
|
+
typeof(TestAttributesComponent)
|
|
175
|
+
);
|
|
176
|
+
return (
|
|
177
|
+
entity,
|
|
178
|
+
entity.GetComponent<EffectHandler>(),
|
|
179
|
+
entity.GetComponent<TestAttributesComponent>(),
|
|
180
|
+
entity.GetComponent<TagHandler>()
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|