internal SpriteAnimationState AddClip(SpriteAnimationClip clip, string newName, int firstFrame, int lastFrame, bool addLoopFrame)
        {
            if (clip == null || (clip != null && !clip))
            {
                Debug.LogError("A null clip/missing clip add to animation!");
                return(null);
            }

            SpriteAnimationState state = this[newName];

            if (state == null)
            {
                state = SpriteAnimationState.CreateState();
                state.Init(clip, this, newName);

                AddState(state);
            }
            else
            {
                state.Init(clip, this, newName);
            }

            SetClipRange(newName, firstFrame * clip.tick, lastFrame * clip.tick);

            List <SpriteAnimationClip> tmpAnis = new List <SpriteAnimationClip>(animations);

            if (!tmpAnis.Contains(clip))
            {
                tmpAnis.Add(clip);
                animations = tmpAnis.ToArray();
            }


            return(state);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cross fades an animation after previous animations has finished playing.<br/>
        ///If queue is QueueMode.CompleteOthers this animation will only start once all other animations have stopped playing.<br/>
        ///If queue is QueueMode.PlayNow this animation will start playing immediately on a duplicated animation state.<br/>
        /// if mode is PlayMode.StopSameLayer, animations in the same layer as animation will be faded out while animation is faded in. if mode is PlayMode.StopAll, all animations will be faded out while animation is faded in.<br/>
        ///After the animation has finished playing it will automatically clean itself up. Using the duplicated animation state after it has finished will result in an exception. <br/>
        /// </summary>
        /// <param name="name">The clip name that you want to fade in.</param>
        /// <param name="fadeLength">The fade in/out length in second.</param>
        /// <param name="queue">How the clip start fade.</param>
        /// <param name="mode">How to stop the other clips.</param>
        /// <returns>The duplicated animation state of the clip.</returns>
        public SpriteAnimationState CrossFadeQueued(string name, float fadeLength, QueueMode queue, PlayMode mode)
        {
            SpriteAnimationState state = this[name];

            if (state == null)
            {
                return(null);
            }

            bool isPlaying = IsLayerPlaying(state.layer);

            if (queue == QueueMode.PlayNow || !isPlaying)
            {
                string newName = state.name + " - Queued Clone " + cloneID++;

                SpriteAnimationState tmpState = SpriteAnimationState.CreateState();
                tmpState.Clone(state, newName);


                tmpState.removeAfterStop = true;
                AddState(tmpState);

                CrossFade(tmpState, fadeLength, mode);

                return(tmpState);
            }
            else
            {
                string newName = state.name + " - Queued Clone " + cloneID++;

                SpriteAnimationState tmpState = SpriteAnimationState.CreateState();
                tmpState.Clone(state, newName);

                tmpState.removeAfterStop = true;
                AddState(tmpState);


                SpriteAnimationQueueItem item = new SpriteAnimationQueueItem();
                item.state      = tmpState;
                item.playMode   = mode;
                item.fadeLength = fadeLength;
                crossFadeQueue.Add(item);

                return(tmpState);
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Plays an animation after previous animations has finished playing.<br/>
        /// If queue is QueueMode.CompleteOthers this animation will only start once all other animations have stopped playing.<br/>
        /// If queue is QueueMode.PlayNow this animation will start playing immediately on a duplicated animation state.<br/>
        /// if mode is PlayMode.StopSameLayer, animations in the same layer as animation will be faded out while animation is faded in. if mode is PlayMode.StopAll, all animations will be faded out while animation is faded in.<br/>
        /// After the animation has finished playing it will automatically clean itself up. Using the duplicated animation state after it has finished will result in an exception.
        /// </summary>
        /// <param name="name">The name of animation clip you want to play.</param>
        /// <param name="queue">QueueMode control how to play the clip in queue.</param>
        /// <param name="mode">QueueMode control how to play the clip in queue.</param>
        /// <returns>The duplicated animation state of the clip.</returns>
        public SpriteAnimationState PlayQueued(string name, QueueMode queue, PlayMode mode)
        {
            SpriteAnimationState state = this[name];

            if (state == null)
            {
                return(null);
            }

            bool isPlaying = IsLayerPlaying(state.layer);

            if (queue == QueueMode.PlayNow || !isPlaying)
            {
                string newName = state.name + " - Queued Clone " + cloneID++;

                SpriteAnimationState tmpState = SpriteAnimationState.CreateState();
                tmpState.Clone(state, newName);

                tmpState.removeAfterStop = true;
                AddState(tmpState);

                Play(newName);
                return(tmpState);
            }
            else
            {
                string newName = state.name + " - Queued Clone " + cloneID++;

                SpriteAnimationState tmpState = SpriteAnimationState.CreateState();
                tmpState.Clone(state, newName);


                tmpState.removeAfterStop = true;
                AddState(tmpState);


                playingQueue.Add(tmpState);

                return(tmpState);
            }

            return(null);
        }