예제 #1
0
        /// <summary>
        /// returns two key frame index, which is included in the specified time.
        /// </summary>
        public void CalculateKeyFrameIndex(float localTime, AnimPlayMode mode,
                                           out int index1, out int index2,
                                           out float interpolateTime)
        {
            index1          = 0; // first key frame index
            index2          = 0; // second key frame index
            interpolateTime = 0.0f;

            //  Calculate first key frame index
            if (HasTime)
            {
                index1 = GetKeyFrameIndex(localTime);
            }
            else
            {
                index1 = (int)(localTime / KeyInterval);
            }

            //  Calculate second key frame index by play mode
            switch (mode)
            {
            case AnimPlayMode.Once:         //  Just play once
            {
                //  if index1 is last index
                index2 = (index1 >= KeyCount - 1 ? index1 : index1 + 1);
            }
            break;

            case AnimPlayMode.Repeat:       //  Play looping
            {
                //  if index1 is last index, index2 must be begin (looping)
                index2 = (index1 >= KeyCount - 1 ? 0 : index1 + 1);
            }
            break;

            default:
                throw new NotSupportedException("Not supported play mode");
            }

            if (index1 >= KeyCount - 1)
            {
                index1 = index2 = KeyCount - 1;

                interpolateTime = 1.0f;
            }
            else
            {
                if (HasTime)
                {
                    interpolateTime = (localTime - Time[index1]) /
                                      (Time[index2] - Time[index1]);
                }
                else
                {
                    interpolateTime = HelperMath.CalculateModulo(localTime, KeyInterval)
                                      / KeyInterval;
                }
            }
        }
예제 #2
0
 /// <summary>
 /// binds the animation key frame.
 /// </summary>
 /// <param name="keyFrame">Animation key frame sequence</param>
 /// <param name="startTime">Start time of the animaton</param>
 /// <param name="timeScaleFactor">Time scale of the animaton</param>
 /// <param name="mode">Play mode of the animaton</param>
 public void BindKeyFrameSequence(KeyFrameSequence keyFrame,
                                  float startTime,
                                  float timeScaleFactor,
                                  AnimPlayMode mode)
 {
     SetKeyFrameSequence(keyFrame);
     SetTime(startTime);
     SetTimeScaleFactor(timeScaleFactor);
     SetPlayMode(mode);
 }
예제 #3
0
        public KeyFrame GetInterpolateKeyFrame(float localTime, AnimPlayMode mode)
        {
            int   index1          = 0; // first key frame index
            int   index2          = 0; // second key frame index
            float interpolateTime = 0.0f;

            CalculateKeyFrameIndex(localTime, mode, out index1, out index2,
                                   out interpolateTime);

            //  Calcurate interpolate key frame matrix between KeyFrame1 and KeyFrame2
            return(GetInterpolateKeyFrame(index1, index2, interpolateTime));
        }
예제 #4
0
    override public void ShowGUI()
    {
        method = (AnimMethodChar)EditorGUILayout.EnumPopup("Method:", method);

        isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
        if (!isPlayer)
        {
            animChar = (Char)EditorGUILayout.ObjectField("Character:", animChar, typeof(Char), true);
        }

        if (method == AnimMethodChar.PlayCustom || method == AnimMethodChar.StopCustom)
        {
            clip = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);

            if (method == AnimMethodChar.PlayCustom)
            {
                layer = (AnimLayer)EditorGUILayout.EnumPopup("Layer:", layer);

                if (layer == AnimLayer.Base)
                {
                    EditorGUILayout.LabelField("Blend mode:", "Blend");
                    playModeBase = (AnimPlayModeBase)EditorGUILayout.EnumPopup("Play mode:", playModeBase);
                }
                else
                {
                    blendMode = (AnimationBlendMode)EditorGUILayout.EnumPopup("Blend mode:", blendMode);
                    playMode  = (AnimPlayMode)EditorGUILayout.EnumPopup("Play mode:", playMode);
                }
            }

            fadeTime = EditorGUILayout.Slider("Transition time:", fadeTime, 0f, 1f);
            willWait = EditorGUILayout.Toggle("Pause until finish?", willWait);
        }

        else if (method == AnimMethodChar.SetStandard)
        {
            clip     = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);
            standard = (AnimStandard)EditorGUILayout.EnumPopup("Change:", standard);
        }

        AfterRunningOption();
    }
