Skip to content

Commit

Permalink
test: NetworkAnimator manual test updates for PR-2127 (Unity-Technolo…
Browse files Browse the repository at this point in the history
…gies#2205)

Fixes and additions to the NetworkAnimator manual tests.
  • Loading branch information
NoelStephensUnity authored Oct 4, 2022
1 parent 5da0247 commit 326bda6
Show file tree
Hide file tree
Showing 9 changed files with 355 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Tests.Manual.NetworkAnimatorTests
[RequireComponent(typeof(Animator))]
public class AnimatedCubeController : NetworkBehaviour
{
public int TestIterations = 20;
private Animator m_Animator;
private bool m_Rotate;
private NetworkAnimator m_NetworkAnimator;
Expand All @@ -30,12 +29,10 @@ private void DetermineNetworkAnimatorComponentType()

public override void OnNetworkSpawn()
{
if (HasAuthority())
{
enabled = false;
}
m_Animator = GetComponent<Animator>();
DetermineNetworkAnimatorComponentType();

m_Animator = GetComponent<Animator>();

m_Rotate = m_Animator.GetBool("Rotate");
}

Expand Down Expand Up @@ -106,7 +103,7 @@ internal void PlayPulseAnimation()
{
if (!IsServer && IsOwner)
{
PlayPulseAnimationServerRpc(m_Rotate);
m_NetworkAnimator.SetTrigger("Pulse");
}
else if (IsServer && IsOwner)
{
Expand All @@ -119,7 +116,6 @@ internal void PlayPulseAnimation()
}
}


private Coroutine m_TestAnimatorRoutine;

internal void TestAnimator(bool useNetworkAnimator = true)
Expand All @@ -133,24 +129,89 @@ internal void TestAnimator(bool useNetworkAnimator = true)
}
}


private IEnumerator TestAnimatorRoutine()
{
var interations = 0;
while (interations < TestIterations)
var waitForSeconds = new WaitForSeconds(0.016f);
var counter = 1.0f;
Debug.Log("Linearly increase test:");
while (counter < 100)
{
m_Animator.SetFloat("TestFloat", counter);
m_Animator.SetInteger("TestInt", (int)counter);
counter++;
yield return waitForSeconds;
}
Debug.Log("Random value assignment test:");
counter = 0.0f;
while (counter < 100)
{
m_Animator.SetFloat("TestFloat", UnityEngine.Random.Range(0.0f, 100.0f));
m_Animator.SetInteger("TestInt", UnityEngine.Random.Range(0, 100));
counter++;
yield return waitForSeconds;
}
StopCoroutine(m_TestAnimatorRoutine);
m_TestAnimatorRoutine = null;
}

private int m_TestIntValue;
private float m_TestFloatValue;

private void DisplayTestIntValueIfChanged()
{
var testIntValue = m_Animator.GetInteger("TestInt");
if (m_TestIntValue != testIntValue)
{
var counter = 1.0f;
m_NetworkAnimator.SetTrigger("TestTrigger");
while (counter < 100)
m_TestIntValue = testIntValue;
Debug.Log($"[{name}]TestInt value changed to = {m_TestIntValue}");
}
var testFloatValue = m_Animator.GetInteger("TestFloat");
if (m_TestFloatValue != testFloatValue)
{
m_TestFloatValue = testFloatValue;
Debug.Log($"[{name}]TestFloat value changed to = {m_TestIntValue}");
}
}

