Esempio n. 1
0
 public void StartAnimation(AnimData animData, float duration)
 {
     StopAnimation(true);
     animationCor = PlayAnimation(animData.AnimName, duration, animData.isLoop, animData.normalizedFadeDuration);
     StartCoroutine(animationCor); // Start the new animation.
 }
Esempio n. 2
0
        private IEnumerator PlayAnimationSequence(string animSequenceName, float duration)
        {
            AnimSequenceData sequence    = ReturnAnimSequenceData(animSequenceName);
            float            totalLength = sequence.Length;

            for (int i = 0; i < sequence.animsData.Count; i++)
            {
                AnimData curAnimData         = sequence.animsData[i];
                float    durationForThisAnim = curAnimData.Length * duration / totalLength;

                float fixedAnimationDuration = durationForThisAnim;
                float percent = 0f;

                if (i == 0)
                {
                    if (isAnimPlaying && sequence.normalizedFadeDuration > 0f)
                    {
                        float fadeDuration = (durationForThisAnim * sequence.normalizedFadeDuration);
                        fixedAnimationDuration = durationForThisAnim - fadeDuration;
                        while (percent < fadeDuration)
                        {
                            anim.CrossFade(curAnimData.AnimName, curAnimData.normalizedFadeDuration);
                            percent += Time.fixedDeltaTime;
                            yield return(waitForFixedUpdate);
                        }

                        anim.CrossFade(curAnimData.AnimName, curAnimData.normalizedFadeDuration);
                    }
                    else
                    {
                        anim.Play(curAnimData.AnimName, 0, 0);
                    }

                    yield return(waitForFixedUpdate);
                }
                else
                {
                    anim.Play(curAnimData.AnimName, 0, 0);
                }

                currentAnim   = sequence.animsData[i].AnimName;
                isAnimPlaying = true;
                anim.SetFloat(lastAnim, 0f);
                lastAnim = currentAnim;

                percent = 0f;
                while (percent < fixedAnimationDuration)
                {
                    anim.SetFloat(currentAnim, percent / fixedAnimationDuration);
                    percent += Time.fixedDeltaTime;
                    yield return(waitForFixedUpdate);
                }

                anim.SetFloat(currentAnim, 1f);

                // animation is finished
                if (i == sequence.animsData.Count - 1)
                {
                    currentAnim   = "";
                    isAnimPlaying = false;
                }

                yield return(waitForFixedUpdate);
            }
        }