コード例 #1
0
        /************************************************************************************************************************/

        protected override void PlayMove()
        {
            // We will play either the Walk or Run animation.

            // We need to know which animation we are trying to play and which is the other one.
            AnimationClip playAnimation, otherAnimation;

            if (Input.GetButton("Fire3"))// Left Shift by default.
            {
                playAnimation  = _Run;
                otherAnimation = Walk;
            }
            else
            {
                playAnimation  = Walk;
                otherAnimation = _Run;
            }

            // Play the one we want.
            var playState = Animancer.CrossFade(playAnimation);

            // If the other one is still fading out, align their NormalizedTime to ensure they stay at the same
            // relative progress through their walk cycle.
            var otherState = Animancer.GetState(otherAnimation);

            if (otherState != null && otherState.IsPlaying)
            {
                playState.NormalizedTime = otherState.NormalizedTime;
            }
        }
コード例 #2
0
        /************************************************************************************************************************/

        private void UpdateAnimation()
        {
            // We will play either the Walk or Run animation.

            // We need to know which animation we are trying to play and which is the other one.
            AnimationClip playAnimation, otherAnimation;

            if (Creature.Brain.IsRunning)
            {
                playAnimation  = _Run;
                otherAnimation = _Walk;
            }
            else
            {
                playAnimation  = _Walk;
                otherAnimation = _Run;
            }

            // Play the one we want.
            var playState = Animancer.CrossFade(playAnimation);

            // If the brain wants to move slowly, slow down the animation.
            var speed = Mathf.Min(Creature.Brain.MovementDirection.magnitude, 1);

            playState.Speed = speed;

            // If the other one is still fading out, align their NormalizedTime to ensure they stay at the same
            // relative progress through their walk cycle.
            var otherState = Animancer.GetState(otherAnimation);

            if (otherState != null && otherState.IsPlaying)
            {
                playState.NormalizedTime = otherState.NormalizedTime;
                otherState.Speed         = speed;
            }
        }