Esempio n. 1
0
        /// <summary>
        /// Clone a SpriteAnimationClip.
        /// </summary>
        /// <param name="source">Clip source.</param>
        /// <param name="init">Is need init the clone instance.</param>
        /// <returns>The clone instance.</returns>
        public static SpriteAnimationClip Duplicate(SpriteAnimationClip source, bool init)
        {
            SpriteAnimationClip ret = ScriptableObject.CreateInstance <SpriteAnimationClip>();

            ret.name = source.name;
            ret.dataFormatVersion = source.dataFormatVersion;

            ret.frameRate = source.frameRate;
            ret.wrapMode  = source.wrapMode;

            ret.events = source.events;

            ret.root      = SpriteAnimationComponent.Duplicate(source.root);
            ret.root.clip = ret;

            ret.subComponents = new SpriteAnimationComponent[source.subComponents.Length];
            foreach (SpriteAnimationComponent comp in source.subComponents)
            {
                SpriteAnimationComponent tmpComp = SpriteAnimationComponent.Duplicate(comp);

                tmpComp.clip = ret;
                ret.subComponents[tmpComp.index] = tmpComp;
            }

            if (init)
            {
                ret.Init(false);
            }

            return(ret);
        }
        internal void RemoveChild(SpriteAnimationComponent comp)
        {
            int idx = comp.index;

            if (idx == -2)
            {
                return;
            }

            int len     = subComponents.Length;
            int lastIdx = len - 1;

            //if only mine in children list, do not need to swap
            if (lastIdx != idx)
            {
                int oldIdx = subComponents[lastIdx].index;

                SpriteAnimationComponent tmpComp = subComponents[oldIdx];

                subComponents[idx] = tmpComp;
                tmpComp.index      = idx;



                //redirect children to new index
                foreach (int cIdx in tmpComp.children)
                {
                    if (cIdx <= lastIdx)
                    {
                        subComponents[cIdx].parentIndex = idx;
                    }
                }



                //remove from parent
                if (tmpComp.parent != null)
                {
                    List <int> parentChildrenIdx = new List <int>(subComponents[idx].parent.children);

                    int i = parentChildrenIdx.IndexOf(oldIdx);
                    if (i >= 0)
                    {
                        parentChildrenIdx[i] = idx;
                    }

                    subComponents[idx].parent.children = parentChildrenIdx.ToArray();
                }


                idx = subComponents.Length - 1;
            }

            List <SpriteAnimationComponent> tmp = new List <SpriteAnimationComponent>(subComponents);

            tmp.RemoveAt(idx);

            subComponents = tmp.ToArray();
            comp.index    = -2;
        }
        public void AddMixingComponent(string componentPath, bool recursive)
        {
            int hash = componentPath.GetHashCode();
            SpriteAnimationComponent component = clip.GetComponentByPathHash(hash);

            if (component != null)
            {
                AddMixingComponent(component, recursive);

                ApplyEnableList();

                string str = "";
                for (int i = 0; i < componentEnable.Length; i++)
                {
                    str += componentEnable[i].ToString();
                }

                Debug.Log(str);

                if (enabled)
                {
                    foreach (SpriteTransform.StateComponentPair pair in referenceList)
                    {
                        pair.applyTo.CalcWeight();
                    }
                }
            }
        }
        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();
        }
Esempio n. 5
0
 internal void Reset()
 {
     ResetTransform();
     layer     = 0;
     parent    = null;
     component = null;
 }
Esempio n. 6
0
        internal void walkSubComponent(SpriteAnimationComponent comp, List <SpriteAnimationComponent> compList)
        {
            foreach (int idx in comp.children)
            {
                walkSubComponent(clip.subComponents[idx], compList);
            }

            compList.Add(comp);
        }
        void applyEnableList(SpriteAnimationComponent component, bool recursive)
        {
            componentEnable[1 + component.index] = 1;

            if (recursive)
            {
                foreach (int idx in component.children)
                {
                    applyEnableList(clip.subComponents[idx], recursive);
                }
            }
        }
        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();
        }
