/// <summary>
 /// helper method to add animation blending to the three main animated parts of the bg ponies
 /// </summary>
 protected virtual void AnimateBodyManeAndTail(string animationName, AnimationBlendingTransition transition, float duration, bool looping)
 {
     bodyBlender.Blend(animationName, transition, duration, looping);
     maneBlender.Blend(animationName, transition, duration, looping);
     tailBlender.Blend(animationName, transition, duration, looping);
 }
        /// <summary>
        /// Fade between two states
        /// </summary>
        /// <param name="animation">The name of the new animation to switch to</param>
        /// <param name="transition">The transition type to use</param>
        /// <param name="duration">How long the blending should last</param>
        /// <param name="looping">Do the animations loop?</param>
        public void Blend(string animation, AnimationBlendingTransition transition, float duration, bool looping)
        {
            // return if we're already playing this animation or if that animation doesn't exist
            if (mCurrentAnim == animation || !mEntity.AllAnimationStates.HasAnimationState(animation))
                return;
            mCurrentAnim = animation;

            mLoop = looping;

            if (transition == AnimationBlendingTransition.BlendSwitch) {
                if (mSource != null)
                    mSource.Enabled = false;

                mSource = mEntity.GetAnimationState(animation);
                mSource.Enabled = true;
                mSource.Weight = 1;
                mSource.TimePosition = 0;
                mSource.Loop = looping;

                mComplete = true;

                mTimeleft = 0;
            }
            else {
                AnimationState newTarget = mEntity.GetAnimationState(animation);

                if (mTimeleft > 0) {
                    // oops, weren't finished yet
                    if (newTarget == mSource) {
                        // going back to the source state, so let's switch
                        mSource = mTarget;
                        mTarget = newTarget;
                        mTimeleft = mDuration - mTimeleft; // i'm ignoring the new duration here

                        mComplete = false;
                    }
                    else if (newTarget != mTarget) {
                        // ok, newTarget is really new, so either we simply replace the target with this one, or
                        // we make the target the new source
                        if (mTimeleft < mDuration * 0.5f) {
                            // simply replace the target with this one
                            mTarget.Enabled = false;
                            mTarget.Weight = 0;
                        }
                        else {
                            // old target becomes new source
                            mSource.Enabled = false;
                            mSource.Weight = 0;
                            mSource = mTarget;

                        }
                        mTarget = newTarget;
                        mTarget.Enabled = true;
                        mTarget.Weight = 1.0f - mTimeleft / mDuration;
                        mTarget.TimePosition = 0;
                        mTarget.Loop = looping;
                        mComplete = false;
                    }
                    // else -> nothing to do! (ignoring duration here)
                }
                else {
                    // assert( target == 0, "target should be 0 when not blending" )
                    // mSource->setEnabled(true);
                    // mSource->setWeight(1);
                    mTransition = transition;
                    mTimeleft = mDuration = duration;
                    mTarget = newTarget;
                    mTarget.Enabled = true;
                    mTarget.Weight = 0;
                    mTarget.TimePosition = 0;
                    mComplete = false;
                }
            }
        }
Beispiel #3
0
 public void ChangeAnimation(DriverAnimation anim, AnimationBlendingTransition transition = AnimationBlendingTransition.BlendWhileAnimating, float duration = 0.2f)
 {
     ChangeAnimation(anim.ToString(), transition, duration);
 }
Beispiel #4
0
 /// <summary>
 /// The same as the other change animation methods, but this one only runs successfully if it is currently not blending an animation.
 /// If it is, nothing happens.
 /// </summary>
 public void ChangeAnimationIfNotBlending(DriverAnimation anim, AnimationBlendingTransition transition = AnimationBlendingTransition.BlendWhileAnimating, float duration = 0.2f)
 {
     if (ModelComponents[0].AnimationBlender.Complete)
         ChangeAnimation(anim, transition, duration);
 }
Beispiel #5
0
 public void ChangeAnimation(string animationName, AnimationBlendingTransition transition, float duration = 0.2f)
 {
     ModelComponents[0].AnimationBlender.Blend(animationName, transition, duration, true);
 }