Skip to content

Commit 326bda6

Browse files
test: NetworkAnimator manual test updates for PR-2127 (#2205)
Fixes and additions to the NetworkAnimator manual tests.
1 parent 5da0247 commit 326bda6

File tree

9 files changed

+355
-65
lines changed

9 files changed

+355
-65
lines changed

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimatedCubeController.cs

Lines changed: 81 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace Tests.Manual.NetworkAnimatorTests
99
[RequireComponent(typeof(Animator))]
1010
public class AnimatedCubeController : NetworkBehaviour
1111
{
12-
public int TestIterations = 20;
1312
private Animator m_Animator;
1413
private bool m_Rotate;
1514
private NetworkAnimator m_NetworkAnimator;
@@ -30,12 +29,10 @@ private void DetermineNetworkAnimatorComponentType()
3029

3130
public override void OnNetworkSpawn()
3231
{
33-
if (HasAuthority())
34-
{
35-
enabled = false;
36-
}
37-
m_Animator = GetComponent<Animator>();
3832
DetermineNetworkAnimatorComponentType();
33+
34+
m_Animator = GetComponent<Animator>();
35+
3936
m_Rotate = m_Animator.GetBool("Rotate");
4037
}
4138

@@ -106,7 +103,7 @@ internal void PlayPulseAnimation()
106103
{
107104
if (!IsServer && IsOwner)
108105
{
109-
PlayPulseAnimationServerRpc(m_Rotate);
106+
m_NetworkAnimator.SetTrigger("Pulse");
110107
}
111108
else if (IsServer && IsOwner)
112109
{
@@ -119,7 +116,6 @@ internal void PlayPulseAnimation()
119116
}
120117
}
121118

122-
123119
private Coroutine m_TestAnimatorRoutine;
124120

125121
internal void TestAnimator(bool useNetworkAnimator = true)
@@ -133,24 +129,89 @@ internal void TestAnimator(bool useNetworkAnimator = true)
133129
}
134130
}
135131

136-
137132
private IEnumerator TestAnimatorRoutine()
138133
{
139-
var interations = 0;
140-
while (interations < TestIterations)
134+
var waitForSeconds = new WaitForSeconds(0.016f);
135+
var counter = 1.0f;
136+
Debug.Log("Linearly increase test:");
137+
while (counter < 100)
138+
{
139+
m_Animator.SetFloat("TestFloat", counter);
140+
m_Animator.SetInteger("TestInt", (int)counter);
141+
counter++;
142+
yield return waitForSeconds;
143+
}
144+
Debug.Log("Random value assignment test:");
145+
counter = 0.0f;
146+
while (counter < 100)
147+
{
148+
m_Animator.SetFloat("TestFloat", UnityEngine.Random.Range(0.0f, 100.0f));
149+
m_Animator.SetInteger("TestInt", UnityEngine.Random.Range(0, 100));
150+
counter++;
151+
yield return waitForSeconds;
152+
}
153+
StopCoroutine(m_TestAnimatorRoutine);
154+
m_TestAnimatorRoutine = null;
155+
}
156+
157+
private int m_TestIntValue;
158+
private float m_TestFloatValue;
159+
160+
private void DisplayTestIntValueIfChanged()
161+
{
162+
var testIntValue = m_Animator.GetInteger("TestInt");
163+
if (m_TestIntValue != testIntValue)
141164
{
142-
var counter = 1.0f;
143-
m_NetworkAnimator.SetTrigger("TestTrigger");
144-
while (counter < 100)
165+
m_TestIntValue = testIntValue;
166+
Debug.Log($"[{name}]TestInt value changed to = {m_TestIntValue}");
167+
}
168+
var testFloatValue = m_Animator.GetInteger("TestFloat");
169+
if (m_TestFloatValue != testFloatValue)
170+
{
171+
m_TestFloatValue = testFloatValue;
172+
Debug.Log($"[{name}]TestFloat value changed to = {m_TestIntValue}");
173+
}
174+
}
175+
176+
private void LateUpdate()
177+
{
178+
179+
if (!IsSpawned || !IsOwner)
180+
{
181+
if (!IsOwner && IsSpawned)
145182
{
146-
m_Animator.SetFloat("TestFloat", counter);
147-
m_Animator.SetInteger("TestInt", (int)counter);
148-
counter++;
149-
yield return null;
183+
DisplayTestIntValueIfChanged();
184+
return;
150185
}
151-
interations++;
186+
187+
return;
188+
}
189+
190+
DisplayTestIntValueIfChanged();
191+
192+
// Rotates the cube
193+
if (Input.GetKeyDown(KeyCode.C))
194+
{
195+
ToggleRotateAnimation();
196+
}
197+
198+
// Pulse animation (scale down and up slowly)
199+
if (Input.GetKeyDown(KeyCode.Space))
200+
{
201+
PlayPulseAnimation();
202+
}
203+
204+
// Test changing Animator parameters over time
205+
if (Input.GetKeyDown(KeyCode.T))
206+
{
207+
TestAnimator();
208+
}
209+
210+
if (Input.GetKeyDown(KeyCode.R))
211+
{
212+
Debug.Log($"[{name}] TestInt value = {m_TestIntValue}");
213+
Debug.Log($"[{name}] TestInt value = {m_TestIntValue}");
152214
}
153-
yield return null;
154215
}
155216
}
156217
}