Esempio n. 9
0
        internal void AddChild(SpriteAnimationComponent child)
        {
            clip.AddChild(child);

            List <int> tmp = new List <int>(children);

            if (!tmp.Contains(child.index))
            {
                tmp.Add(child.index);
                children = tmp.ToArray();
            }
        }
        void calcCurve(SpriteAnimationComponent component)
        {
            component.CalcCurve(null);
            component._fullPath     = component.GetFullPath();
            component._fullPathHash = component._fullPath.GetHashCode();

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                calcCurve(comp);
            }
        }
        internal static bool EnumComponent(SpriteAnimationComponent comp, ComponentDelegate callback, bool skipNotExpand)
        {
            if (!callback(comp))
                return false;

            if (!skipNotExpand || comp.expand)
                foreach (int idx in comp.children)
                    if (!EnumComponent(comp.clip.subComponents[idx], callback, skipNotExpand))
                        return false;

            return true;
        }
        internal void AddChild(SpriteAnimationComponent comp)
        {
            List <SpriteAnimationComponent> tmp = new List <SpriteAnimationComponent>(subComponents);

            if (!tmp.Contains(comp))
            {
                tmp.Add(comp);
                subComponents = tmp.ToArray();

                comp.index = tmp.Count - 1;
            }
        }
        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);
            }
        }
        internal void DetachState(SpriteAnimationState state, SpriteAnimationComponent component)
        {
            foreach (SpriteTransform.StateComponentPair pair in attachStateComponent)
            {
                if (pair.state == state && pair.component == component)
                {
                    attachStateComponent.Remove(pair);
                    state.referenceList.Remove(pair);
                    break;
                }
            }

            Refresh();
        }
Esempio n. 15
0
 /// <summary>
 /// Copy the field from other to self.
 /// </summary>
 /// <param name="other">Copy source SpriteTransform.</param>
 public void Clone(SpriteTransform other)
 {
     position    = other.position;
     rotation    = other.rotation;
     scale       = other.scale;
     shear       = other.shear;
     color       = other.color;
     sprite      = other.sprite;
     layer       = other.layer;
     parent      = other.parent;
     component   = other.component;
     _override   = other._override;
     _isOverride = other._isOverride;
 }
Esempio n. 16
0
        internal void RemoveChild(SpriteAnimationComponent child)
        {
            if (child == null)
            {
                return;
            }

            List <int> tmp = new List <int>(children);

            tmp.Remove(child.index);


            children = tmp.ToArray();
        }
Esempio n. 17
0
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            int searchHash = component._fullPathHash + parentHash;

            SpriteTransform sprTransform = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);

            if (sprTransform == null)
            {
                {
                    sprTransform = spriteRenderer.AttachSpriteComponent(component);

                    sprTransform.parent = parentTransform;

                    sprTransform.layer   = (int)component.layer + state.parentComponentLayer;
                    sprTransform.visible = component.visible;

                    sprTransform.searchHash = searchHash;

                    //sprTransform.name = state.parentTransform != null ? state.parentTransform.component._fullPath + component._fullPath : component._fullPath;
                }


                if (parentTransform != null)
                {
                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransform;
                        parentTransform.lastChild  = sprTransform;

                        sprTransform.prve = null;
                        sprTransform.next = null;
                    }
                    else
                    {
                        sprTransform.next = parentTransform.lastChild.next;
                        sprTransform.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransform;
                    }
                }
            }

            sprTransform.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
            {
                AddSprite(state, state.clip.subComponents[component.children[i]], sprTransform, parentHash);
            }
        }
Esempio n. 18
0
        void calcCurve(SpriteAnimationComponent component, bool calcComp)
        {
            if (calcComp)
            {
                component.CalcCurve(null);
            }

            component._fullPath     = component.GetFullPath();
            component._fullPathHash = EasyMotion2DUtility.GetHashCode(component._fullPath);

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                calcCurve(comp, calcComp);
            }
        }
        internal int getMaxComponentIndex(SpriteAnimationComponent component)
        {
            int ret = component._maxIndex = component.GetMaxIndex();

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                int r = getMaxComponentIndex(comp);
                if (ret < r)
                {
                    ret = r;
                }
            }

            return(ret);
        }
