Пример #1
0
        public void PlayAnimation(string clipName, bool forceOnce = false)
        {
            this.forceOnce = forceOnce;
            if (!HasAnimationClip(clipName))
            {
                throw new Exception("The clip " + clipName + " does not exist in the animation data");
            }
            PlayingGUID = Guid.NewGuid();
            PlayingClip = clipName;
            timer       = 0f;
            frameTime   = 1f / AnimationData.GetClipFPS(clipName);

            /*if (OnPlayingAnimation != null)
             * {
             *      OnPlayingAnimation(clipName);
             * }*/
            OnPlayingAnimation(clipName);
            if (forceOnce)
            {
                currentFrame = AnimationData.GoToNextFrame(clipName, currentFrame, WeaverAnimationData.WrapMode.Once);
            }
            else
            {
                currentFrame = AnimationData.GetStartingFrame(clipName);
            }
            if (currentFrame == -1)
            {
                //Debug.Log("FINISHED PLAYING ANIMATION_A = " + PlayingClip);
                PlayingGUID = default(Guid);
                string originalClip = PlayingClip;
                PlayingClip = null;
                if (onAnimationDone != null)
                {
                    onAnimationDone(originalClip);
                    onAnimationDone = null;
                }
            }
            else
            {
                SpriteRenderer.sprite = AnimationData.GetFrameFromClip(clipName, currentFrame);

                /*if (OnFrameChange != null)
                 * {
                 *      OnFrameChange(currentFrame);
                 * }*/
                OnPlayingFrame(currentFrame);
            }
        }
Пример #2
0
        protected virtual void Update()
        {
            if (currentFrame != -1)
            {
                timer += Time.deltaTime * PlaybackSpeed;
                if (timer >= frameTime)
                {
                    timer -= frameTime;
                    if (forceOnce)
                    {
                        currentFrame = AnimationData.GoToNextFrame(PlayingClip, currentFrame, WeaverAnimationData.WrapMode.Once);
                    }
                    else
                    {
                        currentFrame = AnimationData.GoToNextFrame(PlayingClip, currentFrame);
                    }
                    if (currentFrame == -1)
                    {
                        //Debug.Log("FINISHED PLAYING ANIMATION_B = " + PlayingClip);
                        PlayingGUID = default(Guid);
                        string originalClip = PlayingClip;
                        PlayingClip = null;
                        if (onAnimationDone != null)
                        {
                            onAnimationDone(originalClip);
                            onAnimationDone = null;
                        }
                    }
                    else
                    {
                        SpriteRenderer.sprite = AnimationData.GetFrameFromClip(PlayingClip, currentFrame);

                        /*if (OnFrameChange != null)
                         * {
                         *      OnFrameChange(currentFrame);
                         * }*/
                        OnPlayingFrame(currentFrame);
                    }
                }
            }
            //else
            //{
            //Debug.Log("Animation Not Set");
            //}
        }