Example #1
0
        /// <summary>
        /// Initialize clip internal state.
        /// </summary>
        /// <param name="calcComp">Is need re-init sub compoent curves?</param>
        public void Init(bool calcComp)
        {
            root.clip          = this;
            root.index         = -1;
            root._fullPath     = "/root";
            root._fullPathHash = EasyMotion2DUtility.GetHashCode(root._fullPath);



            tick = 1f / frameRate;

            maxFrameIndex = getMaxComponentIndex(root);
            _length       = maxFrameIndex * tick;



            CalcCurve(calcComp);
            CalcEvents();



            float l    = length;
            float eIdx = (l / tick);

            playingCurve.SetTime(0, 0, _length, Mathf.Floor(eIdx) + 0.051f);
        }
        /// <summary>
        /// Internal function.
        /// </summary>
        public void BuildCollider()
        {
            foreach (ColliderNode node in colliderNones)
            {
                if (node.needAddCollider && node.colliderObject == null)
                {
                    node.nodePathHash = EasyMotion2DUtility.GetHashCode(node.nodePath);

                    GameObject tmp = createColliderObject(node.nodeName, transform, node.nodePath);
                    node.colliderObject = tmp;
                    node.colliderObject.collider.isTrigger = node.isTrigger;
                }
            }
        }
Example #3
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);
            }
        }
Example #4
0
        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();
        }
        /// <summary>
        /// Adds a transform which should be animated. This allows you to reduce the number of animations you have to create. <br/>
        /// For example you might have a handwaving animation. You might want to play the hand waving animation on a idle character or on a walking character. Either you have to create 2 hand waving animations one for idle, one for walking. By using mixing the hand waving animation will have full control of the shoulder. But the lower body will not be affected by it, and continue playing the idle or walk animation. Thus you only need one hand waving animation.<br/>
        /// If recursive is true all children of the mix transform will also be animated. If you don't call AddMixingTransform, all animation curves will be used.
        /// </summary>
        public void AddMixingComponent(string componentPath, bool recursive)
        {
            //int hash = componentPath.GetHashCode();
            int hash = EasyMotion2DUtility.GetHashCode(componentPath);
            SpriteAnimationComponent component = clip.GetComponentByPathHash(hash);

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

                ApplyEnableList();

                if (enabled)
                {
                    foreach (SpriteTransform.StateComponentPair pair in referenceList)
                    {
                        pair.applyTo.CalcWeight();
                    }
                }
            }
        }
        /// <summary>
        /// Removes a transform which should be animated.<br/>
        /// You can only pass bone path that have been added through AddMixingTransform function. If transform has been added as recursive, then it will be removed as recursive. Once you remove all mixing transforms added to animation state all curves become animated again.
        /// </summary>
        public void RemoveMixingComponent(string componentPath)
        {
            //int hash = componentPath.GetHashCode();
            int hash = EasyMotion2DUtility.GetHashCode(componentPath);

            for (int i = 0, e = enableList.Count; i < e; i++)
            {
                if (enableList[i].component._fullPathHash == hash)
                {
                    enableList.RemoveAt(i);
                    break;
                }
            }

            ApplyEnableList();


            foreach (SpriteTransform.StateComponentPair pair in referenceList)
            {
                pair.applyTo.CalcWeight();
            }
        }
Example #7
0
        internal bool Upgrade()
        {
            if (dataFormatVersion < 0.43f)
            {
                try
                {
                    if (subComponents.Length == 0)
                    {
                        Debug.LogWarning("clip " + name + " need upgrade!");

                        List <SpriteAnimationComponent> components = new List <SpriteAnimationComponent>();
                        upgradeComponent(root, components);

                        subComponents = components.ToArray();
                    }
                    dataFormatVersion = 0.43f;
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e.Message + "\n" + "clip " + name + " upgrade to version " + currentFormatVersion + " faild!");
                    return(false);
                }
            }


            if (dataFormatVersion == 0.43f || dataFormatVersion == 0.44f || dataFormatVersion == 0.45f)
            {
                try
                {
                    dataFormatVersion = currentFormatVersion;

                    foreach (SpriteAnimationComponent component in subComponents)
                    {
                        if (component.clip != null)
                        {
                            component._fullPathHash = EasyMotion2DUtility.GetHashCode(component._fullPath);

                            component.CalcCurve(null);
                        }
                    }

                    Debug.Log("clip " + name + " upgrade to version " + currentFormatVersion + " success!");
                }
                catch (System.Exception e)
                {
                    Debug.LogError(e.Message + "\n" + "clip " + name + " upgrade to version " + currentFormatVersion + " faild!");
                    return(false);
                }
            }

            try
            {
                Init(!Application.isPlaying);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message + "\n" + "clip " + name + " upgrade to version " + currentFormatVersion + " faild!");
                return(false);
            }
            return(true);
        }
 public static SpriteAnimationComponent GetComponentByPath(SpriteAnimationClip clip, string path)
 {
     return(clip.GetComponentByPathHash(EasyMotion2DUtility.GetHashCode(path)));
 }