public IEnumerator State_Weight_Normalizes([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clip2 = Resources.Load <AnimationClip>("LinearY"); var clipInstance = Object.Instantiate <AnimationClip>(clip); var clipInstance2 = Object.Instantiate <AnimationClip>(clip2); clipInstance.legacy = animation.usesLegacy; clipInstance2.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "State1"); animation.AddClip(clipInstance2, "State2"); IAnimationState state1 = animation.GetState("State1"); IAnimationState state2 = animation.GetState("State2"); state1.enabled = true; state2.enabled = true; state1.weight = 1f; state2.weight = 1f; state1.time = 0.5f; //Seek the clip so that values should be written; state2.time = 0.5f; //Seek the clip so that values should be written; yield return(null); Assert.AreEqual(0.25f, animation.gameObject.transform.localPosition.x); Assert.AreEqual(0.25f, animation.gameObject.transform.localPosition.y); }
public IEnumerator PlayQueue_WithLoopedAnimation_Prevents_StateAccess_OfOriginalState_FromWorking_Correctly([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); var loopedClipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; loopedClipInstance.legacy = animation.usesLegacy; loopedClipInstance.wrapMode = WrapMode.Loop; animation.AddClip(clipInstance, "FirstClip"); animation.AddClip(loopedClipInstance, "LoopedClip"); animation.Play("FirstClip"); animation.PlayQueued("LoopedClip", QueueMode.CompleteOthers); yield return(new WaitForSeconds(1.1f)); Assert.IsTrue(animation.IsPlaying("LoopedClip"), "Clip 'LoopedClip' should be playing"); IAnimationState state = animation.GetState("LoopedClip"); Assert.IsFalse(state.enabled, "We should be playing a copy of LoopedClip, not the LoopedClip State"); yield return(new WaitForSeconds(1.1f)); state = animation.GetState("LoopedClip"); Assert.IsFalse(state.enabled, "We should still be playing a copy of LoopedClip, not the LoopedClip State"); }
public IEnumerator Stop_WithName_OtherClip_IsPlaying_DoesntChange([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipY = Resources.Load <AnimationClip>("LinearY"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); var clipInstanceY = Object.Instantiate <AnimationClip>(clipY); clipInstanceX.legacy = animation.usesLegacy; clipInstanceY.legacy = animation.usesLegacy; animation.AddClip(clipInstanceY, "ClipToStop"); animation.AddClip(clipInstanceX, "OtherClip"); var stateToStop = animation.GetState("ClipToStop"); var otherState = animation.GetState("OtherClip"); stateToStop.weight = 1f; stateToStop.enabled = true; otherState.weight = 1f; otherState.enabled = true; yield return(null); animation.Stop("ClipToStop"); Assert.IsFalse(animation.IsPlaying("ClipToStop")); Assert.IsTrue(animation.IsPlaying("OtherClip")); }
public IEnumerator Stop_WithoutName_IsPlaying_ReturnsFalse([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipY = Resources.Load <AnimationClip>("LinearY"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); var clipInstanceY = Object.Instantiate <AnimationClip>(clipY); clipInstanceX.legacy = animation.usesLegacy; clipInstanceY.legacy = animation.usesLegacy; animation.AddClip(clipInstanceY, "clip1"); animation.AddClip(clipInstanceX, "clip2"); animation.GetState("clip1").enabled = true; animation.GetState("clip1").weight = 0.5f; animation.GetState("clip2").enabled = true; animation.GetState("clip2").weight = 0.5f; Assert.IsTrue(animation.IsPlaying("clip1")); Assert.IsTrue(animation.IsPlaying("clip2")); yield return(null); animation.Stop(); Assert.IsFalse(animation.IsPlaying("clip1")); Assert.IsFalse(animation.IsPlaying("clip2")); }
public void State_Name_EmptyString_CanBeFound([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.name = ""; state = animation.GetState(""); Assert.IsNotNull(state); }
public IEnumerator StateSpeed_Affects_WhenCrossfadeHappens([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "PlaySlowly"); animation.AddClip(clipInstance, "Queued"); IAnimationState state = animation.GetState("PlaySlowly"); state.enabled = true; state.speed = 0.1f; animation.PlayQueued("Queued", QueueMode.CompleteOthers); //Wait for the original length of PlaySlowly yield return(new WaitForSeconds(1.1f)); Assert.IsFalse(animation.IsPlaying("Queued"), "Clip 'Queued' should not be playing yet. Speed is probably applied wrong."); state.speed = 1000.0f; yield return(null); yield return(null); Assert.IsTrue(animation.IsPlaying("Queued"), "Clip 'PlaySlowly' should now be done, and clip 'Queued' should have started playing."); }
public void GetState_WithNoState_ReturnsNull([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); IAnimationState state = animation.GetState("InvalidName"); Assert.AreEqual(null, state); }
public void Sample_DoesntChange_StateTime([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); clipInstanceX.legacy = animation.usesLegacy; animation.AddClip(clipInstanceX, "clip1"); animation.GetState("clip1").enabled = true; animation.GetState("clip1").weight = 1f; animation.GetState("clip1").time = 0.5f; animation.Sample(); Assert.AreEqual(0.5f, animation.gameObject.transform.localPosition.x); Assert.IsTrue(Mathf.Approximately(0.5f, animation.GetState("clip1").time)); }
public IEnumerator Play_SameClip_StateTime_DoesntChange([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "test"); animation.Play("test"); yield return(null); float time = animation.GetState("test").time; animation.Play("test"); Assert.AreEqual(time, animation.GetState("test").time); }
public void Rewind_WithName_OtherClip_Time_DoesntChange([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ToRewind"); animation.AddClip(clipInstance, "ToLeaveAlone"); IAnimationState toRewind = animation.GetState("ToRewind"); toRewind.time = 0.5f; IAnimationState toLeaveAlone = animation.GetState("ToLeaveAlone"); toLeaveAlone.time = 0.5f; animation.Rewind("ToRewind"); Assert.AreNotEqual(0f, toLeaveAlone.time); }
public void Rewind_WithoutName_AllStateTimes_AreZero([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ToRewind"); animation.AddClip(clipInstance, "ToRewindToo"); IAnimationState toRewind = animation.GetState("ToRewind"); toRewind.time = 0.5f; IAnimationState toRewindToo = animation.GetState("ToRewindToo"); toRewindToo.time = 0.5f; animation.Rewind(); Assert.AreEqual(0f, toRewind.time); Assert.AreEqual(0f, toRewindToo.time); }
public void WrapMode_Equals_Clip_WrapMode([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, clipInstance.name); IAnimationState state = animation.GetState(clipInstance.name); Assert.AreEqual(clipInstance.wrapMode, state.wrapMode); }
public void State_Length_Equals_ClipLength([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); Assert.AreEqual(clipInstance.length, state.length); }
public void State_Enabled_InitialValue_False([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); Assert.IsFalse(state.enabled); }
public void State_Name_NullString_Throws_ArgumentNullException([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); Assert.Throws <System.ArgumentNullException>(() => { state.name = null; }); }
public void AddClip_WithSameName_AsClip_DoenstCreateNewClip([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, clipInstance.name); IAnimationState state = animation.GetState(clipInstance.name); Assert.AreEqual(clipInstance, state.clip, "Component should have no clips after remove"); }
public void AddClip_WithNewName_CreatesNewClip([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "NewName"); IAnimationState state = animation.GetState("NewName"); Assert.AreNotEqual(clipInstance, state.clip, "AddClip should have created a new clip instance"); }
public void GetState_WithState_ReturnsState([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); Assert.AreNotEqual(null, state); Assert.AreEqual("ValidName", state.name); }
public void State_Name_ChangingName_DoesntInvalidate_State([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.name = "NewName"; Assert.IsTrue(state.isValid); }
public void Rewind_ValidName_NotPlaying_StateTime_IsZero([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); clipInstanceX.legacy = animation.usesLegacy; animation.AddClip(clipInstanceX, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.time = 0.5f; animation.Rewind("ValidName"); Assert.AreEqual(0f, state.time); }
public IEnumerator Crossfade_MultipleTimes_DoesntReset_Crossfade_Duration([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clip2 = Resources.Load <AnimationClip>("LinearY"); var clipInstance = Object.Instantiate <AnimationClip>(clip); var clipInstance2 = Object.Instantiate <AnimationClip>(clip2); clipInstance.legacy = animation.usesLegacy; clipInstance2.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ToPlay"); animation.AddClip(clipInstance2, "ToCrossfade"); animation.Play("ToPlay"); animation.CrossFade("ToCrossfade", 0.2f); yield return(new WaitForSeconds(0.1f)); animation.CrossFade("ToCrossfade", 0.2f); yield return(new WaitForSeconds(0.11f)); Assert.AreEqual(0.0f, animation.GetState("ToPlay").weight); Assert.AreEqual(1.0f, animation.GetState("ToCrossfade").weight); }
public void RemoveClip_Invalidates_ExistingState([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, clipInstance.name); IAnimationState state = animation.GetState(clipInstance.name); animation.RemoveClip(clipInstance); Assert.IsFalse(state.isValid); }
public IEnumerator State_Enabled_AfterStateEnd_ReturnsFalse([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.enabled = true; yield return(new WaitForSeconds(1.1f)); Assert.IsFalse(state.enabled); }
public IEnumerator Rewind_ValidName_Playing_StateTime_IsZero([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); clipInstanceX.legacy = animation.usesLegacy; animation.AddClip(clipInstanceX, "ValidName"); animation.Play("ValidName"); yield return(new WaitForSeconds(0.5f)); animation.Rewind("ValidName"); IAnimationState state = animation.GetState("ValidName"); Assert.AreEqual(0f, state.time); }
public void Blend_DoesntChange_OtherState_Weight([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipInstance1 = Object.Instantiate <AnimationClip>(clipX); var clipInstance2 = Object.Instantiate <AnimationClip>(clipX); clipInstance1.legacy = animation.usesLegacy; clipInstance2.legacy = animation.usesLegacy; animation.AddClip(clipInstance1, "ToBlend"); animation.AddClip(clipInstance2, "ToLeaveAlone"); animation.Play("ToLeaveAlone"); animation.Blend("ToBlend", 1f, 0f); Assert.AreEqual(1f, animation.GetState("ToLeaveAlone").weight); }
public void State_Time_SetPast_ClipEnd_Doesnt_Immediately_StopState([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); animation.Play(state.name); state.time = 2.0f; Assert.IsTrue(state.enabled, "State should be enabled"); Assert.IsTrue(animation.IsPlaying(state.name), "State should be playing"); Assert.IsTrue(animation.isPlaying, "Component should be playing"); }
public void State_Time_Affects_ClipPlayback([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.enabled = true; state.weight = 1f; state.time = 0.5f; animation.Sample(); Assert.AreEqual(animation.gameObject.transform.localPosition.x, state.time, "Sampling should have updated the position of the object at time 0.5"); }
public IEnumerator CrossfadedOut_Clips_AreTimeReset([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ToPlay"); animation.AddClip(clipInstance, "ToCrossfade"); animation.Play("ToPlay"); animation.CrossFade("ToCrossfade", 0.1f); yield return(new WaitForSeconds(0.2f)); Assert.AreEqual(0.0f, animation.GetState("ToPlay").normalizedTime); }
public void State_Weight_SetWeight_DoesntChange_Enable([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clip = Resources.Load <AnimationClip>("LinearX"); var clipInstance = Object.Instantiate <AnimationClip>(clip); clipInstance.legacy = animation.usesLegacy; animation.AddClip(clipInstance, "ValidName"); IAnimationState state = animation.GetState("ValidName"); state.weight = 1f; Assert.IsFalse(state.enabled); state.enabled = true; state.weight = 0f; Assert.IsTrue(state.enabled); }
public void Sample_EvaluatesAt_StateTime([ValueSource(typeof(ComparativeTestFixture), "Sources")] System.Type type) { IAnimation animation = ComparativeTestFixture.Instantiate(type); var clipX = Resources.Load <AnimationClip>("LinearX"); var clipInstanceX = Object.Instantiate <AnimationClip>(clipX); clipInstanceX.legacy = animation.usesLegacy; animation.AddClip(clipInstanceX, "ToSample"); IAnimationState state = animation.GetState("ToSample"); state.enabled = true; state.weight = 1f; state.time = 0.5f; animation.Sample(); Assert.AreEqual(0.5f, animation.gameObject.transform.localPosition.x); }