private void LateUpdate()
{

if (!IsSpawned || !IsOwner)
{
if (!IsOwner && IsSpawned)
{
m_Animator.SetFloat("TestFloat", counter);
m_Animator.SetInteger("TestInt", (int)counter);
counter++;
yield return null;
DisplayTestIntValueIfChanged();
return;
}
interations++;

return;
}

DisplayTestIntValueIfChanged();

// Rotates the cube
if (Input.GetKeyDown(KeyCode.C))
{
ToggleRotateAnimation();
}

// Pulse animation (scale down and up slowly)
if (Input.GetKeyDown(KeyCode.Space))
{
PlayPulseAnimation();
}

// Test changing Animator parameters over time
if (Input.GetKeyDown(KeyCode.T))
{
TestAnimator();
}

if (Input.GetKeyDown(KeyCode.R))
{
Debug.Log($"[{name}] TestInt value = {m_TestIntValue}");
Debug.Log($"[{name}] TestInt value = {m_TestIntValue}");
}
yield return null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private void Start()
// Update is called once per frame
private void LateUpdate()
{
if (!IsSpawned || !IsOwner)
if (!IsSpawned)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ AnimatorStateTransition:
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.3220486
m_TransitionDuration: 2.2832582
m_TransitionOffset: 0
m_ExitTime: 0.8417445
m_ExitTime: 0.6903777
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
Expand Down Expand Up @@ -128,6 +128,28 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-4455521266437619866
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -1676030328622575462}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.986124
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-4282378417640754704
AnimatorStateTransition:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -203,6 +225,31 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-2947710236483485956
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: TestTrigger
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -1603678049383302394}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-2547562858931433901
AnimatorStateTransition:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -253,6 +300,7 @@ AnimatorState:
m_Transitions:
- {fileID: -4282378417640754704}
- {fileID: 1678733063235620591}
- {fileID: -2947710236483485956}
m_StateMachineBehaviours:
- {fileID: 6706570197837314945}
m_Position: {x: 50, y: 50, z: 0}
Expand Down Expand Up @@ -297,6 +345,33 @@ AnimatorState:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!1102 &-1603678049383302394
AnimatorState:
serializedVersion: 6
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: TriggerTest2
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: -4455521266437619866}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
m_WriteDefaultValues: 1
m_Mirror: 0
m_SpeedParameterActive: 0
m_MirrorParameterActive: 0
m_CycleOffsetParameterActive: 0
m_TimeParameterActive: 0
m_Motion: {fileID: 7400000, guid: 52bc8e8008543df4594fd2f9a1b9d424, type: 2}
m_Tag:
m_SpeedParameter:
m_MirrorParameter:
m_CycleOffsetParameter:
m_TimeParameter:
--- !u!114 &-1261272140589342921
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -366,7 +441,10 @@ AnimatorStateMachine:
m_Position: {x: 290, y: -150, z: 0}
- serializedVersion: 1
m_State: {fileID: 2733578584814225138}
m_Position: {x: 290, y: 180, z: 0}
m_Position: {x: 50, y: 190, z: 0}
- serializedVersion: 1
m_State: {fileID: -1603678049383302394}
m_Position: {x: 440, y: 190, z: 0}
m_ChildStateMachines: []
m_AnyStateTransitions: []
m_EntryTransitions: []
Expand Down Expand Up @@ -644,7 +722,7 @@ AnimatorState:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Pulse
m_Speed: 0.25
m_Speed: 0.1
m_CycleOffset: 0
m_Transitions:
- {fileID: 1830534497079063084}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ AnimationClip:
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 0.2
time: 0.5
value: {x: 3, y: 3, z: 3}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
Expand All @@ -38,7 +38,7 @@ AnimationClip:
inWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
outWeight: {x: 0.33333334, y: 0.33333334, z: 0.33333334}
- serializedVersion: 3
time: 0.4
time: 1
value: {x: 1, y: 1, z: 1}
inSlope: {x: 0, y: 0, z: 0}
outSlope: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -95,7 +95,7 @@ AnimationClip:
m_AdditiveReferencePoseClip: {fileID: 0}
m_AdditiveReferencePoseTime: 0
m_StartTime: 0
m_StopTime: 0.4
m_StopTime: 1
m_OrientationOffsetY: 0
m_Level: 0
m_CycleOffset: 0
Expand Down Expand Up @@ -124,7 +124,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.2
time: 0.5
value: 3
inSlope: 0
outSlope: 0
Expand All @@ -133,7 +133,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.4
time: 1
value: 1
inSlope: 0
outSlope: 0
Expand Down Expand Up @@ -161,7 +161,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.2
time: 0.5
value: 3
inSlope: 0
outSlope: 0
Expand All @@ -170,7 +170,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.4
time: 1
value: 1
inSlope: 0
outSlope: 0
Expand Down Expand Up @@ -198,7 +198,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.2
time: 0.5
value: 3
inSlope: 0
outSlope: 0
Expand All @@ -207,7 +207,7 @@ AnimationClip:
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.4
time: 1
value: 1
inSlope: 0
outSlope: 0
Expand Down
Loading

0 comments on commit 326bda6

Please sign in to comment.