Пример #1
0
    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 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);
        }
        /// <summary>
        /// Performs the transition between current state and new state
        /// </summary>
        /// <param name="stateName">Name of the new state to transition to </param>
        public void TransitionState(string stateName)
        {
            IAnimationState animationState;

            //Checks if Dict contains the state specified
            if (statesList.ContainsKey(stateName))
            {
                animationState = statesList[stateName];
            }
            else
            {
                Console.WriteLine(stateName + " : Failed to activated because it was not loaded");
                return;
            }

            //Checks if the state is already loaded
            if (animationState == currentState)
            {
                return;
            }
            //Performs onExit if there is a current state already
            if (currentState != null)
            {
                currentState.OnExit();
            }
            currentState = animationState;
            animationState.OnEnter();
        }
Пример #4
0
        /// <summary>
        /// Loads an animation based on the name of the name of the texture files
        /// The texture files need to be loaded previously
        /// The names of the animation frame files should begin with the same string
        /// and add the number of the frame separated with an underscore
        /// </summary>
        /// <param name="textureName"></param>
        public void LoadAnimation(string textureName)
        {
            IAnimationState animation = ASMachine.LoadState <SpriteAnimation>(textureName);
            Texture2D       frame     = _owner.GetResources().GetTexture(textureName);

            if (frame == null)
            {
                frame = _owner.GetResources().GetTexture(textureName + "_0");
            }

            List <Texture2D> frames = new List <Texture2D>();
            int i = 1;

            while (frame != null)
            {
                frames.Add(frame);
                frame = _owner.GetResources().GetTexture(textureName + "_" + i);
                i++;
            }

            if (frames.Count == 0)
            {
                Console.WriteLine("Not frames were found with name: " + textureName);
            }
            animation.LoadFrames(frames.ToArray());
        }
Пример #5
0
        /// <summary>
        /// Loads a sprite animation based on the name of the files
        /// The texture files need to be loaded previously
        /// The names of the animation frame files should begin with the same string
        /// and add the number of the frame separated with an underscore
        /// </summary>
        /// <param name="textureName">Identifier of the texture files of each frame</param>
        /// <returns>Returns the created Animation State</returns>
        public IAnimationState LoadAnimation(string animationName, string textureName)
        {
            //Create the animation state
            IAnimationState animation = ASMachine.LoadState <SpriteAnimation>(textureName);
            //Get the initial texture for the first frame
            Texture2D frame = resourceManager.GetTexture(textureName);

            if (frame == null)
            {
                frame = resourceManager.GetTexture(textureName + "_0");
            }

            List <Texture2D> frames = new List <Texture2D>();
            int i = 1;

            //Adds the various frames until there are no more frames to add
            while (frame != null)
            {
                frames.Add(frame);
                frame = resourceManager.GetTexture(textureName + "_" + i);
                i++;
            }

            if (frames.Count == 0)
            {
                Console.WriteLine("No frames were found with name: " + textureName);
            }
            //Loads the franes into the animation
            SpriteAnimationFrames animationFrames = new SpriteAnimationFrames();

            animationFrames.frames = frames.ToArray();
            animation.LoadFrames(animationFrames);
            return(animation);
        }
Пример #6
0
    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 PlayState(IAnimationState state)
 {
     if (lastState?.Equals(state) ?? false)
     {
         return;
     }
     lastState = state;
     animator?.Play(state.Name);
 }
Пример #9
0
 public void Move(float amount)
 {
     if (amount > 0)
     {
         mainAnimationState = MovementBlendTree;
     }
     else
     {
         mainAnimationState = IdleAnimationState;
     }
 }
        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 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 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_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);
        }
Пример #14
0
    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; });
    }
Пример #15
0
    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 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 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 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);
        }
Пример #19
0
        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 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 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);
        }
Пример #22
0
        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);
        }
Пример #23
0
        /// <summary>
        /// Add Animation States to the Animation State Dictionary
        /// </summary>
        /// <param name="animState"></param>
        /// <param name="stateID"></param>
        public void AddState(IAnimationState animState, string stateID)
        {
            //If the Dictionary is empty
            if (StateAnimation.Count == 0)
            {
                //The Active State is the State being passed
                ActiveAnimation = stateID;
            }

            //If the Dictionary doesnt hold a copy of this State
            if (!HoldingAnimationState(stateID))
            {
                //Add this State to the dictionary
                StateAnimation.Add(stateID, animState);
            }
        }
Пример #24
0
    private void Awake()
    {
        IdleAnimationState     = new IdleAnimationState(this);
        JumpAnimationState     = new JumpAnimationState();
        AttackAnimationState   = new AttackAnimationState();
        BlockAnimationState    = new BlockAnimationState();
        EvadeAnimationState    = new EvadeAnimationState();
        HitAnimationState      = new HitAnimationState();
        DieAnimationState      = new DieAnimationState();
        DanceAnimationState    = new DanceAnimationState();
        InteractAnimationState = new InteractAnimationState();
        MovementBlendTree      = new MovementBlendTree(this);

        SetupAnimations();

        mainAnimationState = IdleAnimationState;
    }
        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 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 IEnumerator State_Weight_EqualZero_DoesntWrite([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  = 0f;
            state.time    = 0.5f; //Seek the clip so that values should be written;
            yield return(null);

            Assert.AreEqual(0f, animation.gameObject.transform.localPosition.x);
        }
        public void State_Speed_DoesntAffect_NormalizedTime([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;
            clipInstance.wrapMode = WrapMode.Loop;

            animation.AddClip(clipInstance, "ValidName");
            IAnimationState state = animation.GetState("ValidName");

            state.time = 0.5f;
            float normalizedTime = state.normalizedTime;

            state.speed = 10.0f;
            Assert.AreEqual(normalizedTime, state.normalizedTime);
        }
Пример #30
0
        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);
        }
Пример #31
0
		public AGSAnimation (IAnimationConfiguration configuration, IAnimationState state, int estimatedNumberOfFrames = 8)
		{
			Configuration = configuration;
			State = state;
			Frames = new List<IAnimationFrame> (estimatedNumberOfFrames);
		}