Esempio n. 20
0
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(component._fullPathHash + parentHash);

            if (sprTransfrom == null)
            {
                {
                    sprTransfrom = spriteRenderer.AttachSpriteComponent(component);

                    sprTransfrom.parent = parentTransform;

                    sprTransfrom.layer   = (int)component.layer + state.parentComponentLayer;
                    sprTransfrom.visible = component.visible;
                }


                sprTransfrom.overrideHash = parentHash != 0 ? component._fullPathHash + parentHash : 0;


                if (parentTransform != null)
                {
                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransfrom;
                        parentTransform.lastChild  = sprTransfrom;

                        sprTransfrom.prve = null;
                        sprTransfrom.next = null;
                    }
                    else
                    {
                        sprTransfrom.next = parentTransform.lastChild.next;
                        sprTransfrom.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransfrom;
                    }
                }
            }

            sprTransfrom.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
            {
                AddSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, 0);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Is component a child of this?
        /// </summary>
        public bool IsChild(SpriteAnimationComponent component)
        {
            if (component == null || component == this)
            {
                return(false);
            }

            while ((component = component.parent) != null)
            {
                if (component == this)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 22
0
        /// <summary>
        /// Draw a EasyMotion2D SpriteAnimationComponent hierarchy in GUI.
        /// Usually use to draw animation clip in a custom editor.
        /// </summary>
        /// <param name="position">The preview rectangle.</param>
        /// <param name="index">Not used.</param>
        /// <param name="frameRate">The framerate of clip.</param>
        /// <param name="root">The root bone you want to draw.</param>
        /// <param name="color">The color multiply to bone color.</param>
        /// <param name="canBeDraw">Not used.</param>
        /// <param name="drawGizmos">Not used.</param>
        /// <param name="drawBone">Not used.</param>
        /// <param name="offset">The offset of animation drawing to.</param>
        /// <param name="time">The current time of clip.</param>
        /// <param name="priviewZoom">The scale factor.</param>
        public static void DrawAnimation(Rect position, int index, float frameRate, SpriteAnimationComponent root,
                                         Color color, bool canBeDraw, bool drawGizmos, bool drawBone, Vector2 offset, float time, float priviewZoom)
        {
            GUI.BeginGroup(position);

            if (canBeDraw)
            {
                float w  = Mathf.Max(position.width, 20f);
                float h  = Mathf.Max(position.height, 20f);
                float cx = w * 0.5f;
                float cy = h * 0.5f;

                componentTransforms.Clear();

                Vector2   orig = new Vector2(cx, cy) + offset;
                Matrix4x4 mat  = Matrix4x4.TRS(orig, Quaternion.identity, Vector3.one);
                DrawAnimationComponent(orig, frameRate, root, time, mat, 0, Vector3.one, null, 0);

                componentTransforms.Sort(SpriteTransformComparerByLayer.comparer);

                foreach (SpriteTransform trans in componentTransforms)
                {
                    if (trans.component.visible && trans.sprite != null && trans.sprite.image != null)
                    {
                        Drawing.DrawSprite(
                            new Vector2(position.x, position.y),
                            orig,
                            trans.position * priviewZoom,
                            trans.rotation,
                            trans.scale * priviewZoom,
                            trans.shear,
                            trans.color * color,
                            trans.sprite,
                            SpriteRenderMode.Additive,
                            false,
                            trans.layer.ToString(),
                            Color.white,
                            null);
                    }
                }
            }
            GUI.EndGroup();
        }
        internal static void ReplaceRefClipInComponent(SpriteAnimationComponent component, SpriteAnimationClip[] src, SpriteAnimationClip[] dest)
        {
            foreach (SpriteAnimationKeyFrame kf in component.keyFrames)
            {
                int idx = -1;
                for (int i = 0; i < src.Length; i++)
                {
                    if (kf.refClip == src[i])
                    {
                        idx = i;
                        break;
                    }
                }

                if (idx >= 0)
                {
                    kf.refClip = dest[idx];
                }
            }
        }
Esempio n. 24
0
        internal static bool EnumComponent(SpriteAnimationComponent comp, ComponentDelegate callback, bool skipNotExpand)
        {
            if (!callback(comp))
            {
                return(false);
            }

            if (!skipNotExpand || comp.expand)
            {
                foreach (int idx in comp.children)
                {
                    if (!EnumComponent(comp.clip.subComponents[idx], callback, skipNotExpand))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 25
0
        public void AddMixingComponent(string componentPath, bool recursive)
        {
            int hash = componentPath.GetHashCode();
            SpriteAnimationComponent component = clip.GetComponentByPathHash(hash);

            if (component != null)
            {
                AddMixingComponent(component, recursive);

                ApplyEnableList();

                if (enabled)
                {
                    foreach (SpriteTransform.StateComponentPair pair in referenceList)
                    {
                        pair.applyTo.CalcWeight();
                    }
                }
            }
        }
        internal void upgradeComponent(SpriteAnimationComponent component, List <SpriteAnimationComponent> components)
        {
            if (component != root && !components.Contains(component))
            {
                components.Add(component);
                component.index         = components.Count - 1;
                component._fullPathHash = component._fullPath.GetHashCode();
            }

            List <int> cIdxList = new List <int>();

            foreach (SpriteAnimationComponent child in component.childs)
            {
                upgradeComponent(child, components);

                child.parent = component;
                cIdxList.Add(child.index);
            }

            component.children = cIdxList.ToArray();
        }
        void AddMixingComponent(SpriteAnimationComponent component, bool recursive)
        {
            bool found = false;


            foreach (EnableComponent _ec in enableList)
            {
                if (_ec.component == component && _ec.recursive == recursive)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                EnableComponent ec;
                ec.component = component;
                ec.recursive = recursive;
                enableList.Add(ec);
            }
        }
Esempio n. 28
0
        internal SpriteTransform AttachSpriteComponent(SpriteAnimationComponent component)
        {
            int idx = activePrimitiveCount++;

            SpriteTransform ret = spriteTransforms[idx];

            ret.id        = idx;
            ret.primitive = primitives[idx];
            ret.ResetTransform();

            ret.component = component;
            if (component != null)
            {
                ret.name = component.name;
            }

            if (component != null && overrideList.Count > 0)
            {
                for (int i = 0; i < overrideList.Count; i++)
                {
                    if (overrideList[i].pathHash == component._fullPathHash)
                    {
                        ret.overrideSprite = overrideList[i].sprite;
                        overrideList.RemoveAt(i);
                        break;
                    }
                }
            }

            if (activePrimitiveCount == primitiveCount)
            {
                Resize(activePrimitiveCount + 1);
            }

            _activePrimitiveCount.value = activePrimitiveCount;

            return(ret);
        }
        static public SpriteAnimationComponent Duplicate(SpriteAnimationComponent src)
        {
            SpriteAnimationComponent ret = new SpriteAnimationComponent(src.name);


            ret.index       = src.index;
            ret.parentIndex = src.parentIndex;

            ret.children = new int[src.children.Length];
            for (int i = 0; i < src.children.Length; i++)
            {
                ret.children[i] = src.children[i];
            }

            ret.layer = src.layer;

            ret._fullPath     = src._fullPath;
            ret._fullPathHash = src._fullPathHash;

            ret.clip    = src.clip;
            ret.visible = src.visible;


            ret._maxIndex = src._maxIndex;
            ret.curves    = src.curves;


            ret.keyFrames = new SpriteAnimationKeyFrame[src.keyFrames.Length];
            for (int i = 0; i < src.keyFrames.Length; i++)
            {
                ret.keyFrames[i] = new SpriteAnimationKeyFrame(src.keyFrames[i]);
            }

            ret.curves = src.curves;

            return(ret);
        }
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash )
        {
            int searchHash = component._fullPathHash + parentHash;
  
            SpriteTransform sprTransform = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);

            if (sprTransform == null)
            {
                {
                    sprTransform = spriteRenderer.AttachSpriteComponent(component);

                    sprTransform.parent = parentTransform;

                    sprTransform.layer = (int)component.layer + state.parentComponentLayer;
                    sprTransform.visible = component.visible;

                    sprTransform.searchHash = searchHash;

                    //sprTransform.name = state.parentTransform != null ? state.parentTransform.component._fullPath + component._fullPath : component._fullPath;
                }


                if (parentTransform != null)
                {

                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransform;
                        parentTransform.lastChild = sprTransform;

                        sprTransform.prve = null;
                        sprTransform.next = null;
                    }
                    else
                    {
                        sprTransform.next = parentTransform.lastChild.next;
                        sprTransform.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransform;
                    }
                }
            }

            sprTransform.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
                AddSprite(state, state.clip.subComponents[component.children[i]], sprTransform, parentHash);
        }
        void RemoveSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            int searchHash = component._fullPathHash + parentHash;
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);


            for (int i = 0, e = component.children.Length; i < e; i++)
                RemoveSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, parentHash);


            if (sprTransfrom != null)
            {
                //if (sprTransfrom.lastRefClip != null)
                //{
                //    string name = state.name + "_" + sprTransfrom.lastRefClip.name;
                //    SpriteAnimationState _state = this[name];


                //    if (_state != null)
                //    {
                //        if (_state.parentState != null)
                //            _state.parentState.subClipState.Remove(_state);

                //        Stop(_state);
                //    }

                //    sprTransfrom.lastRefClip = 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);
                }
            }
        }
        internal void walkSubComponent(SpriteAnimationComponent comp, List<SpriteAnimationComponent> compList)
        {
            foreach (int idx in comp.children)
                walkSubComponent(clip.subComponents[idx], compList);

            compList.Add(comp);
        }
        internal void AddChild(SpriteAnimationComponent child)
        {
            clip.AddChild(child);

            List<int> tmp = new List<int>(children);
            if (!tmp.Contains(child.index))
            {
                tmp.Add(child.index);
                children = tmp.ToArray();
            }
        }
        internal void RemoveChild(SpriteAnimationComponent child)
        {
            if (child == null)
                return;

            List<int> tmp = new List<int>(children);
            tmp.Remove(child.index);


            children = tmp.ToArray();
        }
        internal int getMaxComponentIndex(SpriteAnimationComponent component)
        {
            int ret = component._maxIndex = component.GetMaxIndex();

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                int r = getMaxComponentIndex(comp);
                if (ret < r)
                    ret = r;
            }

            return ret;
        }
