private void EvaluateCompoment()
        {
            for (int i = 0; i < spriteRenderer.GetAttachSpriteCount(); i++)
            {
                SpriteTransform sprTransform = spriteRenderer.GetSpriteTransform(i);
                sprTransform.ZeroTransform();


                foreach (SpriteTransform.StateComponentPair pair in sprTransform.attachStateComponent)
                {
                    SpriteAnimationKeyFrame kf = null;

                    if (pair.state.blendMode == AnimationBlendMode.Additive)
                    {
                        //reset buffer
                        transformPropertys[1]  = transformPropertys[2] = transformPropertys[3] = 0f;
                        transformPropertys[4]  = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 0f;
                        transformPropertys[10] = transformPropertys[11] = 0f;

                        kf = pair.component.EvaluateAddtive(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                    }
                    else
                    {
                        //reset buffer
                        transformPropertys[1]  = transformPropertys[2] = transformPropertys[3] = 0f;
                        transformPropertys[4]  = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 1f;
                        transformPropertys[10] = transformPropertys[11] = 0f;

                        kf = pair.component.EvaluateBlending(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                    }

                    if (pair.applyTo.lastRefClip != kf.refClip)
                    {
                        if (pair.applyTo.lastRefClip != null)
                        {
                            string name = pair.state.name + "_" + pair.applyTo.lastRefClip.name;
                            SpriteAnimationState state = this[name];

                            if (state != null)
                            {
                                Stop(state);
                            }
                        }


                        if (kf.refClip != null)
                        {
                            string name = pair.state.name + "_" + kf.refClip.name;

                            if (!animationStates.ContainsKey(name))
                            {
                                AddClip(kf.refClip, name);
                                SpriteAnimationState state = this[name];

                                state.parentTransform      = spriteRenderer.GetSpriteTransformByFullPathHash(pair.component._fullPathHash);
                                state.parentComponentLayer = (int)pair.component.layer;
                                state.removeAfterStop      = true;

                                state.layer   = pair.state.layer;
                                state.weight  = pair.state.weight;
                                state.enabled = true;

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


                                pair.applyTo.lastRefClip = kf.refClip;
                            }
                        }
                    }


                    float weight = pair.weight;


                    {
                        sprTransform.position.x += transformPropertys[1] * weight;
                        sprTransform.position.y += transformPropertys[2] * weight;
                        sprTransform.rotation   += transformPropertys[3] * weight;
                        sprTransform.scale.x    += transformPropertys[4] * weight;
                        sprTransform.scale.y    += transformPropertys[5] * weight;
                        sprTransform.color.r    += transformPropertys[6] * weight;
                        sprTransform.color.g    += transformPropertys[7] * weight;
                        sprTransform.color.b    += transformPropertys[8] * weight;
                        sprTransform.color.a    += transformPropertys[9] * weight;
                        sprTransform.shear.x    += transformPropertys[10] * weight;
                        sprTransform.shear.y    += transformPropertys[11] * weight;
                    }
                }
            }


            if (preTransformUpdate != null)
            {
                preTransformUpdate(this);
            }
        }
Example #2
0
        internal void EvaluateTransform(SpriteTransform sprTransform)
        {
            sprTransform.ZeroTransform();


            for (int idx = 0; idx < sprTransform.attachStateComponent.Count; idx++)
            {
                SpriteTransform.StateComponentPair pair = sprTransform.attachStateComponent[idx];

                SpriteAnimationKeyFrame kf = null;


                if (pair.state.blendMode == AnimationBlendMode.Additive)
                {
                    //reset buffer
                    transformPropertys[1]  = transformPropertys[2] = transformPropertys[3] = 0f;
                    transformPropertys[4]  = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 0f;
                    transformPropertys[10] = transformPropertys[11] = 0f;

                    kf = pair.component.EvaluateAddtive(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                }
                else
                {
                    //reset buffer
                    transformPropertys[1]  = transformPropertys[2] = transformPropertys[3] = 0f;
                    transformPropertys[4]  = transformPropertys[5] = transformPropertys[6] = transformPropertys[7] = transformPropertys[8] = transformPropertys[9] = 1f;
                    transformPropertys[10] = transformPropertys[11] = 0f;

                    kf = pair.component.EvaluateBlending(pair.state.lastEvaluateTime, sprTransform, transformPropertys);
                }


                if (pair.lastRefClip != kf.refClip)
                {
                    if (pair.lastRefClip != null)
                    {
                        string name = pair.state.name + "_" + pair.component.fullPath + "_" + pair.lastRefClip.name;
                        SpriteAnimationState state = this[name];

                        if (state != null)
                        {
                            Stop(state);
                        }

                        pair.lastRefClip = null;
                    }


                    if (kf.refClip != null)
                    {
                        string name = pair.state.name + "_" + pair.component.fullPath + "_" + kf.refClip.name;

                        if (!animationStates.ContainsKey(name))
                        {
                            AddClip(kf.refClip, name);
                            SpriteAnimationState state = this[name];

                            state.parentState          = pair.state;
                            state.parentTransform      = pair.applyTo;
                            state.parentComponentLayer = (int)pair.component.layer;
                            state.removeAfterStop      = true;

                            state.layer  = pair.state.layer;
                            state.weight = pair.state.weight;

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


                            pair.lastRefClip = kf.refClip;
                            state.parentState.subClipState.Add(state);

                            state.enabled = true;
                        }
                    }
                }


                float weight = pair.weight;


                {
                    sprTransform.position.x += transformPropertys[1] * weight;
                    sprTransform.position.y += transformPropertys[2] * weight;
                    sprTransform.rotation   += transformPropertys[3] * weight;
                    sprTransform.scale.x    += transformPropertys[4] * weight;
                    sprTransform.scale.y    += transformPropertys[5] * weight;
                    sprTransform.color.r    += transformPropertys[6] * weight;
                    sprTransform.color.g    += transformPropertys[7] * weight;
                    sprTransform.color.b    += transformPropertys[8] * weight;
                    sprTransform.color.a    += transformPropertys[9] * weight;
                    sprTransform.shear.x    += transformPropertys[10] * weight;
                    sprTransform.shear.y    += transformPropertys[11] * weight;
                }
            }
        }