コード例 #1
0
ファイル: MovinShape.cs プロジェクト: juusee/InfiniteHappines
        public void UpdateProperty(float frame, ref MotionProps m, BodymovinAnimatedProperties[] set)
        {
            /* ----- CHECK FOR COMPLETE ----- */

            if (m.keys <= 0)
            {
                //Debug.Log(">>> NO PROP KEYS TO ANIMATE!");
                m.completed = true;
                return;
            }

            if (frame >= m.endFrame)
            {
                if (m.key + 1 == set.Length - 1)
                {
                    m.completed = true;
                    //Debug.Log("****** Prop Animation done! ******");
                    return;
                }

                while (frame >= m.endFrame)
                {
                    // Debug.Log("fr > end, eq:  " + frame + " - " + m.startFrame + " / (" + m.endFrame + " - " + m.startFrame + ")   keyframe:  " + m.key );
                    SetKeyframe(ref m, set, m.key + 1);
                    if (m.key == 0)
                    {
                        break;
                    }
                }
            }


            /* ----- PERCENT KEYFRAME COMPLETE ----- */

            m.percent = (frame - m.startFrame) / (m.endFrame - m.startFrame);


            /* ----- CUBIC BEZIER EASE ----- */

            //Debug.Log("to:  " + m.currentOutTangent + "   ti:  " + m.nextInTangent);

            float ease = Ease.CubicBezier(Vector2.zero, m.currentOutTangent, m.nextInTangent, Vector2.one, m.percent);


            /* ----- UPDATE PROPERTY ----- */

            if (set == content.strokeColorSets)
            {
                Color   c = stroke.Color;
                Vector3 v = Value3(m, ease);
                currentStrokeColor = v;
                c.r = v.x;
                c.g = v.y;
                c.b = v.z;

                UpdateStrokeColor(c);
            }
            else if (set == content.fillColorSets)
            {
                //Debug.Log("diff:  " + (set[m.key].e.x - set[m.key].s.x).ToString("F4") + "   fnl:  " + (set[m.key].s + ((set[m.key].e - set[m.key].s) * ease)) + "   percent:  " + m.percent + "   ease:  " + ease);

                Color   c = fill.Color;
                Vector3 v = Value3(m, ease);
                currentFillColor = v;
                c.r = v.x;
                c.g = v.y;
                c.b = v.z;

                UpdateFillColor(c);
            }
        }
コード例 #2
0
        public void UpdateProperty(float frame, ref MotionProps m, BodymovinAnimatedProperties[] set)
        {
            /* ----- CHECK FOR COMPLETE ----- */

            if (m.keys <= 0)
            {
                //Debug.Log(">>> NO PROP KEYS TO ANIMATE!");
                m.completed = true;
                return;
            }

            if (frame >= m.endFrame)
            {
                if (m.key + 1 == set.Length - 1)
                {
                    m.completed = true;
                    //Debug.Log("****** Prop Animation done! ******");
                    return;
                }

                while (frame >= m.endFrame)
                {
                    // Debug.Log("fr > end, eq:  " + frame + " - " + m.startFrame + " / (" + m.endFrame + " - " + m.startFrame + ")   keyframe:  " + m.key );
                    SetKeyframe(ref m, set, m.key + 1);
                    if (m.key == 0)
                    {
                        break;
                    }
                }
            }


            /* ----- PERCENT KEYFRAME COMPLETE ----- */

            m.percent = (frame - m.startFrame) / (m.endFrame - m.startFrame);


            /* ----- CUBIC BEZIER EASE ----- */

            float ease = Ease.CubicBezier(Vector2.zero, m.currentOutTangent, m.nextInTangent, Vector2.one, m.percent);


            /* ----- UPDATE PROPERTY ----- */

            if (set == content.positionSets)
            {
                transform.localPosition = Value3(m, ease) + positionOffset;
            }
            else if (set == content.anchorSets)
            {
                Vector3 v = Value3(m, ease);
                currentAnchor = v;

                for (int i = 0; i < shapes.Length; i++)
                {
                    shapes[i].UpdateAnchor(v);
                }
            }
            else if (set == content.scaleSets)
            {
                transform.localScale = Value3(m, ease);
            }
            else if (set == content.rotationXSets)
            {
                finalRotation.x = Value1(m, ease);
            }
            else if (set == content.rotationYSets)
            {
                finalRotation.y = Value1(m, ease);
            }
            else if (set == content.rotationZSets)
            {
                finalRotation.z = Value1(m, ease);
            }
            else if (set == content.opacitySets)
            {
                float v = Value1(m, ease);
                currentOpacity = v;

                for (int i = 0; i < shapes.Length; i++)
                {
                    shapes[i].UpdateOpacity(v);
                }
            }
        }