|
1 | 1 | #if COM_UNITY_MODULES_ANIMATION && UNITY_EDITOR |
2 | 2 | using System.Collections; |
3 | 3 | using System.Text; |
| 4 | +using NUnit.Framework; |
4 | 5 | using Unity.Netcode.Components; |
5 | 6 | using Unity.Netcode.TestHelpers.Runtime; |
6 | 7 | using UnityEditor; |
@@ -38,12 +39,18 @@ protected override void OnServerAndClientsCreated() |
38 | 39 | m_DestinationState = rootStateMachine.AddState("State B"); |
39 | 40 | rootStateMachine.defaultState = m_DefaultState; |
40 | 41 |
|
| 42 | + // The source clip is much longer than the default one, so a cross-fade normalized to the wrong state blends far faster |
| 43 | + m_DefaultState.motion = CreateClip("Short", 1.0f); |
| 44 | + m_SourceState.motion = CreateClip("Long", 100.0f); |
| 45 | + m_DestinationState.motion = CreateClip("Destination", 1.0f); |
| 46 | + |
41 | 47 | // Both states transition into the same destination, and the transitions are long enough to still be running when the client joins |
42 | 48 | foreach (var state in new[] { m_DefaultState, m_SourceState }) |
43 | 49 | { |
44 | 50 | var transition = state.AddTransition(m_DestinationState); |
45 | 51 | transition.hasExitTime = false; |
46 | | - transition.duration = 10.0f; |
| 52 | + transition.hasFixedDuration = false; |
| 53 | + transition.duration = 0.5f; |
47 | 54 | transition.AddCondition(AnimatorConditionMode.If, 0.0f, k_TriggerName); |
48 | 55 | } |
49 | 56 | AssetDatabase.SaveAssets(); |
@@ -91,6 +98,15 @@ public IEnumerator LateJoinFromNonDefaultStateCrossFadesToDestination() |
91 | 98 |
|
92 | 99 | yield return WaitForConditionOrTimeOut(errorLog => ReachingDestination(clientAnimator, errorLog)); |
93 | 100 | AssertOnTimeout($"Late-joining client did not cross-fade to {m_DestinationState.name}!"); |
| 101 | + Assert.That(clientAnimator.GetCurrentAnimatorStateInfo(0).shortNameHash, Is.EqualTo(m_SourceState.nameHash), $"Late-joining client did not cross-fade from {m_SourceState.name}!"); |
| 102 | + } |
| 103 | + |
| 104 | + private AnimationClip CreateClip(string name, float length) |
| 105 | + { |
| 106 | + var clip = new AnimationClip { name = name }; |
| 107 | + clip.SetCurve(string.Empty, typeof(Transform), "localScale.x", AnimationCurve.Linear(0.0f, 1.0f, length, 1.0f)); |
| 108 | + AssetDatabase.AddObjectToAsset(clip, m_Controller); |
| 109 | + return clip; |
94 | 110 | } |
95 | 111 |
|
96 | 112 | private bool ReachingDestination(Animator animator, StringBuilder errorLog) |
|
0 commit comments