Ejemplo n.º 1
0
    private IEnumerator Play(NAnimation anim)
    {
        int frameIndex     = 0;
        int loopsRemaining = anim.loopCount;

        if (!anim.events.callStartEveryLoop)
        {
            anim.events.OnStart.Invoke();
        }

        while (anim.frames.Length > 0)
        {
            while (WorldControl.IsPaused)
            {
                yield return(null);
            }
            if (anim.events.callStartEveryLoop)
            {
                anim.events.OnStart.Invoke();
            }

            SetAnimSprite(anim.frames[frameIndex]);
            anim.CallEvents(frameIndex);

            yield return(StartCoroutine(WorldControl.PauseableWait(1f / anim.framerate)));

            if (frameIndex == anim.frames.Length - 1)               // end of the animation?
            {
                if (anim.events.callFinishEveryLoop)
                {
                    anim.events.OnFinish.Invoke();
                }

                if (!anim.lööp || loopsRemaining <= 0 && anim.loopCount != 0)
                {
                    break;
                }
                else if (anim.loopCount != 0)
                {
                    loopsRemaining--;
                }
            }
            frameIndex = (frameIndex + 1) % anim.frames.Length;
        }

        if (!anim.events.callFinishEveryLoop)
        {
            anim.events.OnFinish.Invoke();
        }

        currentAnimPlaying = null;
        if (anim.nextAnim != "")
        {
            PlayAnim(anim.nextAnim);
        }
    }