Esempio n. 36
0
        void RemoveSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash)
        {
            int             searchHash   = component._fullPathHash + parentHash;
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(searchHash);


            for (int i = 0, e = component.children.Length; i < e; i++)
            {
                RemoveSprite(state, state.clip.subComponents[component.children[i]], sprTransfrom, parentHash);
            }


            if (sprTransfrom != null)
            {
                //if (sprTransfrom.lastRefClip != null)
                //{
                //    string name = state.name + "_" + sprTransfrom.lastRefClip.name;
                //    SpriteAnimationState _state = this[name];


                //    if (_state != null)
                //    {
                //        if (_state.parentState != null)
                //            _state.parentState.subClipState.Remove(_state);

                //        Stop(_state);
                //    }

                //    sprTransfrom.lastRefClip = 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);
                }
            }
        }
        void calcCurve(SpriteAnimationComponent component)
        {
            component.CalcCurve( null );
            component._fullPath = component.GetFullPath();
            component._fullPathHash = component._fullPath.GetHashCode();

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                calcCurve(comp);
            }
        }
        internal void upgradeComponent(SpriteAnimationComponent component, List<SpriteAnimationComponent> components)
        {
            if ( component != root && !components.Contains(component))
            {
                components.Add(component);
                component.index = components.Count - 1;
                component._fullPathHash = EasyMotion2DUtility.GetHashCode(component._fullPath);
            }

            List<int> cIdxList = new List<int>();

            foreach (SpriteAnimationComponent child in component.childs)
            {
                upgradeComponent(child, components);

                child.parent = component;
                cIdxList.Add(child.index);
            }

            component.children = cIdxList.ToArray();
        }
        internal SpriteTransform AttachSpriteComponent(SpriteAnimationComponent component)
        {
            int idx = activePrimitiveCount++;

            SpriteTransform ret = spriteTransforms[idx];

            ret.id = idx;
            ret.primitive = primitives[idx];
            ret.ResetTransform();

            ret.component = component;
            if ( component != null )
                ret.name = component.name;

            if (component != null && overrideList.Count > 0)
            {
                for (int i = 0; i < overrideList.Count; i++)
                {
                    if (overrideList[i].pathHash == component._fullPathHash)
                    {
                        ret.overrideSprite = overrideList[i].sprite;
                        overrideList.RemoveAt(i);
                        break;
                    }
                }
            }

            if (activePrimitiveCount == primitiveCount)
                Resize(activePrimitiveCount + 1);

            _activePrimitiveCount.value = activePrimitiveCount;

            return ret;
        }
        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);
        }
        void AddSprite(SpriteAnimationState state, SpriteAnimationComponent component, SpriteTransform parentTransform, int parentHash )
        {
  
            SpriteTransform sprTransfrom = spriteRenderer.GetSpriteTransformByFullPathHash(component._fullPathHash + parentHash);

            if (sprTransfrom == null)
            {
                {
                    sprTransfrom = spriteRenderer.AttachSpriteComponent(component);

                    sprTransfrom.parent = parentTransform;

                    sprTransfrom.layer = (int)component.layer + state.parentComponentLayer;
                    sprTransfrom.visible = component.visible;
                }


                sprTransfrom.overrideHash = parentHash != 0 ? component._fullPathHash + parentHash : 0;


                if (parentTransform != null)
                {
                    if (parentTransform.firstChild == null)
                    {
                        parentTransform.firstChild = sprTransfrom;
                        parentTransform.lastChild = sprTransfrom;

                        sprTransfrom.prve = null;
                        sprTransfrom.next = null;
                    }
                    else
                    {
                        sprTransfrom.next = parentTransform.lastChild.next;
                        sprTransfrom.prve = parentTransform.lastChild;

                        parentTransform.lastChild.next = sprTransfrom;
                    }
                }
            }

            sprTransfrom.AttachState(state, component);

            for (int i = 0, e = component.children.Length; i < e; i++)
                AddSprite( state, state.clip.subComponents[ component.children[i] ], sprTransfrom, 0);
        }
        internal void RemoveChild(SpriteAnimationComponent comp)
        {
            int idx = comp.index;

            if (idx == -2)
                return;

            int len = subComponents.Length;
            int lastIdx = len - 1;

            //if only mine in children list, do not need to swap
            if (lastIdx != idx)
            {
                int oldIdx = subComponents[lastIdx].index;

                SpriteAnimationComponent tmpComp = subComponents[oldIdx];
                
                subComponents[idx] = tmpComp;                
                tmpComp.index = idx;

                

                //redirect children to new index
                foreach (int cIdx in tmpComp.children)
                {
                    if ( cIdx <= lastIdx )
                        subComponents[cIdx].parentIndex = idx;
                }


                

                //remove from parent
                if (tmpComp.parent != null)
                {
                    List<int> parentChildrenIdx = new List<int>(subComponents[idx].parent.children);

                    int i = parentChildrenIdx.IndexOf(oldIdx);
                    if ( i >= 0)
                        parentChildrenIdx[i] = idx;

                    subComponents[idx].parent.children = parentChildrenIdx.ToArray();
                }


                idx = subComponents.Length - 1;
            }

            List<SpriteAnimationComponent> tmp = new List<SpriteAnimationComponent>(subComponents);
            tmp.RemoveAt(idx);

            subComponents = tmp.ToArray();
            comp.index = -2;

        }
        internal void AddChild(SpriteAnimationComponent comp)
        {
            List<SpriteAnimationComponent> tmp = new List<SpriteAnimationComponent>(subComponents);

            if (!tmp.Contains(comp))
            {
                tmp.Add(comp);
                subComponents = tmp.ToArray();

                comp.index = tmp.Count - 1;
            }
        }
