Example #1
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;
        }