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 void Init(SpriteAnimationClip clip, SpriteAnimation animation, string name)
        {
            ClearState();


            //set playing curve
            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    clip.playingCurve.startTime,
                    clip.playingCurve.startValue,
                    clip.playingCurve.endTime,
                    clip.playingCurve.endValue);
            }
            else
            {
                curve.SetTime(clip.playingCurve.startTime,
                              clip.playingCurve.startValue,
                              clip.playingCurve.endTime,
                              clip.playingCurve.endValue);
            }

            blendMode = AnimationBlendMode.Blend;

            wrapMode = clip.wrapMode;

            _clip      = clip;
            _animation = animation;


            if (clip.length <= 0f)
            {
                normalizedSpeed = 1f;
            }
            else
            {
                normalizedSpeed = 1f / length;
            }


            if (componentEnable == null)
            {
                componentEnable = new byte[clip.subComponents.Length + 1];
            }

            else if (componentEnable.Length < clip.subComponents.Length + 1)
            {
                componentEnable = new byte[clip.subComponents.Length + 1];
            }


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


            this.name = name;
        }
        internal void Init(SpriteAnimationClip clip, SpriteAnimation animation, string name)
        {
            //set playing curve
            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    clip.playingCurve.startTime,
                    clip.playingCurve.startValue,
                    clip.playingCurve.endTime,
                    clip.playingCurve.endValue);
            }
            else
            {
                curve.SetTime(clip.playingCurve.startTime,
                              clip.playingCurve.startValue,
                              clip.playingCurve.endTime,
                              clip.playingCurve.endValue);
            }


            wrapMode = clip.wrapMode;

            _clip      = clip;
            _animation = animation;


            normalizedSpeed = 1f / clip.length;



            if (componentEnable == null)
            {
                componentEnable = new byte[clip.subComponents.Length + 1];
            }

            else if (componentEnable.Length < clip.subComponents.Length + 1)
            {
                System.Array.Resize(ref componentEnable, clip.subComponents.Length + 1);
            }


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


            this.name = name;
        }
Beispiel #4
0
        internal void Init(SpriteAnimationClip clip, SpriteAnimation animation, string name)
        {
            // remove from SpriteTransform
            foreach (SpriteTransform.StateComponentPair pair in referenceList)
            {
                pair.applyTo.DetachState(pair.state, pair.component);
            }

            //set playing curve
            if (curve == null)
            {
                curve = new AnimationLinearCurve(
                    clip.playingCurve.startTime,
                    clip.playingCurve.startValue,
                    clip.playingCurve.endTime,
                    clip.playingCurve.endValue);
            }
            else
            {
                curve.SetTime(clip.playingCurve.startTime,
                              clip.playingCurve.startValue,
                              clip.playingCurve.endTime,
                              clip.playingCurve.endValue);
            }


            wrapMode = clip.wrapMode;

            _clip      = clip;
            _animation = animation;


            normalizedSpeed = 1f / clip.length;


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


            this.name = name;
        }
Beispiel #5
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;
        }