Esempio n. 44
0
        static void DrawAnimationComponent(Vector2 orig, float frameRate,
                                           SpriteAnimationComponent component, float time, Matrix4x4 parentMat, float parentRotation, Vector2 parentScale, SpriteTransform parentTran, int parentLayer)
        {
            SpriteTransform transform = new SpriteTransform();

            transform.parent    = parentTran;
            transform.component = component;
            transform.layer     = (int)component.layer + parentLayer;

            Sprite spr = null;
            SpriteAnimationClip refClip = null;


            SpriteAnimationKeyFrame kf = component.Evaluate(time,
                                                            ref transform.position,
                                                            ref transform.rotation,
                                                            ref transform.scale,
                                                            ref transform.shear,
                                                            ref transform.color,
                                                            ref spr,
                                                            ref refClip);

            transform.sprite = spr;

            componentTransforms.Add(transform);

            transform.position.y = -transform.position.y;

            Vector2   tranPosition = parentMat.MultiplyPoint3x4(transform.position);
            Matrix4x4 tmpMat       = Matrix4x4.TRS(transform.position, Quaternion.Euler(0, 0, -transform.rotation), transform.scale);



            if (refClip != null)
            {
                float l    = refClip.length;
                float tick = 1f / refClip.frameRate;
                AnimationLinearCurve clipPlayingCurve = new AnimationLinearCurve(0, 0, l, l);

                clipPlayingCurve.wrapMode = refClip.wrapMode;
                float t = clipPlayingCurve.Evaluate(time - kf.frameIndex * tick);

                DrawAnimationComponent(orig, frameRate, refClip.root, t, parentMat * tmpMat,
                                       parentRotation + transform.rotation,
                                       new Vector2(transform.scale.x * parentScale.x, transform.scale.y * parentScale.y),
                                       transform, transform.layer);
            }



            foreach (int comIdx in component.children)
            {
                SpriteAnimationComponent com = component.clip.subComponents[comIdx];
                DrawAnimationComponent(orig, frameRate, com, time, parentMat * tmpMat,
                                       parentRotation + transform.rotation,
                                       new Vector2(transform.scale.x * parentScale.x, transform.scale.y * parentScale.y),
                                       transform, parentLayer);
            }


            transform.position = tranPosition - orig;
            transform.scale    = new Vector2(transform.scale.x * parentScale.x, transform.scale.y * parentScale.y);

            transform.rotation = parentRotation + transform.rotation;
        }
        internal static void ReplaceRefClipInComponent(SpriteAnimationComponent component, SpriteAnimationClip[] src, SpriteAnimationClip[] dest)
        {
            foreach (SpriteAnimationKeyFrame kf in component.keyFrames)
            {
                int idx = -1;
                for (int i = 0; i < src.Length; i++)
                {
                    if (kf.refClip == src[i])
                    {
                        idx = i;
                        break;
                    }
                }

                if (idx >= 0)
                    kf.refClip = dest[idx];
            }
        }
        static public SpriteAnimationComponent Duplicate(SpriteAnimationComponent src)
        {
            SpriteAnimationComponent ret = new SpriteAnimationComponent(src.name);


            ret.index = src.index;
            ret.parentIndex = src.parentIndex;

            ret.children = new int[src.children.Length];
            for (int i = 0; i < src.children.Length; i++)
                ret.children[i] = src.children[i];

            ret.layer = src.layer;

            ret._fullPath = src._fullPath;
            ret._fullPathHash = src._fullPathHash;

            ret.clip = src.clip;
            ret.visible = src.visible;


            ret._maxIndex = src._maxIndex;
            ret.curves = src.curves;


            ret.keyFrames = new SpriteAnimationKeyFrame[src.keyFrames.Length];
            for(int i = 0; i < src.keyFrames.Length; i++)
                ret.keyFrames[i] = new SpriteAnimationKeyFrame(src.keyFrames[i]);

            ret.curves = src.curves;

            return ret;
        }
        /// <summary>
        /// Is component a child of this?
        /// </summary>
        public bool IsChild(SpriteAnimationComponent component)
        {
            if (component == null || component == this)
                return false;

            while ((component = component.parent) != null)
            {
                if (component == this)
                    return true;
            }

            return false;
        }
        void calcCurve(SpriteAnimationComponent component, bool calcComp )
        {
            if (calcComp)
                component.CalcCurve( null );

            component._fullPath = component.GetFullPath();
            component._fullPathHash = EasyMotion2DUtility.GetHashCode( component._fullPath );

            foreach (int idx in component.children)
            {
                SpriteAnimationComponent comp = subComponents[idx];
                calcCurve(comp, calcComp);
            }
        }