예제 #5
0
    override public void ShowGUI()
    {
        method = (AnimMethod)EditorGUILayout.EnumPopup("Method:", method);

        _anim = (Animation)EditorGUILayout.ObjectField("Object:", _anim, typeof(Animation), true);

        clip = (AnimationClip)EditorGUILayout.ObjectField("Clip:", clip, typeof(AnimationClip), true);

        if (method == AnimMethod.PlayCustom)
        {
            playMode  = (AnimPlayMode)EditorGUILayout.EnumPopup("Play mode:", playMode);
            blendMode = (AnimationBlendMode)EditorGUILayout.EnumPopup("Blend mode:", blendMode);
        }

        fadeTime = EditorGUILayout.Slider("Transition time:", fadeTime, 0f, 1f);

        willWait = EditorGUILayout.Toggle("Pause until finish?", willWait);

        AfterRunningOption();
    }
예제 #6
0
        /// <summary>
        /// inserts the new KeyFrameSequence, which is specified in the Binder.
        /// If there are two Binder’s, the first Binder will be gone and
        /// the second Binder will be moved as the first Binder,
        /// and the new KeyFrameSequence will be inserted into the second Binder.
        /// When the every Binder is empty, it will then insert to the first Binder
        /// </summary>
        /// <param name="keyFrame">Animation key frame sequence</param>
        /// <param name="startTime">Start time of the animaton</param>
        /// <param name="blendTime">Blend time of two the animaton</param>
        /// <param name="timeScaleFactor">Time scale of the animaton</param>
        /// <param name="mode">Play mode of the animaton</param>
        public void AddKeyFrameSequence(KeyFrameSequence keyFrame,
                                        float startTime,
                                        float blendTime,
                                        float timeScaleFactor,
                                        AnimPlayMode mode)
        {
            this.blendTime   = blendTime;
            this.elapsedTime = startTime;

            if (this.BlendTime == 0.0f)
            {
                ClearAllBinder();

                firstBinder.BindKeyFrameSequence(keyFrame, startTime,
                                                 timeScaleFactor, mode);
            }
            else
            {
                // If binding above two binders, push out one binder
                if (this.bindCount == 2)
                {
                    ShiftBinder();
                }

                if (this.bindCount == 0)
                {
                    firstBinder.BindKeyFrameSequence(keyFrame, startTime,
                                                     timeScaleFactor, mode);
                }
                else if (this.bindCount == 1)
                {
                    secondBinder.BindKeyFrameSequence(keyFrame, startTime,
                                                      timeScaleFactor, mode);
                }
            }

            this.bindCount++;
        }
예제 #7
0
        /// <summary>
        /// plays the bone animation by index.
        /// </summary>
        /// <param name="index">stored animation index</param>
        /// <param name="startTime">begin time of the animation</param>
        /// <param name="blendTime">blending time of the animation</param>
        /// <param name="timeScaleFactor">
        /// time scale of the animation (default is 1.0)
        /// </param>
        /// <param name="playMode">animation play mode</param>
        /// <returns></returns>
        public bool PlayAnimation(int index, float startTime, float blendTime,
                                  float timeScaleFactor, AnimPlayMode playMode)
        {
            AnimationSequence animation = GetAnimation(index);

            if (animation != null)
            {
                //  Binding the playable AnimationSequence to AnimationBinder
                for (int i = 0; i < animation.KeyFrameSequences.Count; i++)
                {
                    KeyFrameSequence sequence = animation.KeyFrameSequences[i];

                    AnimationBlender blender =
                        FindAnimationBlenderByBoneName(sequence.BoneName);
                    if (blender == null)
                    {
                        throw new InvalidOperationException(
                                  "The animation specified a bone (\"" + sequence.BoneName +
                                  "\") that the model (\"" + this.Name + "\") does not have.");
                    }

                    //  Initialize KeyFrameSequence infomation
                    blender.AddKeyFrameSequence(sequence, startTime, blendTime,
                                                timeScaleFactor, playMode);
                }

                if (traceAnimation)
                {
                    System.Diagnostics.Debug.WriteLine(
                        string.Format("Play Animtion : {0} ({1})", Name, index));
                }

                return(true);
            }

            return(false);
        }
예제 #8
0
        /// <summary>
        /// plays an animation according to action.
        /// </summary>
        /// <param name="action">boss's action</param>
        /// <param name="startTime">start time of animation</param>
        public void PlayAction(Action action, float startTime)
        {
            AnimPlayMode playMode  = AnimPlayMode.Repeat;
            float        blendTime = 0.0f;

            this.currentAction = action;

            switch (action)
            {
            case Action.Idle:
            {
                blendTime = 0.5f;
            }
            break;

            case Action.Melee:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.Damage:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.ForwardWalk:
            {
                blendTime = 0.3f;
            }
            break;

            case Action.BackwardWalk:
            {
                blendTime = 0.3f;
            }
            break;

            case Action.LeftWalk:
            {
                blendTime = 0.3f;
            }
            break;

            case Action.RightWalk:
            {
                blendTime = 0.3f;
            }
            break;

            case Action.LeftTurn:
            {
                blendTime = 0.5f;
            }
            break;

            case Action.RightTurn:
            {
                blendTime = 0.5f;
            }
            break;

            case Action.ForwardDead:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.BackwardDead:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.LeftDead:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.RightDead:
            {
                playMode  = AnimPlayMode.Once;
                blendTime = 0.2f;
            }
            break;

            case Action.Reload:
            {
                return;
            }
            }

            PlayAnimation(indexAnimation[(int)action], startTime, blendTime,
                          defaultAnimationScaleFactor, playMode);

            this.actionElapsedTime = 0.0f;
        }
