internal void DetachState(SpriteAnimationState state, SpriteAnimationComponent component)
        {
            foreach (SpriteTransform.StateComponentPair pair in attachStateComponent)
            {
                if (pair.state == state && pair.component == component)
                {
                    if (pair.lastRefClip != null)
                    {
                        string name = state.name + "_" + pair.component.fullPath + "_" + pair.lastRefClip.name;
                        SpriteAnimationState _state = state._animation[name];


                        if (_state != null)
                        {
                            state._animation.Stop(_state);
                        }

                        pair.lastRefClip = null;
                    }


                    attachStateComponent.Remove(pair);
                    state.referenceList.Remove(pair);

                    ReleaseComponentPair(pair);
                    break;
                }
            }

            Refresh();
        }
示例#2
0
        /// <summary>
        /// Will start animation with name animation. The animation will be played abruptly without any blending.<br/>
        /// </summary>
        /// <param name="name">The name of animation clip you want to play.</param>
        /// <param name="mode">How the other animations will stopped?</param>
        /// <returns>Will return false if animation can't be played (no animation clip).</returns>
        /// <remarks>
        /// If mode is PlayMode.StopSameLayer then all animations in the same layer will be stopped. If mode is PlayMode.StopAll then all animations currently playing will be stopped.<br/>
        /// If the animation is already playing, other animations will be stopped but the animation will not rewind to the beginning.<br/>
        /// If the animation is not set to be looping it will be stopped and rewinded after playing.<br/>
        /// </remarks>
        public bool Play(string name, PlayMode mode)
        {
            SpriteAnimationState state = this[name];

            if (state != null)
            {
                if (mode == PlayMode.StopAll)
                {
                    StopAll();
                }
                else
                {
                    StopLayer(state.layer);
                }

                if (state.enabled)
                {
                    return(true);
                }

                state.time    = 0f;
                state.weight  = 1f;
                state.enabled = true;

                state.lastTime         = 0f;
                state.lastFrameIndex   = -1;
                state.lastEvaluateTime = 0;

                return(true);
            }

            return(false);
        }
        internal void Clone(SpriteAnimationState other, string name)
        {
            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    other.curve.startTime,
                    other.curve.startValue,
                    other.curve.endTime,
                    other.curve.endValue);
            }
            else
            {
                curve.SetTime(other.curve.startTime,
                              other.curve.startValue,
                              other.curve.endTime,
                              other.curve.endValue);
            }

            wrapMode = other.wrapMode;

            _clip      = other.clip;
            _animation = other._animation;

            normalizedSpeed = other.normalizedSpeed;

            componentEnable = new byte[clip.subComponents.Length + 1];
            for (int i = 0, e = componentEnable.Length; i < e; i++)
            {
                componentEnable[i] = 1;
            }

            _name   = name;
            _layer  = other._layer;
            _weight = other._weight;
        }
        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);
        }
        internal void fini()
        {
            for (int i = 0, e = componentEnable.Length; i < e; i++)
            {
                componentEnable[i] = 0;
            }
            enableList.Clear();


            // remove from SpriteTransform
            tmpBuffer.AddRange(referenceList);
            foreach (SpriteTransform.StateComponentPair pair in tmpBuffer)
            {
                pair.applyTo.DetachState(pair.state, pair.component);
            }
            tmpBuffer.Clear();


            referenceList.Clear();
            subClipState.Clear();

            if (subClipState.Count > 0)
            {
                Debug.LogError("sub state not empty " + _name);
                subClipState.Clear();
            }

            _name           = string.Empty;
            parentTransform = null;
            _clip           = null;
            _animation      = null;
            parentState     = null;

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

            SpriteAnimationState state = animationStates[newName] as SpriteAnimationState;

            if (state == null)
            {
                state = new SpriteAnimationState(clip, this, newName);
                AddState(state);
            }
            else
            {
                state.Init(clip, this, newName);
            }

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

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


            return(state);
        }
 /// <summary>
 /// Remove clip from the animation list.
 /// This willl remove the animation state that match the name.
 /// </summary>
 /// <param name="clipName"></param>
 public void RemoveClip(string clipName)
 {
     if (animationStates.ContainsKey(clip.name))
     {
         SpriteAnimationState state = animationStates[clip.name] as SpriteAnimationState;
         RemoveState(state);
     }
 }
 internal static void ReleaseState(SpriteAnimationState state)
 {
     if (state != null)
     {
         state.fini();
         stateCache.Add(state);
     }
 }