testproject/Assets/Tests/Manual/NetworkAnimatorTests/AnimationUserInput.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private void Start()
1717
// Update is called once per frame
1818
private void LateUpdate()
1919
{
20-
if (!IsSpawned || !IsOwner)
20+
if (!IsSpawned)
2121
{
2222
return;
2323
}

testproject/Assets/Tests/Manual/NetworkAnimatorTests/CubeAnimatorController.controller

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ AnimatorStateTransition:
9595
m_Mute: 0
9696
m_IsExit: 0
9797
serializedVersion: 3
98-
m_TransitionDuration: 0.3220486
98+
m_TransitionDuration: 2.2832582
9999
m_TransitionOffset: 0
100-
m_ExitTime: 0.8417445
100+
m_ExitTime: 0.6903777
101101
m_HasExitTime: 1
102102
m_HasFixedDuration: 1
103103
m_InterruptionSource: 0
@@ -128,6 +128,28 @@ AnimatorStateTransition:
128128
m_InterruptionSource: 0
129129
m_OrderedInterruption: 1
130130
m_CanTransitionToSelf: 1
131+
--- !u!1101 &-4455521266437619866
132+
AnimatorStateTransition:
133+
m_ObjectHideFlags: 1
134+
m_CorrespondingSourceObject: {fileID: 0}
135+
m_PrefabInstance: {fileID: 0}
136+
m_PrefabAsset: {fileID: 0}
137+
m_Name:
138+
m_Conditions: []
139+
m_DstStateMachine: {fileID: 0}
140+
m_DstState: {fileID: -1676030328622575462}
141+
m_Solo: 0
142+
m_Mute: 0
143+
m_IsExit: 0
144+
serializedVersion: 3
145+
m_TransitionDuration: 0.25
146+
m_TransitionOffset: 0
147+
m_ExitTime: 0.986124
148+
m_HasExitTime: 1
149+
m_HasFixedDuration: 1
150+
m_InterruptionSource: 0
151+
m_OrderedInterruption: 1
152+
m_CanTransitionToSelf: 1
131153
--- !u!1101 &-4282378417640754704
132154
AnimatorStateTransition:
133155
m_ObjectHideFlags: 1
@@ -203,6 +225,31 @@ AnimatorStateTransition:
203225
m_InterruptionSource: 0
204226
m_OrderedInterruption: 1
205227
m_CanTransitionToSelf: 1
228+
--- !u!1101 &-2947710236483485956
229+
AnimatorStateTransition:
230+
m_ObjectHideFlags: 1
231+
m_CorrespondingSourceObject: {fileID: 0}
232+
m_PrefabInstance: {fileID: 0}
233+
m_PrefabAsset: {fileID: 0}
234+
m_Name:
235+
m_Conditions:
236+
- m_ConditionMode: 1
237+
m_ConditionEvent: TestTrigger
238+
m_EventTreshold: 0
239+
m_DstStateMachine: {fileID: 0}
240+
m_DstState: {fileID: -1603678049383302394}
241+
m_Solo: 0
242+
m_Mute: 0
243+
m_IsExit: 0
244+
serializedVersion: 3
245+
m_TransitionDuration: 0.25
246+
m_TransitionOffset: 0
247+
m_ExitTime: 0.75
248+
m_HasExitTime: 1
249+
m_HasFixedDuration: 1
250+
m_InterruptionSource: 0
251+
m_OrderedInterruption: 1
252+
m_CanTransitionToSelf: 1
206253
--- !u!1101 &-2547562858931433901
207254
AnimatorStateTransition:
208255
m_ObjectHideFlags: 1
@@ -253,6 +300,7 @@ AnimatorState:
253300
m_Transitions:
254301
- {fileID: -4282378417640754704}
255302
- {fileID: 1678733063235620591}
303+
- {fileID: -2947710236483485956}
256304
m_StateMachineBehaviours:
257305
- {fileID: 6706570197837314945}
258306
m_Position: {x: 50, y: 50, z: 0}
@@ -297,6 +345,33 @@ AnimatorState:
297345
m_MirrorParameter:
298346
m_CycleOffsetParameter:
299347
m_TimeParameter:
348+
--- !u!1102 &-1603678049383302394
349+
AnimatorState:
350+
serializedVersion: 6
351+
m_ObjectHideFlags: 1
352+
m_CorrespondingSourceObject: {fileID: 0}
353+
m_PrefabInstance: {fileID: 0}
354+
m_PrefabAsset: {fileID: 0}
355+
m_Name: TriggerTest2
356+
m_Speed: 1
357+
m_CycleOffset: 0
358+
m_Transitions:
359+
- {fileID: -4455521266437619866}
360+
m_StateMachineBehaviours: []
361+
m_Position: {x: 50, y: 50, z: 0}
362+
m_IKOnFeet: 0
363+
m_WriteDefaultValues: 1
364+
m_Mirror: 0
365+
m_SpeedParameterActive: 0
366+
m_MirrorParameterActive: 0
367+
m_CycleOffsetParameterActive: 0
368+
m_TimeParameterActive: 0
369+
m_Motion: {fileID: 7400000, guid: 52bc8e8008543df4594fd2f9a1b9d424, type: 2}
370+
m_Tag:
371+
m_SpeedParameter:
372+
m_MirrorParameter:
373+
m_CycleOffsetParameter:
374+
m_TimeParameter:
300375
--- !u!114 &-1261272140589342921
301376
MonoBehaviour:
302377
m_ObjectHideFlags: 1
@@ -366,7 +441,10 @@ AnimatorStateMachine:
366441
m_Position: {x: 290, y: -150, z: 0}
367442
- serializedVersion: 1
368443
m_State: {fileID: 2733578584814225138}
369-
m_Position: {x: 290, y: 180, z: 0}
444+
m_Position: {x: 50, y: 190, z: 0}
445+
- serializedVersion: 1
446+
m_State: {fileID: -1603678049383302394}
447+
m_Position: {x: 440, y: 190, z: 0}
370448
m_ChildStateMachines: []
371449
m_AnyStateTransitions: []
372450
m_EntryTransitions: []
@@ -644,7 +722,7 @@ AnimatorState:
644722
m_PrefabInstance: {fileID: 0}
645723
m_PrefabAsset: {fileID: 0}
646724
m_Name: Pulse
647-
m_Speed: 0.25
725+
m_Speed: 0.1
648726
m_CycleOffset: 0
649727
m_Transitions:
650728
- {fileID: 1830534497079063084}

testproject/Assets/Tests/Manual/NetworkAnimatorTests/Cube_Pulse.anim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ AnimationClip:
2929
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
3030
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
3131
- serializedVersion: 3
32-
time: 0.2
32+
time: 0.5
3333
value: {x: 3, y: 3, z: 3}
3434
inSlope: {x: 0, y: 0, z: 0}
3535
outSlope: {x: 0, y: 0, z: 0}
@@ -38,7 +38,7 @@ AnimationClip:
3838
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
3939
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
4040
- serializedVersion: 3
41-
time: 0.4
41+
time: 1
4242
value: {x: 1, y: 1, z: 1}
4343
inSlope: {x: 0, y: 0, z: 0}
4444
outSlope: {x: 0, y: 0, z: 0}
@@ -95,7 +95,7 @@ AnimationClip:
9595
m_AdditiveReferencePoseClip: {fileID: 0}
9696
m_AdditiveReferencePoseTime: 0
9797
m_StartTime: 0
98-
m_StopTime: 0.4
98+
m_StopTime: 1
9999
m_OrientationOffsetY: 0
100100
m_Level: 0
101101
m_CycleOffset: 0
@@ -124,7 +124,7 @@ AnimationClip:
124124
inWeight: 0.33333334
125125
outWeight: 0.33333334
126126
- serializedVersion: 3
127-
time: 0.2
127+
time: 0.5
128128
value: 3
129129
inSlope: 0
130130
outSlope: 0
@@ -133,7 +133,7 @@ AnimationClip:
133133
inWeight: 0.33333334
134134
outWeight: 0.33333334
135135
- serializedVersion: 3
136-
time: 0.4
136+
time: 1
137137
value: 1
138138
inSlope: 0
139139
outSlope: 0
@@ -161,7 +161,7 @@ AnimationClip:
161161
inWeight: 0.33333334
162162
outWeight: 0.33333334
163163
- serializedVersion: 3
164-
time: 0.2
164+
time: 0.5
165165
value: 3
166166
inSlope: 0
167167
outSlope: 0
@@ -170,7 +170,7 @@ AnimationClip:
170170
inWeight: 0.33333334
171171
outWeight: 0.33333334
172172
- serializedVersion: 3
173-
time: 0.4
173+
time: 1
174174
value: 1
175175
inSlope: 0
176176
outSlope: 0
@@ -198,7 +198,7 @@ AnimationClip:
198198
inWeight: 0.33333334
199199
outWeight: 0.33333334
200200
- serializedVersion: 3
201-
time: 0.2
201+
time: 0.5
202202
value: 3
203203
inSlope: 0
204204
outSlope: 0
@@ -207,7 +207,7 @@ AnimationClip:
207207
inWeight: 0.33333334
208208
outWeight: 0.33333334
209209
- serializedVersion: 3
210-
time: 0.4
210+
time: 1
211211
value: 1
212212
inSlope: 0
213213
outSlope: 0

0 commit comments

Comments
 (0)