예제 #9
0
 /// <summary>
 /// plays the bone animation by index.
 /// </summary>
 /// <param name="index">stored animation index</param>
 /// <param name="playMode">animation play mode</param>
 /// <returns></returns>
 public bool PlayAnimation(int index, AnimPlayMode playMode)
 {
     return(PlayAnimation(index, 0.0f, 0.0f, 1.0f, playMode));
 }
예제 #10
0
        /// <summary>
        /// inserts the new KeyFrameSequence, which is specified in the Binder. 
        /// If there are two Binder’s, the first Binder will be gone and 
        /// the second Binder will be moved as the first Binder,
        /// and the new KeyFrameSequence will be inserted into the second Binder.
        /// When the every Binder is empty, it will then insert to the first Binder
        /// </summary>
        /// <param name="keyFrame">Animation key frame sequence</param>
        /// <param name="startTime">Start time of the animaton</param>
        /// <param name="blendTime">Blend time of two the animaton</param>
        /// <param name="timeScaleFactor">Time scale of the animaton</param>
        /// <param name="mode">Play mode of the animaton</param>
        public void AddKeyFrameSequence(KeyFrameSequence keyFrame, 
                                        float startTime, 
                                        float blendTime, 
                                        float timeScaleFactor, 
                                        AnimPlayMode mode)
        {
            this.blendTime = blendTime;
            this.elapsedTime = startTime;

            if (this.BlendTime == 0.0f)
            {
                ClearAllBinder();

                firstBinder.BindKeyFrameSequence(keyFrame, startTime, 
                                                 timeScaleFactor, mode);
            }
            else
            {
                // If binding above two binders, push out one binder
                if (this.bindCount == 2)
                    ShiftBinder();

                if (this.bindCount == 0)
                {
                    firstBinder.BindKeyFrameSequence(keyFrame, startTime, 
                                                     timeScaleFactor, mode);
                }
                else if (this.bindCount == 1)
                {
                    secondBinder.BindKeyFrameSequence(keyFrame, startTime, 
                                                      timeScaleFactor, mode);
                }
            }

            this.bindCount++;
        }
예제 #11
0
        /// <summary>
        /// plays the bone animation by index.
        /// </summary>
        /// <param name="index">stored animation index</param>
        /// <param name="startTime">begin time of the animation</param>
        /// <param name="blendTime">blending time of the animation</param>
        /// <param name="timeScaleFactor">
        /// time scale of the animation (default is 1.0)
        /// </param>
        /// <param name="playMode">animation play mode</param>
        /// <returns></returns>
        public bool PlayAnimation(int index, float startTime, float blendTime, 
                                  float timeScaleFactor, AnimPlayMode playMode)
        {
            AnimationSequence animation = GetAnimation(index);
            if (animation != null)
            {                
                //  Binding the playable AnimationSequence to AnimationBinder
                for( int i=0; i<animation.KeyFrameSequences.Count; i++)
                {
                    KeyFrameSequence sequence = animation.KeyFrameSequences[i];

                    AnimationBlender blender = 
                        FindAnimationBlenderByBoneName(sequence.BoneName);
                    if (blender == null)
                    {
                        throw new InvalidOperationException(
                            "The animation specified a bone (\"" + sequence.BoneName + 
                            "\") that the model (\"" + this.Name + "\") does not have.");
                    }

                    //  Initialize KeyFrameSequence infomation
                    blender.AddKeyFrameSequence(sequence, startTime, blendTime,
                                                timeScaleFactor, playMode);
                }

                if (traceAnimation)
                {
                    System.Diagnostics.Debug.WriteLine(
                        string.Format("Play Animtion : {0} ({1})", Name, index));
                }

                return true;
            }

            return false;
        }
예제 #12
0
 /// <summary>
 /// plays the bone animation by index.
 /// </summary>
 /// <param name="index">stored animation index</param>
 /// <param name="playMode">animation play mode</param>
 /// <returns></returns>
 public bool PlayAnimation(int index, AnimPlayMode playMode)
 {
     return PlayAnimation(index, 0.0f, 0.0f, 1.0f, playMode);
 }