示例#9
0
        /// <summary>
        /// Fades the animation with name animation in over a period of time seconds and fades other animations out.<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/>
        /// If the animation is not set to be looping it will be stopped and rewinded after playing.
        /// </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="mode">How to stop the other clips.</param>
        public void CrossFade(string name, float fadeLength, PlayMode mode)
        {
            SpriteAnimationState state = this[name];

            if (state != null)
            {
                CrossFade(state, fadeLength, mode);
            }
        }
示例#10
0
        /// <summary>
        /// Rewinds the animation named name.
        /// </summary>
        /// <param name="name">The animatino named name you want rewind.</param>
        /// <remarks></remarks>
        public void Rewind(string name)
        {
            SpriteAnimationState state = this[name];

            if (state != null)
            {
                Rewind(state);
            }
        }
示例#11
0
        /// <summary>
        /// Blends the animation named animation towards targetWeight over the 0.3f seconds.<br/>
        /// Playback of other animations will not be affected.
        /// </summary>
        /// <param name="name">Blending clip name.</param>
        /// <param name="targetWeight">Blending target weight.</param>
        /// <param name="fadeLength">Blending length in second.</param>
        /// <param name="needStop">After fade, did need stop the clip playing?</param>
        public void Blend(string name, float targetWeight, float fadeLength, bool needStop)
        {
            SpriteAnimationState state = this[name];

            if (state != null)
            {
                Blend(state, targetWeight, fadeLength, needStop);
            }
        }
示例#12
0
 /// <summary>
 /// Returns the animation state named name.
 /// </summary>
 public SpriteAnimationState this[string name]
 {
     get
     {
         SpriteAnimationState ret = null;
         animationStates.TryGetValue(name, out ret);
         return(ret);
     }
 }
示例#13
0
        /// <summary>
        /// Remove clip from the animation list.
        /// This willl remove the animation state that match the name.
        /// </summary>
        /// <param name="clipName"></param>
        public void RemoveClip(string clipName)
        {
            SpriteAnimationState state = this[clipName];

            if (state != null)
            {
                RemoveState(state);
            }
        }
        internal void RemoveState(SpriteAnimationState state)
        {
            animationStates.Remove(state.name);

            List <SpriteAnimationState> tmp = new List <SpriteAnimationState>(allStates);

            tmp.Remove(state);
            allStates = tmp.ToArray();
        }
        internal void AddState(SpriteAnimationState state)
        {
            animationStates.Add(state.name, state);

            List <SpriteAnimationState> tmp = new List <SpriteAnimationState>(allStates);

            tmp.Add(state);
            allStates = tmp.ToArray();
        }
        internal void SetStateName(SpriteAnimationState state, string oldName)
        {
            if (oldName != null && animationStates.ContainsKey(oldName))
            {
                SpriteAnimationState tmpState = animationStates[oldName] as SpriteAnimationState;

                animationStates.Remove(oldName);
                animationStates.Add(state.name, tmpState);
            }
        }
示例#17
0
 void StopLayerExcept(int layer, SpriteAnimationState s)
 {
     foreach (SpriteAnimationState state in allStates)
     {
         if (state.layer == layer && state != s)
         {
             Stop(state);
         }
     }
 }
示例#18
0
        internal void RemoveState(SpriteAnimationState state)
        {
            if (state != null)
            {
                animationStates.Remove(state.name);
                allStates.Remove(state);

                SpriteAnimationState.ReleaseState(state);
            }
        }
示例#19
0
 void StopAllExcept(SpriteAnimationState s)
 {
     foreach (SpriteAnimationState state in allStates)
     {
         if (state != s)
         {
             Stop(state);
         }
     }
 }
示例#20
0
        static bool removeClip(SpriteAnimationState state)
        {
            bool needRemove = state.clip == _removeClip;

            if (needRemove)
            {
                state._animation.animationStates.Remove(state.name);
                SpriteAnimationState.ReleaseState(state);
            }
            return(needRemove);
        }
 static bool checkPlayingQueue(SpriteAnimationState item)
 {
     if (!item._animation.IsLayerPlaying(item.layer))
     {
         item.time    = 0f;
         item.weight  = 1f;
         item.enabled = true;
         return(true);
     }
     return(false);
 }
示例#22
0
 void Rewind(SpriteAnimationState state)
 {
     if (state.speed < 0f)
     {
         state.time = state.clip.length;
     }
     else
     {
         state.time = 0f;
     }
 }
示例#23
0
 internal void SetStateName(SpriteAnimationState state, string oldName)
 {
     //if ( oldName != null )
     {
         if (animationStates.ContainsKey(oldName))
         {
             animationStates.Remove(oldName);
             animationStates.Add(state.name, state);
         }
     }
 }
示例#24
0
        void Stop(SpriteAnimationState state)
        {
            state.time    = 0;
            state.weight  = 0f;
            state.enabled = false;

            if (state.removeAfterStop)
            {
                removeList.Add(state);
            }
        }
示例#25
0
        internal void Stop(SpriteAnimationState state)
        {
            state.time    = 0;
            state.weight  = 0f;
            state.enabled = false;

            if (state.removeAfterStop && !state.isRemoving)
            {
                removeList.Add(state);
                state.isRemoving = true;
            }
        }
        internal void AttachState(SpriteAnimationState state, SpriteAnimationComponent component)
        {
            SpriteTransform.StateComponentPair pair = new SpriteTransform.StateComponentPair();
            pair.state     = state;
            pair.component = component;
            pair.applyTo   = this;

            attachStateComponent.Add(pair);
            state.referenceList.Add(pair);

            Refresh();
        }
示例#27
0
 void Blend(SpriteAnimationState state, float targetWeight, float fadeLength, bool needStop)
 {
     if (state.parentTransform == null)
     {
         state.needFade     = true;
         state.fadeBase     = state.weight;
         state.fadeTarget   = targetWeight;
         state.fadeLength   = fadeLength;
         state.currFadeTime = 0f;
         state.needStop     = needStop;
     }
 }
        void RemoveSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(component._fullPathHash + parentHash);


            if (sprTransfrom != null)
            {
                sprTransfrom.DetachState(state, component);

                if (sprTransfrom.attachStateComponent.Count <= 0)
                {
                    if (sprTransfrom.prve != null)
                    {
                        sprTransfrom.prve.next = sprTransfrom.next;
                    }

                    if (sprTransfrom.next != null)
                    {
                        sprTransfrom.next.prve = sprTransfrom.prve;
                    }

                    if (sprTransfrom.parent != null && sprTransfrom.parent.firstChild == sprTransfrom)
                    {
                        sprTransfrom.parent.firstChild = sprTransfrom.next;
                    }

                    for (SpriteTransform child = sprTransfrom.firstChild; child != null; child = child.next)
                    {
                        child.parent = null;
                    }
                    {
                        sprTransfrom.parent     = null;
                        sprTransfrom.next       = null;
                        sprTransfrom.prve       = null;
                        sprTransfrom.firstChild = null;
                        sprTransfrom.lastChild  = null;
                    }

                    if (stateRoot.Contains(sprTransfrom))
                    {
                        stateRoot.Remove(sprTransfrom);
                    }

                    spriteRenderer.DetachSprite(sprTransfrom.id);
                }
            }

            for (int i = 0, e = component.children.Length; i < e; i++)
            {
                RemoveSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, 0);
            }
        }
示例#29
0
        /// <summary>
        /// Resume a clip. If not paused, will play the clip.
        /// </summary>
        /// <param name="name">The name of animation clip you want to resume.</param>
        /// <remarks></remarks>
        public void Resume(string name)
        {
            SpriteAnimationState state = this[name];

            if (state != null)
            {
                state.enabled = true;
            }
            else
            {
                Debug.LogError("Can not find a clip named " + name);
            }
        }
示例#30
0
        internal void AddSprite(SpriteAnimationState state)
        {
            AddSprite(state, state.clip.root, state.parentTransform,
                      state.parentTransform == null ? 0 : state.parentTransform.component._fullPathHash);


            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(state.clip.root._fullPathHash);

            if (state.parentTransform == null && !stateRoot.Contains(sprTransfrom))
            {
                stateRoot.Add(sprTransfrom);
            }
        }