예제 #13
0
 /// <summary>
 /// binds the animation key frame.
 /// </summary>
 /// <param name="keyFrame">Animation key frame sequence</param>
 /// <param name="startTime">Start time of the animaton</param>
 /// <param name="timeScaleFactor">Time scale of the animaton</param>
 /// <param name="mode">Play mode of the animaton</param>
 public void BindKeyFrameSequence(KeyFrameSequence keyFrame, 
                                  float startTime, 
                                  float timeScaleFactor, 
                                  AnimPlayMode mode)
 {
     SetKeyFrameSequence(keyFrame);
     SetTime(startTime);
     SetTimeScaleFactor(timeScaleFactor);
     SetPlayMode(mode);
 }
예제 #14
0
 /// <summary>
 /// sets the mode of the animation play.
 /// </summary>
 /// <param name="mode">animation mode</param>
 public void SetPlayMode(AnimPlayMode mode)
 {
     playMode = mode;
 }
예제 #15
0
 /// <summary>
 /// sets the mode of the animation play.
 /// </summary>
 /// <param name="mode">animation mode</param>
 public void SetPlayMode(AnimPlayMode mode)
 {
     playMode = mode;
 }
예제 #16
0
    override public float Run()
    {
        if (isPlayer)
        {
            animChar = GameObject.FindWithTag(Tags.player).GetComponent <Char>();
        }

        if (!isRunning)
        {
            isRunning = true;


            if (animChar)
            {
                if (method == AnimMethodChar.PlayCustom && clip)
                {
                    AdvGame.CleanUnusedClips(animChar.animation);

                    WrapMode  wrap            = WrapMode.Once;
                    Transform mixingTransform = null;

                    if (layer == AnimLayer.Base)
                    {
                        animChar.charState = CharState.Custom;
                        blendMode          = AnimationBlendMode.Blend;
                        playMode           = (AnimPlayMode)playModeBase;
                    }
                    else if (layer == AnimLayer.UpperBody)
                    {
                        mixingTransform = animChar.upperBodyBone;
                    }
                    else if (layer == AnimLayer.LeftArm)
                    {
                        mixingTransform = animChar.leftArmBone;
                    }
                    else if (layer == AnimLayer.RightArm)
                    {
                        mixingTransform = animChar.rightArmBone;
                    }
                    else if (layer == AnimLayer.Neck || layer == AnimLayer.Head || layer == AnimLayer.Face || layer == AnimLayer.Mouth)
                    {
                        mixingTransform = animChar.neckBone;
                    }

                    if (playMode == AnimPlayMode.PlayOnceAndClamp)
                    {
                        wrap = WrapMode.ClampForever;
                    }
                    else if (playMode == AnimPlayMode.Loop)
                    {
                        wrap = WrapMode.Loop;
                    }

                    AdvGame.PlayAnimClip(animChar.GetComponent <Animation>(), (int)layer, clip, blendMode, wrap, fadeTime, mixingTransform);
                }

                else if (method == AnimMethodChar.StopCustom && clip)
                {
                    if (clip != animChar.idleAnim && clip != animChar.walkAnim)
                    {
                        animChar.animation.Blend(clip.name, 0f, fadeTime);
                    }
                }

                else if (method == AnimMethodChar.ResetToIdle)
                {
                    animChar.ResetBaseClips();
                    animChar.charState = CharState.Idle;
                    AdvGame.CleanUnusedClips(animChar.animation);
                }

                else if (method == AnimMethodChar.SetStandard && clip)
                {
                    if (standard == AnimStandard.Idle)
                    {
                        animChar.idleAnim = clip;
                    }

                    else if (standard == AnimStandard.Walk)
                    {
                        animChar.walkAnim = clip;
                    }

                    else if (standard == AnimStandard.Run)
                    {
                        animChar.runAnim = clip;
                    }
                }


                if (willWait && clip)
                {
                    if (method == AnimMethodChar.PlayCustom)
                    {
                        return(defaultPauseTime);
                    }
                    else if (method == AnimMethodChar.StopCustom)
                    {
                        return(fadeTime);
                    }
                }
            }

            return(0f);
        }
        else
        {
            if (animChar.animation[clip.name] && animChar.animation[clip.name].normalizedTime < 1f && animChar.animation.IsPlaying(clip.name))
            {
                return(defaultPauseTime);
            }
            else
            {
                isRunning = false;

                if (playMode == AnimPlayMode.PlayOnce)
                {
                    animChar.animation.Blend(clip.name, 0f, fadeTime);

                    if (layer == AnimLayer.Base && method == AnimMethodChar.PlayCustom)
                    {
                        animChar.charState = CharState.Idle;
                        animChar.ResetBaseClips();
                    }
                }

                AdvGame.CleanUnusedClips(animChar.animation);

                return(0f);
            }
        }
    }