示例#1
0
        public static void setSteppedInterval(AnimationCurve curve, int i, int nextI)
        {
            if (curve.keys[i].value == curve.keys[nextI].value)
            {
                return;
            }

            object thisKeyframeBoxed = curve[i];
            object nextKeyframeBoxed = curve[nextI];

            if (!KeyframeUtil.isKeyBroken(thisKeyframeBoxed))
            {
                KeyframeUtil.SetKeyBroken(thisKeyframeBoxed, true);
            }
            if (!KeyframeUtil.isKeyBroken(nextKeyframeBoxed))
            {
                KeyframeUtil.SetKeyBroken(nextKeyframeBoxed, true);
            }

            KeyframeUtil.SetKeyTangentMode(thisKeyframeBoxed, 1, TangentMode.Stepped);
            KeyframeUtil.SetKeyTangentMode(nextKeyframeBoxed, 0, TangentMode.Stepped);

            Keyframe thisKeyframe = (Keyframe)thisKeyframeBoxed;
            Keyframe nextKeyframe = (Keyframe)nextKeyframeBoxed;

            thisKeyframe.outTangent = float.PositiveInfinity;
            nextKeyframe.inTangent  = float.PositiveInfinity;
            curve.MoveKey(i, thisKeyframe);
            curve.MoveKey(nextI, nextKeyframe);
        }
    public static AnimationCurve VolumeFalloff(float falloffPoint, float falloffPower)
    {
        AnimationCurve animationCurve = new AnimationCurve();

        animationCurve.AddKey(KeyframeUtil.GetNew(0f, 1f, TangentMode.Linear));
        if (falloffPoint >= 1f || falloffPower == 1f)
        {
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, 1f, TangentMode.Linear));
        }
        else
        {
            for (float num = 0f; num < 10f; num += 0.5f)
            {
                float num2 = falloffPoint * Mathf.Pow(2f, num);
                if (num2 > 1f)
                {
                    break;
                }
                float value = Mathf.Pow(falloffPower, num) * Mathf.InverseLerp(1f, falloffPoint, num2);
                animationCurve.AddKey(KeyframeUtil.GetNew(num2, value, TangentMode.Linear));
            }
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, 0f, TangentMode.Linear));
        }
        animationCurve.UpdateAllLinearTangents();
        return(animationCurve);
    }
    public static AnimationCurve Spread(float near, float far, float falloffPoint, float falloffPower)
    {
        AnimationCurve animationCurve = new AnimationCurve();

        animationCurve.AddKey(KeyframeUtil.GetNew(0f, near, TangentMode.Linear));
        if (falloffPoint >= 1f || falloffPower == 1f)
        {
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, near, TangentMode.Linear));
        }
        else
        {
            float num = 1f / falloffPoint;
            for (float num2 = 0f; num2 < 10f; num2 += 0.5f)
            {
                float num3 = falloffPoint * Mathf.Pow(2f, num2);
                if (num3 >= 1f)
                {
                    break;
                }
                float value = Mathf.Lerp(far, near, Mathf.Pow(falloffPower, num2));
                animationCurve.AddKey(KeyframeUtil.GetNew(num3, value, TangentMode.Linear));
            }
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, far, TangentMode.Linear));
        }
        animationCurve.UpdateAllLinearTangents();
        return(animationCurve);
    }
示例#4
0
    public void SetWaypoint(Vector3 position, float time)
    {
        List <Waypoint> waypoints = this.Waypoints;

        if (waypoints == null)
        {
            return;
        }

        Waypoint keyframe = GetKeyframe(waypoints, time) as Waypoint;

        if (keyframe == null)
        {
            Vector3 tangent = 0.125f * KeyframeUtil.GetTangent(waypoints, time, true, true);
            keyframe           = Track.CreateMarker <Waypoint>(time);
            keyframe.JointType = JointType.Continuous;
            keyframe.Tangent   = tangent;

            TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
            UpdateProperties();
            EnforceWaypointConstraints();
        }

        bool endpoint = (waypoints.Count == 0) || (time > waypoints[waypoints.Count - 1].time);

        Undo.RecordObjects(new Object[] { keyframe }, "Change Waypoints");
        keyframe.Position = position;

        if (endpoint)
        {
            keyframe.JointType = JointType.Linear;
        }

        UpdateView();
    }
示例#5
0
    public void UpdateView()
    {
        KeyframeUtil.InterpolationSet <GuideKeyframe> interpolationData = KeyframeUtil.Interpolate(Keyframes, Time, true);
        if (interpolationData != null)
        {
            GuideKeyframe firstKeyframe = interpolationData.first;
            GuideKeyframe nextKeyframe  = interpolationData.second;
            float         value         = interpolationData.value;


            transform.position   = Vector3.Lerp(firstKeyframe.Position, nextKeyframe.Position, value);
            transform.rotation   = Quaternion.Slerp(firstKeyframe.Rotation, nextKeyframe.Rotation, value);
            transform.localScale = Vector3.Lerp(firstKeyframe.Scale, nextKeyframe.Scale, value);
        }
    }
示例#6
0
    public static void DrawColorKeyframes(Crazyflie drone, List <Waypoint> waypoints)
    {
        List <ColorKeyframe> colorKeyframes = drone.ColorKeyframes;
        Vector3 dronePosition = drone.transform.position;

        for (int i = 0; i < colorKeyframes.Count; i++)
        {
            ColorKeyframe keyframe = colorKeyframes[i];
            keyframe.Position = KeyframeUtil.GetPosition(waypoints, keyframe.time, dronePosition);
            keyframe.Tangent  = KeyframeUtil.GetTangent(waypoints, keyframe.time, true, true);
            keyframe.Offset   = GetOffset(i, colorKeyframes);

            DrawSelector(keyframe);
        }
    }
示例#7
0
    public static void DrawTangent(List <Waypoint> waypoints, float scale = 1.0f, double time = -1.0)
    {
        time = (time < 0) ? TimelineUtilities.Director.time : time;
        Vector3 position      = KeyframeUtil.GetPosition(waypoints, time, Vector3.zero);
        Vector3 tangentVector = KeyframeUtil.GetTangent(waypoints, time, true, true);

        Color previousColor = Handles.color;

        Handles.color = Color.red;

        float   multiplier  = (scale / 2.0f);
        Vector3 halfTangent = multiplier * tangentVector;

        Handles.DrawLine(position - halfTangent, position + halfTangent);
        Handles.color = previousColor;
    }
示例#8
0
        public static void setLinearInterval(AnimationCurve curve, int i, int nextI)
        {
            Keyframe thisKeyframe = curve[i];
            Keyframe nextKeyframe = curve[nextI];

            thisKeyframe.outTangent = CurveExtension.CalculateLinearTangent(curve, i, nextI);
            nextKeyframe.inTangent  = CurveExtension.CalculateLinearTangent(curve, nextI, i);

            KeyframeUtil.SetKeyBroken((object)thisKeyframe, true);
            KeyframeUtil.SetKeyBroken((object)nextKeyframe, true);

            KeyframeUtil.SetKeyTangentMode((object)thisKeyframe, 1, TangentMode.Linear);
            KeyframeUtil.SetKeyTangentMode((object)nextKeyframe, 0, TangentMode.Linear);


            curve.MoveKey(i, thisKeyframe);
            curve.MoveKey(nextI, nextKeyframe);
        }
    public static void createAnimation()
    {
        GameObject go = GameObject.Find(GAME_OBJECT_NAME);

        if (go != null)
        {
            removeGameObjectAndComponents(go);
        }

        Animator animator;

        go = createGameObjects(out animator);
        AnimationClip animationClip = new AnimationClip();

        AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);


        AnimationCurve activeCurve         = new AnimationCurve();
        AnimationCurve positionLineCurve   = new AnimationCurve();
        AnimationCurve positionSmoothCurve = new AnimationCurve();


        for (int i = 0; i < stepValues.Length; i++)
        {
            float time = stepTime * i;
            activeCurve.AddKey(KeyframeUtil.GetNew(time, stepValues[i], TangentMode.Stepped));
            positionLineCurve.AddKey(KeyframeUtil.GetNew(time, stepValues[i] + 2, TangentMode.Linear));
            positionSmoothCurve.AddKey(KeyframeUtil.GetNew(time, stepValues[i] - 2, TangentMode.Smooth));
        }

        //this will be linear curve, so need to update tangents (should be after keyframes assignments)
        positionLineCurve.UpdateAllLinearTangents();



        animationClip.SetCurve(CUBE1_NAME, typeof(GameObject), "m_IsActive", activeCurve);
        animationClip.SetCurve(CUBE2_NAME, typeof(Transform), "localPosition.x", positionLineCurve);
        animationClip.SetCurve(CUBE2_NAME, typeof(Transform), "localPosition.y", positionSmoothCurve);

        AssetDatabase.CreateAsset(animationClip, ANIMATION_CLIP_PATH);
        AssetDatabase.SaveAssets();
        AddClipToAnimatorComponent(go, animator, animationClip);
    }
    public static AnimationCurve VolumeFalloffFromTo(float near, float far, float falloffStart, float falloff48db, float falloffFocus)
    {
        AnimationCurve animationCurve = new AnimationCurve();

        animationCurve.AddKey(KeyframeUtil.GetNew(0f, near, TangentMode.Linear));
        if (falloff48db <= falloffStart)
        {
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, near, TangentMode.Linear));
        }
        else if (falloffFocus == 1f)
        {
            float num  = falloffStart / (falloffStart + falloff48db);
            float num2 = 1f;
            for (int i = 0; i < 16; i++)
            {
                float time = num + (1f - num) * (float)i / 16f;
                animationCurve.AddKey(KeyframeUtil.GetNew(time, Mathf.Lerp(far, near, num2), TangentMode.Linear));
                num2 /= Mathf.Sqrt(2f);
            }
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, far, TangentMode.Linear));
        }
        else
        {
            float f    = Mathf.Pow(2f, 1f - falloffFocus);
            float num3 = falloffStart / (falloffStart + falloff48db);
            float num4 = (1f - Mathf.Pow(f, 8f) * num3) / (1f - Mathf.Pow(f, 8f));
            float num5 = num3 - num4;
            float num6 = 1f;
            for (int j = 0; j < 16; j++)
            {
                animationCurve.AddKey(KeyframeUtil.GetNew(num4 + num5, Mathf.Lerp(far, near, num6), TangentMode.Linear));
                num5 *= Mathf.Sqrt(f);
                num6 /= Mathf.Sqrt(2f);
            }
            animationCurve.AddKey(KeyframeUtil.GetNew(1f, far, TangentMode.Linear));
        }
        animationCurve.UpdateAllLinearTangents();
        return(animationCurve);
    }
示例#11
0
    public void EngineCurveInit()
    {
        if (aiScript.totalGears <= 0)
        {
            Debug.LogError("You are trying to set your vehicle gear to 0 or below! Why you trying to do this???");
            return;
        }

        aiScript.gearSpeed         = new float[aiScript.totalGears];
        aiScript.engineTorqueCurve = new AnimationCurve[aiScript.totalGears];
        aiScript.currentGear       = 0;

        for (int i = 0; i < aiScript.engineTorqueCurve.Length; i++)
        {
            aiScript.engineTorqueCurve[i] = new AnimationCurve(new Keyframe(0, 1));
        }

        for (int i = 0; i < aiScript.totalGears; i++)
        {
            aiScript.gearSpeed[i] = Mathf.Lerp(0, aiScript.maxSpeed / 1.5f, ((float)i / (float)(aiScript.totalGears - 0)));

            if (i != 0)
            {
                aiScript.engineTorqueCurve[i].MoveKey(0, new Keyframe(0, .5f));
                aiScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(0, aiScript.maxSpeed, ((float)i / (float)(aiScript.totalGears - 0))), 1f, CurveExtended.TangentMode.Smooth));
                aiScript.engineTorqueCurve[i].AddKey(aiScript.maxSpeed, 0);
                aiScript.engineTorqueCurve[i].postWrapMode = WrapMode.Clamp;
                aiScript.engineTorqueCurve[i].UpdateAllLinearTangents();
            }
            else
            {
                aiScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(25, aiScript.maxSpeed, ((float)i / (float)(aiScript.totalGears - 1))), 1.25f, TangentMode.Linear));
                aiScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(25f, aiScript.maxSpeed, ((float)(i + 1) / (float)(aiScript.totalGears - 1))), 0, TangentMode.Linear));
                aiScript.engineTorqueCurve[i].AddKey(aiScript.maxSpeed, 0);
                aiScript.engineTorqueCurve[i].UpdateAllLinearTangents();
            }
        }
    }
示例#12
0
    void EngineCurveInit()
    {
        if (motorScript.totalGears <= 0)
        {
            return;
        }

        motorScript.gearSpeed         = new float[motorScript.totalGears];
        motorScript.engineTorqueCurve = new AnimationCurve[motorScript.totalGears];
        motorScript.currentGear       = 0;

        for (int i = 0; i < motorScript.engineTorqueCurve.Length; i++)
        {
            motorScript.engineTorqueCurve[i] = new AnimationCurve(new Keyframe(0, 1));
        }

        for (int i = 0; i < motorScript.totalGears; i++)
        {
            motorScript.gearSpeed[i] = Mathf.Lerp(0, motorScript.maxSpeed, ((float)i / (float)(motorScript.totalGears - 0)));

            if (i != 0)
            {
                motorScript.engineTorqueCurve[i].MoveKey(0, new Keyframe(0, .25f));
                motorScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(0, motorScript.maxSpeed, ((float)i / (float)(motorScript.totalGears - 0))), 1f, CurveExtended.TangentMode.Smooth));
                motorScript.engineTorqueCurve[i].AddKey(motorScript.maxSpeed, 0);
                motorScript.engineTorqueCurve[i].postWrapMode = WrapMode.Clamp;
                motorScript.engineTorqueCurve[i].UpdateAllLinearTangents();
            }
            else
            {
                motorScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(25, motorScript.maxSpeed, ((float)i / (float)(motorScript.totalGears - 1))), 1.25f, TangentMode.Linear));
                motorScript.engineTorqueCurve[i].AddKey(KeyframeUtil.GetNew(Mathf.Lerp(25f, motorScript.maxSpeed, ((float)(i + 1) / (float)(motorScript.totalGears - 1))), 0, TangentMode.Linear));
                motorScript.engineTorqueCurve[i].AddKey(motorScript.maxSpeed, 0);
                motorScript.engineTorqueCurve[i].UpdateAllLinearTangents();
            }
        }
    }
示例#13
0
        // UnityEditor.CurveUtility.cs (c) Unity Technologies
        public static void UpdateTangentsFromMode(AnimationCurve curve, int index)
        {
            if (index < 0 || index >= curve.length)
            {
                return;
            }
            Keyframe key = curve[index];

            if (KeyframeUtil.GetKeyTangentMode(key, 0) == TangentMode.Linear && index >= 1)
            {
                key.inTangent = CalculateLinearTangent(curve, index, index - 1);
                curve.MoveKey(index, key);
            }
            if (KeyframeUtil.GetKeyTangentMode(key, 1) == TangentMode.Linear && index + 1 < curve.length)
            {
                key.outTangent = CalculateLinearTangent(curve, index, index + 1);
                curve.MoveKey(index, key);
            }
            if (KeyframeUtil.GetKeyTangentMode(key, 0) != TangentMode.Smooth && KeyframeUtil.GetKeyTangentMode(key, 1) != TangentMode.Smooth)
            {
                return;
            }
            curve.SmoothTangents(index, 0.0f);
        }
示例#14
0
        static void CreateSlotAnim(ArmatureEditor armatureEditor, AnimationClip clip, DragonBoneData.AnimSubData[] subDatas, Dictionary <string, Transform> transformKV)
        {
            for (int i = 0; i < subDatas.Length; ++i)
            {
                DragonBoneData.AnimSubData animSubData = subDatas[i];
                string    slotName = string.IsNullOrEmpty(animSubData.slot) ? animSubData.name : animSubData.slot;
                Transform slotNode = transformKV[slotName];
                DragonBoneData.SlotData  defaultSlotData  = armatureEditor.slotsDataKV[slotName];
                DragonBoneData.ColorData defaultColorData = defaultSlotData.color;

                AnimationCurve color_rcurve  = new AnimationCurve();
                AnimationCurve color_gcurve  = new AnimationCurve();
                AnimationCurve color_bcurve  = new AnimationCurve();
                AnimationCurve color_acurve  = new AnimationCurve();
                AnimationCurve display_curve = new AnimationCurve();

                float during      = animSubData.offset;
                float perKeyTime  = 1f / armatureEditor.armatureData.frameRate;
                bool  isHaveCurve = false;
                for (int j = 0; j < animSubData.frameDatas.Length; ++j)
                {
                    DragonBoneData.AnimFrameData frameData = animSubData.frameDatas[j];

                    float   prevTweeneasing = float.PositiveInfinity;                  //前一帧的tweenEasing
                    float[] prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSubData.frameDatas[j - 1].tweenEasing;
                        prevCurves      = animSubData.frameDatas[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (frameData.curve != null && frameData.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (frameData.tweenEasing == float.PositiveInfinity)
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else if (frameData.tweenEasing == 0)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                        else if (frameData.tweenEasing == 1)
                        {
                            tanModeR = TangentMode.Smooth;
                        }
                        else if (frameData.tweenEasing == 2)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }

                    if (frameData.color != null)
                    {
                        if (defaultColorData == null)
                        {
                            defaultColorData = new DragonBoneData.ColorData();
                        }
                        Color c = new Color(
                            frameData.color.rM + frameData.color.r0,
                            frameData.color.gM + frameData.color.g0,
                            frameData.color.bM + frameData.color.b0,
                            frameData.color.aM + frameData.color.a0
                            );
                        color_rcurve.AddKey(KeyframeUtil.GetNew(during, c.r, tanModeL, tanModeR));
                        color_gcurve.AddKey(KeyframeUtil.GetNew(during, c.g, tanModeL, tanModeR));
                        color_bcurve.AddKey(KeyframeUtil.GetNew(during, c.b, tanModeL, tanModeR));
                        color_acurve.AddKey(KeyframeUtil.GetNew(during, c.a, tanModeL, tanModeR));
                    }

                    //改displyindex
                    if (frameData.displayIndex > -2)
                    {
                        display_curve.AddKey(new Keyframe(during, frameData.displayIndex, float.PositiveInfinity, float.PositiveInfinity));
                    }

                    during += frameData.duration * perKeyTime;
                }

                CurveExtension.OptimizesCurve(color_rcurve);
                CurveExtension.OptimizesCurve(color_gcurve);
                CurveExtension.OptimizesCurve(color_bcurve);
                CurveExtension.OptimizesCurve(color_acurve);
                CurveExtension.OptimizesCurve(display_curve);

                string path = "";
                if (slotPathKV.ContainsKey(slotName))
                {
                    path = slotPathKV[slotName];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, slotNode);
                    slotPathKV[slotNode.name] = path;
                }

                if (defaultColorData == null)
                {
                    defaultColorData = new DragonBoneData.ColorData();
                }

                float da = defaultColorData.aM + defaultColorData.a0;
                float dr = defaultColorData.rM + defaultColorData.r0;
                float dg = defaultColorData.gM + defaultColorData.g0;
                float db = defaultColorData.bM + defaultColorData.b0;

                SetColorCurve <Slot>(path, clip, color_rcurve, "color.r", isHaveCurve, dr, animSubData.frameDatas);
                SetColorCurve <Slot>(path, clip, color_gcurve, "color.g", isHaveCurve, dg, animSubData.frameDatas);
                SetColorCurve <Slot>(path, clip, color_bcurve, "color.b", isHaveCurve, db, animSubData.frameDatas);
                SetColorCurve <Slot>(path, clip, color_acurve, "color.a", isHaveCurve, da, animSubData.frameDatas);

                if (display_curve.keys != null && display_curve.keys.Length > 0 &&
                    CheckCurveValid(display_curve, slotNode.GetComponent <Slot>().displayIndex))
                {
                    clip.SetCurve(path, typeof(Slot), "m_DisplayIndex", display_curve);
                }
            }
        }
示例#15
0
        public static void setCustomTangents(AnimationCurve curve, int i, int nextI, JsonData tangentArray)
        {
            float diffValue = curve[nextI].value - curve[i].value;
            float diffTime  = curve[nextI].time - curve[i].time;

            if (diffValue == 0)
            {
                return;
            }



            float   cx1    = parseFloat(tangentArray[0]);
            float   cy1    = parseFloat(tangentArray[1]);
            float   cx2    = parseFloat(tangentArray[2]);
            float   cy2    = parseFloat(tangentArray[3]);
            Vector2 p0     = new Vector2(0, curve[i].value);
            Vector2 p3     = new Vector2(diffTime, curve[nextI].value);
            Vector2 cOrig1 = new Vector2(diffTime * cx1, curve[i].value);

            cOrig1.y += diffValue > 0 ? diffValue * cy1 : -1.0f * Mathf.Abs(diffValue * cy1);

            Vector2 cOrig2 = new Vector2(diffTime * cx2, curve[i].value);

            cOrig2.y += diffValue > 0 ? diffValue * cy2 : -1.0f * Mathf.Abs(diffValue * cy2);

            Vector2 p1 = getBezierPoint(p0, cOrig1, cOrig2, p3, 1.0f / 3.0f);
            Vector2 p2 = getBezierPoint(p0, cOrig1, cOrig2, p3, 2.0f / 3.0f);


            Vector2 c1tg, c2tg, c1, c2;

            calcControlPoints(p0, p1, p2, p3, out c1, out c2);

            c1tg = c1 - p0;
            c2tg = c2 - p3;

            float outTangent = c1tg.y / c1tg.x;
            float inTangent  = c2tg.y / c2tg.x;


            object thisKeyframeBoxed = curve[i];
            object nextKeyframeBoxed = curve[nextI];


            if (!KeyframeUtil.isKeyBroken(thisKeyframeBoxed))
            {
                KeyframeUtil.SetKeyBroken(thisKeyframeBoxed, true);
            }
            KeyframeUtil.SetKeyTangentMode(thisKeyframeBoxed, 1, TangentMode.Editable);

            if (!KeyframeUtil.isKeyBroken(nextKeyframeBoxed))
            {
                KeyframeUtil.SetKeyBroken(nextKeyframeBoxed, true);
            }
            KeyframeUtil.SetKeyTangentMode(nextKeyframeBoxed, 0, TangentMode.Editable);

            Keyframe thisKeyframe = (Keyframe)thisKeyframeBoxed;
            Keyframe nextKeyframe = (Keyframe)nextKeyframeBoxed;

            thisKeyframe.outTangent = outTangent;
            nextKeyframe.inTangent  = inTangent;

            curve.MoveKey(i, thisKeyframe);
            curve.MoveKey(nextI, nextKeyframe);

            //* test method
            bool  ok        = true;
            float startTime = thisKeyframe.time;

            float epsilon = 0.001f;

            for (float j = 0; j < 25f; j++)
            {
                float   t          = j / 25.0f;
                Vector2 t1         = getBezierPoint(p0, cOrig1, cOrig2, p3, t);
                Vector2 t2         = getBezierPoint(p0, c1, c2, p3, t);
                float   curveValue = curve.Evaluate(startTime + diffTime * t);
                if (!NearlyEqual(t1.y, t2.y, epsilon) ||
                    !NearlyEqual(t2.y, curveValue, epsilon))
                {
                    Debug.LogError("time = " + t + "   t1 = [" + t1.y.ToString("N8") + "]   t2 = [" + t2.y.ToString("N8") + "]    curve = [" + curveValue.ToString("N8") + "]");
                    ok = false;
                }
            }
            if (!ok)
            {
                Debug.LogWarning("something wrong with bezier points");
            }
            //*/
        }
示例#16
0
        static void CreateFFDAnim(ArmatureEditor armatureEditor, AnimationClip clip, DragonBoneData.AnimSubData[] subDatas, Dictionary <string, Transform> transformKV)
        {
            if (subDatas == null)
            {
                return;
            }
            for (int i = 0; i < subDatas.Length; ++i)
            {
                DragonBoneData.AnimSubData animSubData = subDatas[i];
                string    slotName = string.IsNullOrEmpty(animSubData.slot) ? animSubData.name : animSubData.slot;
                Transform slotNode = transformKV[slotName];

                List <AnimationCurve[]> vertexcurvexArray = null;
                List <AnimationCurve[]> vertexcurveyArray = null;
                if (slotNode.childCount > 0)
                {
                    vertexcurvexArray = new List <AnimationCurve[]>();
                    vertexcurveyArray = new List <AnimationCurve[]>();
                    for (int j = 0; j < slotNode.childCount; ++j)
                    {
                        Transform ffdNode = slotNode.GetChild(j);
                        if (ffdNode.name == animSubData.name)
                        {
                            AnimationCurve[] vertex_xcurves = new AnimationCurve[ffdNode.childCount];
                            AnimationCurve[] vertex_ycurves = new AnimationCurve[ffdNode.childCount];
                            for (int r = 0; r < vertex_xcurves.Length; ++r)
                            {
                                vertex_xcurves[r] = new AnimationCurve();
                                vertex_ycurves[r] = new AnimationCurve();
                            }
                            vertexcurvexArray.Add(vertex_xcurves);
                            vertexcurveyArray.Add(vertex_ycurves);
                        }
                    }
                }

                float during      = animSubData.offset;
                float perKeyTime  = 1f / armatureEditor.armatureData.frameRate;
                bool  isHaveCurve = false;
                for (int j = 0; j < animSubData.frameDatas.Length; ++j)
                {
                    DragonBoneData.AnimFrameData frameData = animSubData.frameDatas[j];

                    float   prevTweeneasing = float.PositiveInfinity;                  //前一帧的tweenEasing
                    float[] prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSubData.frameDatas[j - 1].tweenEasing;
                        prevCurves      = animSubData.frameDatas[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (frameData.curve != null && frameData.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (frameData.tweenEasing == float.PositiveInfinity)
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else if (frameData.tweenEasing == 0)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                        else if (frameData.tweenEasing == 1)
                        {
                            tanModeR = TangentMode.Smooth;
                        }
                        else if (frameData.tweenEasing == 2)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }

                    //mesh animation
                    if (vertexcurvexArray != null)
                    {
                        for (int k = 0; k < vertexcurvexArray.Count; ++k)
                        {
                            Transform ffdNode = slotNode.GetChild(k);
                            if (ffdNode.name == animSubData.name)
                            {
                                AnimationCurve[] vertex_xcurves = vertexcurvexArray[k];
                                AnimationCurve[] vertex_ycurves = vertexcurveyArray[k];
                                int len = ffdNode.childCount;
                                if (frameData.vertices != null && frameData.vertices.Length > 0)
                                {
                                    for (int r = 0; r < len; ++r)
                                    {
                                        AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                        AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                        Transform      vCtr          = ffdNode.GetChild(r);                          //顶点控制点
                                        if (r >= frameData.offset && r - frameData.offset < frameData.vertices.Length)
                                        {
                                            Keyframe kfx = KeyframeUtil.GetNew(during, vCtr.localPosition.x + frameData.vertices[r - frameData.offset].x, tanModeL, tanModeR);
                                            vertex_xcurve.AddKey(kfx);
                                            Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y + frameData.vertices[r - frameData.offset].y, tanModeL, tanModeR);
                                            vertex_ycurve.AddKey(kfy);
                                        }
                                        else
                                        {
                                            Keyframe kfx = KeyframeUtil.GetNew(during, vCtr.localPosition.x, tanModeL, tanModeR);
                                            vertex_xcurve.AddKey(kfx);
                                            Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y, tanModeL, tanModeR);
                                            vertex_ycurve.AddKey(kfy);
                                        }
                                    }
                                }
                                else
                                {
                                    //add default vertex position
                                    for (int r = 0; r < len; ++r)
                                    {
                                        AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                        AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                        Transform      vCtr          = slotNode.GetChild(k).GetChild(r);                          //顶点控制点
                                        Keyframe       kfx           = KeyframeUtil.GetNew(during, vCtr.localPosition.x, tanModeL, tanModeR);
                                        vertex_xcurve.AddKey(kfx);
                                        Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y, tanModeL, tanModeR);
                                        vertex_ycurve.AddKey(kfy);
                                    }
                                }
                            }
                        }
                    }

                    during += frameData.duration * perKeyTime;
                }

                string path = "";
                if (slotPathKV.ContainsKey(slotName))
                {
                    path = slotPathKV[slotName];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, slotNode);
                    slotPathKV[slotName] = path;
                }

                if (vertexcurvexArray != null)
                {
                    for (int k = 0; k < vertexcurvexArray.Count; ++k)
                    {
                        Transform ffdNode = slotNode.GetChild(k);
                        if (ffdNode.name == animSubData.name)
                        {
                            changedSpriteMeshsKV[path + "/" + ffdNode.name] = ffdNode.GetComponent <SpriteMesh>();

                            AnimationCurve[] vertex_xcurves = vertexcurvexArray[k];
                            AnimationCurve[] vertex_ycurves = vertexcurveyArray[k];
                            for (int r = 0; r < vertex_xcurves.Length; ++r)
                            {
                                AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                Transform      v             = ffdNode.GetChild(r);
                                string         ctrlPath      = path + "/" + ffdNode.name + "/" + v.name;

                                CurveExtension.OptimizesCurve(vertex_xcurve);
                                CurveExtension.OptimizesCurve(vertex_ycurve);

                                bool vcurveFlag = false;
                                if (vertex_xcurve.keys != null && vertex_xcurve.keys.Length > 0 && CheckCurveValid(vertex_xcurve, v.localPosition.x))
                                {
                                    vcurveFlag = true;
                                }
                                if (vertex_ycurve.keys != null && vertex_ycurve.keys.Length > 0 && CheckCurveValid(vertex_ycurve, v.localPosition.y))
                                {
                                    vcurveFlag = true;
                                }
                                if (vcurveFlag)
                                {
                                    if (isHaveCurve)
                                    {
                                        SetCustomCurveTangents(vertex_xcurve, animSubData.frameDatas);
                                    }
                                    CurveExtension.UpdateAllLinearTangents(vertex_xcurve);
                                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.x"), vertex_xcurve);
                                    if (isHaveCurve)
                                    {
                                        SetCustomCurveTangents(vertex_ycurve, animSubData.frameDatas);
                                    }
                                    CurveExtension.UpdateAllLinearTangents(vertex_ycurve);
                                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.y"), vertex_ycurve);
                                }
                            }
                        }
                    }
                }
            }
        }
示例#17
0
        static void CreateBoneAnim(ArmatureEditor armatureEditor, AnimationClip clip, DragonBoneData.AnimSubData[] subDatas, Dictionary <string, Transform> transformKV)
        {
            if (subDatas == null)
            {
                return;
            }
            Dictionary <string, string> bonePathKV = new Dictionary <string, string>();

            for (int i = 0; i < subDatas.Length; ++i)
            {
                DragonBoneData.AnimSubData animSubData = subDatas[i];
                string    boneName = animSubData.name;
                Transform boneNode = transformKV[boneName];
                DragonBoneData.TransformData defaultTransformData = armatureEditor.bonesDataKV[animSubData.name].transform;

                AnimationCurve xcurve      = new AnimationCurve();
                AnimationCurve ycurve      = new AnimationCurve();
                AnimationCurve sxcurve     = new AnimationCurve();
                AnimationCurve sycurve     = new AnimationCurve();
                AnimationCurve rotatecurve = new AnimationCurve();

                float during      = animSubData.offset;
                float perKeyTime  = 1f / armatureEditor.armatureData.frameRate;
                bool  isHaveCurve = false;
                for (int j = 0; j < animSubData.frameDatas.Length; ++j)
                {
                    DragonBoneData.AnimFrameData frameData = animSubData.frameDatas[j];

                    float   prevTweeneasing = float.PositiveInfinity;                  //前一帧的tweenEasing
                    float[] prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSubData.frameDatas[j - 1].tweenEasing;
                        prevCurves      = animSubData.frameDatas[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (frameData.curve != null && frameData.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (frameData.tweenEasing == float.PositiveInfinity)
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else if (frameData.tweenEasing == 0)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                        else if (frameData.tweenEasing == 1)
                        {
                            tanModeR = TangentMode.Smooth;
                        }
                        else if (frameData.tweenEasing == 2)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }
                    if (frameData.transformData != null)
                    {
                        if (!float.IsNaN(frameData.transformData.x))
                        {
                            if (!float.IsNaN(defaultTransformData.x))
                            {
                                xcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.x + defaultTransformData.x, tanModeL, tanModeR));
                            }
                            else
                            {
                                xcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.x, tanModeL, tanModeR));
                            }
                        }
                        else if (!float.IsNaN(defaultTransformData.x))
                        {
                            xcurve.AddKey(KeyframeUtil.GetNew(during, defaultTransformData.x, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.y))
                        {
                            if (!float.IsNaN(defaultTransformData.y))
                            {
                                ycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.y + defaultTransformData.y, tanModeL, tanModeR));
                            }
                            else
                            {
                                ycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.y, tanModeL, tanModeR));
                            }
                        }
                        else if (!float.IsNaN(defaultTransformData.y))
                        {
                            ycurve.AddKey(KeyframeUtil.GetNew(during, defaultTransformData.y, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.rotate))
                        {
                            float rotate = frameData.transformData.rotate + defaultTransformData.rotate;
                            rotatecurve.AddKey(KeyframeUtil.GetNew(during, rotate, tanModeL, tanModeR));
                        }
                        else if (!float.IsNaN(defaultTransformData.rotate))
                        {
                            rotatecurve.AddKey(KeyframeUtil.GetNew(during, boneNode.localEulerAngles.z, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.scx))
                        {
                            sxcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.scx * defaultTransformData.scx, tanModeL, tanModeR));
                        }
                        else
                        {
                            sxcurve.AddKey(KeyframeUtil.GetNew(during, boneNode.localScale.x, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.scy))
                        {
                            sycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.scy * defaultTransformData.scy, tanModeL, tanModeR));
                        }
                        else
                        {
                            sycurve.AddKey(KeyframeUtil.GetNew(during, boneNode.localScale.y, tanModeL, tanModeR));
                        }
                    }
                    during += frameData.duration * perKeyTime;
                }

                CurveExtension.OptimizesCurve(xcurve);
                CurveExtension.OptimizesCurve(ycurve);
                CurveExtension.OptimizesCurve(sxcurve);
                CurveExtension.OptimizesCurve(sycurve);
                CurveExtension.OptimizesCurve(rotatecurve);

                string path = "";
                if (bonePathKV.ContainsKey(boneName))
                {
                    path = bonePathKV[boneName];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, boneNode);
                    bonePathKV[boneName] = path;
                }
                bool localPosFlag = false;
                if (xcurve.keys != null && xcurve.keys.Length > 0 && CheckCurveValid(xcurve, boneNode.localPosition.x))
                {
                    localPosFlag = true;
                }
                if (ycurve.keys != null && ycurve.keys.Length > 0 && CheckCurveValid(ycurve, boneNode.localPosition.y))
                {
                    localPosFlag = true;
                }
                if (localPosFlag)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(xcurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(xcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"), xcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(ycurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(ycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"), ycurve);
                }

                bool localSc = false;
                if (sxcurve.keys != null && sxcurve.keys.Length > 0 && CheckCurveValid(sxcurve, defaultTransformData.scx))
                {
                    localSc = true;
                }
                if (sycurve.keys != null && sycurve.keys.Length > 0 && CheckCurveValid(sycurve, defaultTransformData.scy))
                {
                    localSc = true;
                }
                if (localSc)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sxcurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(sxcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.x"), sxcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sycurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(sycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.y"), sycurve);
                }

                if (rotatecurve.keys != null && rotatecurve.keys.Length > 0 && CheckCurveValid(rotatecurve, defaultTransformData.rotate))
                {
                    CurveExtension.ClampCurveRotate360(rotatecurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(rotatecurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(rotatecurve);
                    clip.SetCurve(path, typeof(Transform), "localEulerAngles.z", rotatecurve);
                }
            }
        }
示例#18
0
        public static void addSlotAnimationToClip(AnimationClip clip,
                                                  Dictionary <string, SpineSlotAnimation> slotsAnimation,
                                                  SpineData spineData,
                                                  AttachmentGOByNameBySlot attachmentGOByNameBySlot)
        {
            foreach (KeyValuePair <string, SpineSlotAnimation> kvp in slotsAnimation)
            {
                string slotName          = kvp.Key;
                string defaultAttachment = spineData.slotDefaultAttachments[slotName];
                if (string.IsNullOrEmpty(defaultAttachment))
                {
                    continue;
                }
                SpineSlotAnimation slotAnimation = kvp.Value;
                if (slotAnimation.attachment != null && slotAnimation.attachment.Count > 0)
                {
                    Dictionary <string, AnimationCurve> curveByName = new Dictionary <string, AnimationCurve>();


                    for (int i = 0; i < slotAnimation.attachment.Count; i++)
                    {
                        bool nullAttachment = false;
                        SpineSlotAttachmentAnimation anim = slotAnimation.attachment[i];
                        if (string.IsNullOrEmpty(anim.name))
                        {
                            anim.name      = getFirstAttachmentName(slotAnimation);
                            nullAttachment = true;
                        }

                        if (anim.name.Equals(""))
                        {
                            continue;
                        }
                        AnimationCurve enableCurve;
                        if (curveByName.ContainsKey(anim.name))
                        {
                            enableCurve = curveByName[anim.name];
                        }
                        else
                        {
                            enableCurve = new AnimationCurve();
                            if (anim.time > 0.0f)
                            {
                                enableCurve.AddKey(KeyframeUtil.GetNew(0, 0.0f, TangentMode.Stepped));
                            }

                            curveByName.Add(anim.name, enableCurve);

                            if (i == 0 && !anim.name.Equals(defaultAttachment))
                            {
                                AnimationCurve defSlotCurve = new AnimationCurve();
                                curveByName.Add(defaultAttachment, defSlotCurve);

                                if (anim.time != 0.0f)
                                {
                                    defSlotCurve.AddKey(KeyframeUtil.GetNew(0, nullAttachment ? 0 : 1, TangentMode.Stepped));
                                    defSlotCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 0, TangentMode.Stepped));
                                }
                                else
                                {
                                    defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped));
                                }
                            }
                        }

                        enableCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, nullAttachment ? 0 : 1, TangentMode.Stepped));
                        if (i < (slotAnimation.attachment.Count - 1))
                        {
                            SpineSlotAttachmentAnimation nextAnim = slotAnimation.attachment[i + 1];
                            bool nullNextAttachment = false;
                            if (string.IsNullOrEmpty(nextAnim.name))
                            {
                                nextAnim.name      = getFirstAttachmentName(slotAnimation);
                                nullNextAttachment = true;
                            }

                            if (!nextAnim.name.Equals(anim.name) || nullNextAttachment)
                            {
                                enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped));
                            }
                        }
                    }
                    foreach (KeyValuePair <string, AnimationCurve> kvp2 in curveByName)
                    {
                        string         attachmentName = kvp2.Key;
                        AnimationCurve animationCurve = kvp2.Value;
                        string         attachmentPath = spineData.slotPathByName[slotName] + "/" + attachmentName.Replace("/", SLASH_REPLACEMENT);
                        clip.SetCurve(attachmentPath, typeof(GameObject), "m_IsActive", animationCurve);
                    }
                }

                if (slotAnimation.color != null && slotAnimation.color.Count > 0)
                {
                    Debug.LogWarning("slot color animation is not supported yet");
                }
            }
        }
示例#19
0
    public Keyframe createKey(float time, float value)
    {
        Keyframe tmp = KeyframeUtil.GetNew(time, value, TangentMode.Smooth, TangentMode.Smooth);

        return(tmp);
    }
示例#20
0
 public void UpdateView()
 {
     previousColor      = LightColor;
     transform.position = KeyframeUtil.GetPosition(Waypoints, Time, transform.position);
     LightColor         = KeyframeUtil.GetColor(ColorKeyframes, Time, LightColor);
 }
示例#21
0
        static void CreateAnimSlot(SpineArmatureEditor armatureEditor, AnimationClip clip, SpineData.AnimationSlotData[] animSlotDatas)
        {
            for (int i = 0; i < animSlotDatas.Length; ++i)
            {
                SpineData.AnimationSlotData animSlotData = animSlotDatas[i];
                string             slotName        = animSlotData.name;
                Transform          slot            = armatureEditor.slotsKV[slotName];
                SpineData.SlotData defaultSlotData = armatureEditor.slotsDataKV[slotName];
                Color defaultColorData             = defaultSlotData.color;

                AnimationCurve color_rcurve = new AnimationCurve();
                AnimationCurve color_gcurve = new AnimationCurve();
                AnimationCurve color_bcurve = new AnimationCurve();
                AnimationCurve color_acurve = new AnimationCurve();

                AnimationCurve display_curve = new AnimationCurve();

                bool isHaveCurve = false;
                for (int j = 0; j < animSlotData.timelines.Length; ++j)
                {
                    SpineData.SlotTimeline timeline = animSlotData.timelines[j];
                    string  prevTweeneasing         = "linear";           //前一帧的tweenEasing
                    float[] prevCurves = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSlotData.timelines[j - 1].tweenEasing;
                        prevCurves      = animSlotData.timelines[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (timeline.curve != null && timeline.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (timeline.tweenEasing == "stepped")
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }

                    if (timeline.type == "color")
                    {
                        if (!string.IsNullOrEmpty(timeline.color))
                        {
                            Color c = SpineArmatureEditor.HexToColor(timeline.color);
                            color_rcurve.AddKey(KeyframeUtil.GetNew(timeline.time, c.r, tanModeL, tanModeR));
                            color_gcurve.AddKey(KeyframeUtil.GetNew(timeline.time, c.g, tanModeL, tanModeR));
                            color_bcurve.AddKey(KeyframeUtil.GetNew(timeline.time, c.b, tanModeL, tanModeR));
                            color_acurve.AddKey(KeyframeUtil.GetNew(timeline.time, c.a, tanModeL, tanModeR));                         //*defaultColorData.a
                        }
                        else if (color_acurve.length > 0)
                        {
                            color_rcurve.AddKey(KeyframeUtil.GetNew(timeline.time, defaultColorData.r, tanModeL, tanModeR));
                            color_gcurve.AddKey(KeyframeUtil.GetNew(timeline.time, defaultColorData.g, tanModeL, tanModeR));
                            color_bcurve.AddKey(KeyframeUtil.GetNew(timeline.time, defaultColorData.b, tanModeL, tanModeR));
                            color_acurve.AddKey(KeyframeUtil.GetNew(timeline.time, defaultColorData.a, tanModeL, tanModeR));
                        }
                    }
                    else if (timeline.type == "attachment")
                    {
                        if (string.IsNullOrEmpty(timeline.attachmentName))
                        {
                            display_curve.AddKey(new Keyframe(timeline.time, -1f, float.PositiveInfinity, float.PositiveInfinity));
                        }
                        else
                        {
                            for (int r = 0; r < slot.childCount; ++r)
                            {
                                if (slot.GetChild(r).name.Equals(timeline.attachmentName))
                                {
                                    display_curve.AddKey(new Keyframe(timeline.time, r, float.PositiveInfinity, float.PositiveInfinity));
                                    break;
                                }
                            }
                        }
                    }
                }
                CurveExtension.OptimizesCurve(color_rcurve);
                CurveExtension.OptimizesCurve(color_gcurve);
                CurveExtension.OptimizesCurve(color_bcurve);
                CurveExtension.OptimizesCurve(color_acurve);
                CurveExtension.OptimizesCurve(display_curve);

                string path = "";
                if (slotPathKV.ContainsKey(slot.name))
                {
                    path = slotPathKV[slot.name];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, slot);
                    slotPathKV[slot.name] = path;
                }

                SetColorCurve <Slot>(path, clip, color_rcurve, "color.r", isHaveCurve, defaultColorData.r, animSlotData.timelines);
                SetColorCurve <Slot>(path, clip, color_gcurve, "color.g", isHaveCurve, defaultColorData.g, animSlotData.timelines);
                SetColorCurve <Slot>(path, clip, color_bcurve, "color.b", isHaveCurve, defaultColorData.b, animSlotData.timelines);
                SetColorCurve <Slot>(path, clip, color_acurve, "color.a", isHaveCurve, defaultColorData.a, animSlotData.timelines);

                //add pose
                AnimationCurve pose_color_rcurve = new AnimationCurve();
                AnimationCurve pose_color_gcurve = new AnimationCurve();
                AnimationCurve pose_color_bcurve = new AnimationCurve();
                AnimationCurve pose_color_acurve = new AnimationCurve();
                pose_color_rcurve.AddKey(new Keyframe(0f, defaultColorData.r));
                pose_color_gcurve.AddKey(new Keyframe(0f, defaultColorData.g));
                pose_color_bcurve.AddKey(new Keyframe(0f, defaultColorData.b));
                pose_color_acurve.AddKey(new Keyframe(0f, defaultColorData.a));
                AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Slot), "color.r"), pose_color_rcurve);
                AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Slot), "color.g"), pose_color_gcurve);
                AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Slot), "color.b"), pose_color_bcurve);
                AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Slot), "color.a"), pose_color_acurve);

                if (display_curve.keys != null && display_curve.keys.Length > 0 &&
                    CheckCurveValid(display_curve, slot.GetComponent <Slot>().displayIndex))
                {
                    clip.SetCurve(path, typeof(Slot), "m_DisplayIndex", display_curve);
                    //add pose
                    AnimationCurve pose_display_curve = new AnimationCurve();
                    pose_display_curve.AddKey(new Keyframe(0f, slot.GetComponent <Slot>().displayIndex));
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Slot), "m_DisplayIndex"), pose_display_curve);
                }
            }
        }
示例#22
0
        static void CreateAnimDeform(SpineArmatureEditor armatureEditor, AnimationClip clip, SpineData.AnimationDeformData[] animDeformDatas)
        {
            string[] skins     = armatureEditor.armature.GetComponent <Armature>().skins;
            bool     multiSkin = (skins == null || skins.Length <= 1)? false : true;

            for (int i = 0; i < animDeformDatas.Length; ++i)
            {
                SpineData.AnimationDeformData animDeformData = animDeformDatas[i];
                if (animDeformData.timelines == null || animDeformData.timelines.Length == 0)
                {
                    continue;
                }

                Dictionary <string, AnimationCurve[]> xCurveKV = new Dictionary <string, AnimationCurve[]>();             //key is attachment name
                Dictionary <string, AnimationCurve[]> yCurveKV = new Dictionary <string, AnimationCurve[]>();

                Transform slot = armatureEditor.slotsKV[animDeformData.slotName];

                bool isHaveCurve = false;
                for (int j = 0; j < animDeformData.timelines.Length; ++j)
                {
                    SpineData.DeformTimeline timeline = animDeformData.timelines[j];
                    Transform attachment      = multiSkin? slot.Find(animDeformData.skinName + "/" + timeline.attachment) : slot.Find(timeline.attachment);
                    string    prevTweeneasing = "linear";                 //前一帧的tweenEasing
                    float[]   prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animDeformData.timelines[j - 1].tweenEasing;
                        prevCurves      = animDeformData.timelines[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (timeline.curve != null && timeline.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (timeline.tweenEasing == "stepped")
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }
                    if (!xCurveKV.ContainsKey(timeline.attachment))
                    {
                        xCurveKV[timeline.attachment] = new AnimationCurve[attachment.childCount];
                        yCurveKV[timeline.attachment] = new AnimationCurve[attachment.childCount];
                    }
                    AnimationCurve[] xCurveArray = xCurveKV[timeline.attachment];
                    AnimationCurve[] yCurveArray = yCurveKV[timeline.attachment];

                    int len = attachment.childCount;
                    if (timeline.vertices != null && timeline.vertices.Length > 0)
                    {
                        for (int r = 0; r < len; ++r)
                        {
                            if (xCurveArray[r] == null)
                            {
                                xCurveArray[r] = new AnimationCurve();
                                yCurveArray[r] = new AnimationCurve();
                            }
                            AnimationCurve xCurve = xCurveArray[r];
                            AnimationCurve yCurve = yCurveArray[r];

                            Transform vCtr = attachment.GetChild(r);                            //vertex control
                            if (r >= timeline.offset && r - timeline.offset < timeline.vertices.Length)
                            {
                                Vector3 v = timeline.vertices[r - timeline.offset];
                                v += vCtr.localPosition;
                                Keyframe kfx = KeyframeUtil.GetNew(timeline.time, v.x, tanModeL, tanModeR);
                                xCurve.AddKey(kfx);
                                Keyframe kfy = KeyframeUtil.GetNew(timeline.time, v.y, tanModeL, tanModeR);
                                yCurve.AddKey(kfy);
                            }
                            else
                            {
                                Keyframe kfx = KeyframeUtil.GetNew(timeline.time, vCtr.localPosition.x, tanModeL, tanModeR);
                                xCurve.AddKey(kfx);
                                Keyframe kfy = KeyframeUtil.GetNew(timeline.time, vCtr.localPosition.y, tanModeL, tanModeR);
                                yCurve.AddKey(kfy);
                            }
                        }
                    }
                    else
                    {
                        //add default vertex position
                        for (int r = 0; r < len; ++r)
                        {
                            if (xCurveArray[r] == null)
                            {
                                xCurveArray[r] = new AnimationCurve();
                                yCurveArray[r] = new AnimationCurve();
                            }
                            AnimationCurve xCurve = xCurveArray[r];
                            AnimationCurve yCurve = yCurveArray[r];

                            Transform vCtr = attachment.GetChild(r);                            //vertex control
                            Keyframe  kfx  = KeyframeUtil.GetNew(timeline.time, vCtr.localPosition.x, tanModeL, tanModeR);
                            xCurve.AddKey(kfx);
                            Keyframe kfy = KeyframeUtil.GetNew(timeline.time, vCtr.localPosition.y, tanModeL, tanModeR);
                            yCurve.AddKey(kfy);
                        }
                    }
                }
                string path = "";
                if (slotPathKV.ContainsKey(slot.name))
                {
                    path = slotPathKV[slot.name];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, slot);
                    slotPathKV[slot.name] = path;
                }
                if (multiSkin)
                {
                    path += "/" + animDeformData.skinName;
                }

                foreach (string attachmentName in xCurveKV.Keys)
                {
                    AnimationCurve[] vertex_xcurves = xCurveKV[attachmentName];
                    AnimationCurve[] vertex_ycurves = yCurveKV[attachmentName];

                    Transform attachment = multiSkin? slot.Find(animDeformData.skinName + "/" + attachmentName) : slot.Find(attachmentName);
                    int       len        = attachment.childCount;
                    for (int r = 0; r < len; ++r)
                    {
                        AnimationCurve vertex_xcurve = vertex_xcurves[r];
                        AnimationCurve vertex_ycurve = vertex_ycurves[r];
                        Transform      v             = attachment.GetChild(r);
                        string         ctrlPath      = path + "/" + attachment.name + "/" + v.name;

                        CurveExtension.OptimizesCurve(vertex_xcurve);
                        CurveExtension.OptimizesCurve(vertex_ycurve);

                        bool vcurveFlag = false;
                        if (vertex_xcurve.keys != null && vertex_xcurve.keys.Length > 0 && CheckCurveValid(vertex_xcurve, v.localPosition.x))
                        {
                            vcurveFlag = true;
                        }
                        if (vertex_ycurve.keys != null && vertex_ycurve.keys.Length > 0 && CheckCurveValid(vertex_ycurve, v.localPosition.y))
                        {
                            vcurveFlag = true;
                        }
                        if (vcurveFlag)
                        {
                            if (isHaveCurve)
                            {
                                SetCustomCurveTangents(vertex_xcurve, animDeformData.timelines);
                            }
                            CurveExtension.UpdateAllLinearTangents(vertex_xcurve);
                            AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.x"), vertex_xcurve);
                            if (isHaveCurve)
                            {
                                SetCustomCurveTangents(vertex_ycurve, animDeformData.timelines);
                            }
                            CurveExtension.UpdateAllLinearTangents(vertex_ycurve);
                            AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.y"), vertex_ycurve);

                            //add pose
                            AnimationCurve pose_vertex_xcurve = new AnimationCurve();
                            AnimationCurve pose_vertex_ycurve = new AnimationCurve();
                            pose_vertex_xcurve.AddKey(new Keyframe(0f, v.localPosition.x));
                            pose_vertex_ycurve.AddKey(new Keyframe(0f, v.localPosition.y));
                            AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.x"), pose_vertex_xcurve);
                            AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.y"), pose_vertex_ycurve);
                        }
                    }
                }
            }
        }
示例#23
0
        static bool CreateAnimBone(SpineArmatureEditor armatureEditor, AnimationClip clip, SpineData.AnimationBoneData[] animBoneDatas)
        {
            Dictionary <string, string> bonePathKV = new Dictionary <string, string>();

            for (int i = 0; i < animBoneDatas.Length; ++i)
            {
                SpineData.AnimationBoneData animBoneData = animBoneDatas[i];
                Transform bone = armatureEditor.bonesKV[animBoneData.name];

                AnimationCurve xcurve      = new AnimationCurve();
                AnimationCurve ycurve      = new AnimationCurve();
                AnimationCurve sxcurve     = new AnimationCurve();
                AnimationCurve sycurve     = new AnimationCurve();
                AnimationCurve rotatecurve = new AnimationCurve();

                bool isHaveCurve = false;
                for (int j = 0; j < animBoneData.timelines.Length; ++j)
                {
                    SpineData.BoneTimeline timeline = animBoneData.timelines[j];
                    string  prevTweeneasing         = "linear";           //前一帧的tweenEasing
                    float[] prevCurves = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animBoneData.timelines[j - 1].tweenEasing;
                        prevCurves      = animBoneData.timelines[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (timeline.curve != null && timeline.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (timeline.tweenEasing == "stepped")
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }
                    if (timeline.type == "rotate")                 //rotate,scale,translate,shear
                    {
                        if (!float.IsNaN(timeline.angle))
                        {
                            float rotate = timeline.angle + bone.localEulerAngles.z;
                            rotatecurve.AddKey(KeyframeUtil.GetNew(timeline.time, rotate, tanModeL, tanModeR));
                        }
                    }
                    else if (timeline.type == "translate")
                    {
                        if (!float.IsNaN(timeline.x))
                        {
                            xcurve.AddKey(KeyframeUtil.GetNew(timeline.time, timeline.x + bone.localPosition.x, tanModeL, tanModeR));
                        }
                        if (!float.IsNaN(timeline.y))
                        {
                            ycurve.AddKey(KeyframeUtil.GetNew(timeline.time, timeline.y + bone.localPosition.y, tanModeL, tanModeR));
                        }
                    }
                    else if (timeline.type == "scale")
                    {
                        if (!float.IsNaN(timeline.x))
                        {
                            sxcurve.AddKey(KeyframeUtil.GetNew(timeline.time, timeline.x * bone.localScale.x, tanModeL, tanModeR));
                        }
                        if (!float.IsNaN(timeline.y))
                        {
                            sycurve.AddKey(KeyframeUtil.GetNew(timeline.time, timeline.y * bone.localScale.y, tanModeL, tanModeR));
                        }
                    }
                }
                CurveExtension.OptimizesCurve(xcurve);
                CurveExtension.OptimizesCurve(ycurve);
                CurveExtension.OptimizesCurve(sxcurve);
                CurveExtension.OptimizesCurve(sycurve);
                CurveExtension.OptimizesCurve(rotatecurve);

                string path = "";
                if (bonePathKV.ContainsKey(bone.name))
                {
                    path = bonePathKV[bone.name];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, bone);
                    bonePathKV[bone.name] = path;

                    if (slotPathKV.ContainsKey(bone.name) && slotPathKV[bone.name].Equals(path))
                    {
                        Debug.LogError("Bone2D Error: Name conflict ->" + path);
                        return(false);
                    }
                }

                bool localPosFlag = false;
                if (xcurve.keys != null && xcurve.keys.Length > 0 && CheckCurveValid(xcurve, bone.localPosition.x))
                {
                    localPosFlag = true;
                }
                if (ycurve.keys != null && ycurve.keys.Length > 0 && CheckCurveValid(ycurve, bone.localPosition.y))
                {
                    localPosFlag = true;
                }
                if (localPosFlag)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(xcurve, animBoneData.timelines);
                    }
                    CurveExtension.UpdateAllLinearTangents(xcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"), xcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(ycurve, animBoneData.timelines);
                    }
                    CurveExtension.UpdateAllLinearTangents(ycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"), ycurve);

                    //add pose
                    AnimationCurve posexcurve = new AnimationCurve();
                    AnimationCurve poseycurve = new AnimationCurve();
                    posexcurve.AddKey(new Keyframe(0f, bone.localPosition.x));
                    poseycurve.AddKey(new Keyframe(0f, bone.localPosition.y));
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"), posexcurve);
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"), poseycurve);
                }

                Bone   myBone = bone.GetComponent <Bone>();
                string scPath = path;
                if (myBone && myBone.inheritScale)
                {
                    scPath = myBone.inheritScale.name;
                }
                bool localSc = false;
                if (sxcurve.keys != null && sxcurve.keys.Length > 0 && CheckCurveValid(sxcurve, bone.localScale.x))
                {
                    localSc = true;
                }
                if (sycurve.keys != null && sycurve.keys.Length > 0 && CheckCurveValid(sycurve, bone.localScale.y))
                {
                    localSc = true;
                }
                if (localSc)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sxcurve, animBoneData.timelines);
                    }
                    CurveExtension.UpdateAllLinearTangents(sxcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(scPath, typeof(Transform), "m_LocalScale.x"), sxcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sycurve, animBoneData.timelines);
                    }
                    CurveExtension.UpdateAllLinearTangents(sycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(scPath, typeof(Transform), "m_LocalScale.y"), sycurve);

                    //add pose
                    AnimationCurve posesxcurve = new AnimationCurve();
                    AnimationCurve posesycurve = new AnimationCurve();
                    posesxcurve.AddKey(new Keyframe(0f, bone.localScale.x));
                    posesycurve.AddKey(new Keyframe(0f, bone.localScale.y));
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.x"), posesxcurve);
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.y"), posesycurve);
                }

                string rotatePath = path;
                if (myBone && myBone.inheritRotation)
                {
                    rotatePath = myBone.inheritRotation.name;
                }
                if (rotatecurve.keys != null && rotatecurve.keys.Length > 0 && CheckCurveValid(rotatecurve, bone.localEulerAngles.z))
                {
                    CurveExtension.ClampCurveRotate360(rotatecurve, false);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(rotatecurve, animBoneData.timelines);
                    }
                    CurveExtension.UpdateAllLinearTangents(rotatecurve);
                    clip.SetCurve(rotatePath, typeof(Transform), "localEulerAngles.z", rotatecurve);

                    //add pose
                    AnimationCurve posesrotatecurve = new AnimationCurve();
                    posesrotatecurve.AddKey(new Keyframe(0f, bone.localEulerAngles.z));
                    AnimationUtility.SetEditorCurve(poseClip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "localEulerAngles.z"), posesrotatecurve);
                }
            }
            return(true);
        }
示例#24
0
        static void CreateAnimBoneAndSlot(ArmatureEditor armatureEditor, AnimationClip clip, DragonBoneData.AnimSubData[] subDatas, Dictionary <string, Transform> transformKV, bool boneOrSlot, bool isffd = false)
        {
            for (int i = 0; i < subDatas.Length; ++i)
            {
                DragonBoneData.AnimSubData animSubData = subDatas[i];
                string    name = string.IsNullOrEmpty(animSubData.slot) ? animSubData.name : animSubData.slot;
                Transform node = transformKV[name];
                DragonBoneData.TransformData defaultTransformData = boneOrSlot ? armatureEditor.bonesDataKV[animSubData.name].transform:null;
                float defaultZ = boneOrSlot ? 0: armatureEditor.slotsDataKV[name].z;;
                DragonBoneData.SlotData  defaultSlotData  = boneOrSlot ? null:armatureEditor.slotsDataKV[name];
                DragonBoneData.ColorData defaultColorData = boneOrSlot ? null: defaultSlotData.color;
                AnimationCurve           xcurve           = new AnimationCurve();
                AnimationCurve           ycurve           = new AnimationCurve();
                AnimationCurve           zcurve           = new AnimationCurve();
                AnimationCurve           sxcurve          = new AnimationCurve();
                AnimationCurve           sycurve          = new AnimationCurve();
                AnimationCurve           color_rcurve     = new AnimationCurve();
                AnimationCurve           color_gcurve     = new AnimationCurve();
                AnimationCurve           color_bcurve     = new AnimationCurve();
                AnimationCurve           color_acurve     = new AnimationCurve();
                AnimationCurve           rotatecurve      = new AnimationCurve();

                Renderer[]       renders      = node.GetComponentsInChildren <Renderer>();
                AnimationCurve[] renderCurves = new AnimationCurve[renders.Length];
                for (int r = 0; r < renderCurves.Length; ++r)
                {
                    renderCurves[r] = new AnimationCurve();
                }

                List <AnimationCurve[]> vertexcurvexArray = null;
                List <AnimationCurve[]> vertexcurveyArray = null;
                if (isffd && node.childCount > 0)
                {
                    vertexcurvexArray = new List <AnimationCurve[]>();
                    vertexcurveyArray = new List <AnimationCurve[]>();

                    for (int j = 0; j < node.childCount; ++j)
                    {
                        Transform ffdNode = node.GetChild(j);
                        if (ffdNode.name == animSubData.name)
                        {
                            AnimationCurve[] vertex_xcurves = new AnimationCurve[ffdNode.childCount];
                            AnimationCurve[] vertex_ycurves = new AnimationCurve[ffdNode.childCount];
                            for (int r = 0; r < vertex_xcurves.Length; ++r)
                            {
                                vertex_xcurves[r] = new AnimationCurve();
                                vertex_ycurves[r] = new AnimationCurve();
                            }
                            vertexcurvexArray.Add(vertex_xcurves);
                            vertexcurveyArray.Add(vertex_ycurves);
                        }
                    }
                }

                float during      = animSubData.offset;
                float perKeyTime  = 1f / armatureEditor.armatureData.frameRate;
                bool  isHaveCurve = false;
                for (int j = 0; j < animSubData.frameDatas.Length; ++j)
                {
                    DragonBoneData.AnimFrameData frameData = animSubData.frameDatas[j];

                    float   prevTweeneasing = float.PositiveInfinity;                  //前一帧的tweenEasing
                    float[] prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSubData.frameDatas[j - 1].tweenEasing;
                        prevCurves      = animSubData.frameDatas[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (frameData.curve != null && frameData.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (frameData.tweenEasing == float.PositiveInfinity)
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else if (frameData.tweenEasing == 0)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                        else if (frameData.tweenEasing == 1)
                        {
                            tanModeR = TangentMode.Smooth;
                        }
                        else if (frameData.tweenEasing == 2)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }
                    if (frameData.transformData != null)
                    {
                        if (!float.IsNaN(frameData.transformData.x))
                        {
                            if (!float.IsNaN(defaultTransformData.x))
                            {
                                xcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.x + defaultTransformData.x, tanModeL, tanModeR));
                            }
                            else
                            {
                                xcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.x, tanModeL, tanModeR));
                            }
                        }
                        else if (!float.IsNaN(defaultTransformData.x))
                        {
                            xcurve.AddKey(KeyframeUtil.GetNew(during, defaultTransformData.x, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.y))
                        {
                            if (!float.IsNaN(defaultTransformData.y))
                            {
                                ycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.y + defaultTransformData.y, tanModeL, tanModeR));
                            }
                            else
                            {
                                ycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.y, tanModeL, tanModeR));
                            }
                        }
                        else if (!float.IsNaN(defaultTransformData.y))
                        {
                            ycurve.AddKey(KeyframeUtil.GetNew(during, defaultTransformData.y, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.z))
                        {
                            zcurve.AddKey(new Keyframe(during, frameData.z, float.PositiveInfinity, float.PositiveInfinity));
                        }
                        else if (!boneOrSlot)
                        {
                            zcurve.AddKey(new Keyframe(during, node.localPosition.z, float.PositiveInfinity, float.PositiveInfinity));
                        }

                        if (!float.IsNaN(frameData.transformData.rotate))
                        {
                            float rotate = frameData.transformData.rotate + defaultTransformData.rotate;
                            rotatecurve.AddKey(KeyframeUtil.GetNew(during, rotate, tanModeL, tanModeR));
                        }
                        else if (!float.IsNaN(defaultTransformData.rotate))
                        {
                            rotatecurve.AddKey(KeyframeUtil.GetNew(during, node.localEulerAngles.z, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.scx))
                        {
                            sxcurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.scx * defaultTransformData.scx, tanModeL, tanModeR));
                        }
                        else
                        {
                            sxcurve.AddKey(KeyframeUtil.GetNew(during, node.localScale.x, tanModeL, tanModeR));
                        }

                        if (!float.IsNaN(frameData.transformData.scy))
                        {
                            sycurve.AddKey(KeyframeUtil.GetNew(during, frameData.transformData.scy * defaultTransformData.scy, tanModeL, tanModeR));
                        }
                        else
                        {
                            sycurve.AddKey(KeyframeUtil.GetNew(during, node.localScale.y, tanModeL, tanModeR));
                        }
                    }
                    if (!boneOrSlot)
                    {
                        if (frameData.color != null)
                        {
                            if (defaultColorData == null)
                            {
                                defaultColorData = new DragonBoneData.ColorData();
                            }
                            Color c = new Color(
                                frameData.color.rM + frameData.color.r0,
                                frameData.color.gM + frameData.color.g0,
                                frameData.color.bM + frameData.color.b0,
                                frameData.color.aM + frameData.color.a0
                                );
                            color_rcurve.AddKey(KeyframeUtil.GetNew(during, c.r, tanModeL, tanModeR));
                            color_gcurve.AddKey(KeyframeUtil.GetNew(during, c.g, tanModeL, tanModeR));
                            color_bcurve.AddKey(KeyframeUtil.GetNew(during, c.b, tanModeL, tanModeR));
                            color_acurve.AddKey(KeyframeUtil.GetNew(during, c.a, tanModeL, tanModeR));
                        }

                        if (!isffd)
                        {
                            //改displyindex
                            if (frameData.displayIndex == -1)
                            {
                                for (int r = 0; r < renders.Length; ++r)
                                {
                                    renderCurves[r].AddKey(new Keyframe(during, 0f, float.PositiveInfinity, float.PositiveInfinity));
                                }
                            }
                            else
                            {
                                for (int r = 0; r < renders.Length; ++r)
                                {
                                    if (r != frameData.displayIndex)
                                    {
                                        renderCurves[r].AddKey(new Keyframe(during, 0f, float.PositiveInfinity, float.PositiveInfinity));
                                    }
                                    else
                                    {
                                        renderCurves[r].AddKey(new Keyframe(during, 1f, float.PositiveInfinity, float.PositiveInfinity));
                                    }
                                }
                            }
                        }
                    }


                    //mesh animation
                    if (isffd && vertexcurvexArray != null)
                    {
                        for (int k = 0; k < vertexcurvexArray.Count; ++k)
                        {
                            Transform ffdNode = node.GetChild(k);
                            if (ffdNode.name == animSubData.name)
                            {
                                AnimationCurve[] vertex_xcurves = vertexcurvexArray[k];
                                AnimationCurve[] vertex_ycurves = vertexcurveyArray[k];
                                int len = ffdNode.childCount;
                                if (frameData.vertices != null && frameData.vertices.Length > 0)
                                {
                                    for (int r = 0; r < len; ++r)
                                    {
                                        AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                        AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                        Transform      vCtr          = ffdNode.GetChild(r);                          //顶点控制点
                                        if (r >= frameData.offset && r - frameData.offset < frameData.vertices.Length)
                                        {
                                            Keyframe kfx = KeyframeUtil.GetNew(during, vCtr.localPosition.x + frameData.vertices[r - frameData.offset].x, tanModeL, tanModeR);
                                            vertex_xcurve.AddKey(kfx);
                                            Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y + frameData.vertices[r - frameData.offset].y, tanModeL, tanModeR);
                                            vertex_ycurve.AddKey(kfy);
                                        }
                                        else
                                        {
                                            Keyframe kfx = KeyframeUtil.GetNew(during, vCtr.localPosition.x, tanModeL, tanModeR);
                                            vertex_xcurve.AddKey(kfx);
                                            Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y, tanModeL, tanModeR);
                                            vertex_ycurve.AddKey(kfy);
                                        }
                                    }
                                }
                                else
                                {
                                    //add default vertex position
                                    for (int r = 0; r < len; ++r)
                                    {
                                        AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                        AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                        Transform      vCtr          = node.GetChild(k).GetChild(r);                          //顶点控制点
                                        Keyframe       kfx           = KeyframeUtil.GetNew(during, vCtr.localPosition.x, tanModeL, tanModeR);
                                        vertex_xcurve.AddKey(kfx);
                                        Keyframe kfy = KeyframeUtil.GetNew(during, vCtr.localPosition.y, tanModeL, tanModeR);
                                        vertex_ycurve.AddKey(kfy);
                                    }
                                }
                            }
                        }
                    }

                    during += frameData.duration * perKeyTime;
                }

                CurveExtension.OptimizesCurve(xcurve);
                CurveExtension.OptimizesCurve(ycurve);
                CurveExtension.OptimizesCurve(zcurve);
                CurveExtension.OptimizesCurve(sxcurve);
                CurveExtension.OptimizesCurve(sycurve);
                CurveExtension.OptimizesCurve(color_rcurve);
                CurveExtension.OptimizesCurve(color_gcurve);
                CurveExtension.OptimizesCurve(color_bcurve);
                CurveExtension.OptimizesCurve(color_acurve);
                CurveExtension.OptimizesCurve(rotatecurve);


                string path         = GetNodeRelativePath(armatureEditor, node);
                bool   localPosFlag = false;
                if (xcurve.keys != null && xcurve.keys.Length > 0 && CheckCurveValid(xcurve, node.localPosition.x))
                {
                    localPosFlag = true;
                }
                if (ycurve.keys != null && ycurve.keys.Length > 0 && CheckCurveValid(ycurve, node.localPosition.y))
                {
                    localPosFlag = true;
                }
                if (zcurve.keys != null && zcurve.keys.Length > 0 && CheckCurveValid(zcurve, defaultZ))
                {
                    localPosFlag = true;
                }
                if (localPosFlag)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(xcurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(xcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.x"), xcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(ycurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(ycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalPosition.y"), ycurve);
                }

                bool localSc = false;
                if (sxcurve.keys != null && sxcurve.keys.Length > 0 && CheckCurveValid(sxcurve, defaultTransformData.scx))
                {
                    localSc = true;
                }
                if (sycurve.keys != null && sycurve.keys.Length > 0 && CheckCurveValid(sycurve, defaultTransformData.scy))
                {
                    localSc = true;
                }
                if (localSc)
                {
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sxcurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(sxcurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.x"), sxcurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(sycurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(sycurve);
                    AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(path, typeof(Transform), "m_LocalScale.y"), sycurve);
                }

                if (rotatecurve.keys != null && rotatecurve.keys.Length > 0 && CheckCurveValid(rotatecurve, defaultTransformData.rotate))
                {
                    CurveExtension.ClampCurveRotate360(rotatecurve);
                    if (isHaveCurve)
                    {
                        SetCustomCurveTangents(rotatecurve, animSubData.frameDatas);
                    }
                    CurveExtension.UpdateAllLinearTangents(rotatecurve);
                    clip.SetCurve(path, typeof(Transform), "localEulerAngles.z", rotatecurve);
                }

                if (!boneOrSlot)
                {
                    if (defaultColorData == null)
                    {
                        defaultColorData = new DragonBoneData.ColorData();
                    }

                    float da = defaultColorData.aM + defaultColorData.a0;
                    float dr = defaultColorData.rM + defaultColorData.r0;
                    float dg = defaultColorData.gM + defaultColorData.g0;
                    float db = defaultColorData.bM + defaultColorData.b0;
                    if (armatureEditor.useUnitySprite)
                    {
                        SpriteRenderer[] sprites = node.GetComponentsInChildren <SpriteRenderer>();
                        if (sprites != null)
                        {
                            for (int z = 0; z < sprites.Length; ++z)
                            {
                                string childPath = path + "/" + sprites[z].name;
                                SetColorCurve <SpriteRenderer>(childPath, clip, color_rcurve, "m_Color.r", isHaveCurve, dr, animSubData.frameDatas);
                                SetColorCurve <SpriteRenderer>(childPath, clip, color_gcurve, "m_Color.g", isHaveCurve, dg, animSubData.frameDatas);
                                SetColorCurve <SpriteRenderer>(childPath, clip, color_bcurve, "m_Color.b", isHaveCurve, db, animSubData.frameDatas);
                                SetColorCurve <SpriteRenderer>(childPath, clip, color_acurve, "m_Color.a", isHaveCurve, da, animSubData.frameDatas);
                            }
                        }
                    }
                    else
                    {
                        SpriteFrame[] sprites = node.GetComponentsInChildren <SpriteFrame>();
                        if (sprites != null)
                        {
                            for (int z = 0; z < sprites.Length; ++z)
                            {
                                string childPath = path + "/" + sprites[z].name;
                                bool   anim_r    = SetColorCurve <SpriteFrame>(childPath, clip, color_rcurve, "m_color.r", isHaveCurve, dr, animSubData.frameDatas);
                                bool   anim_g    = SetColorCurve <SpriteFrame>(childPath, clip, color_gcurve, "m_color.g", isHaveCurve, dg, animSubData.frameDatas);
                                bool   anim_b    = SetColorCurve <SpriteFrame>(childPath, clip, color_bcurve, "m_color.b", isHaveCurve, db, animSubData.frameDatas);
                                bool   anim_a    = SetColorCurve <SpriteFrame>(childPath, clip, color_acurve, "m_color.a", isHaveCurve, da, animSubData.frameDatas);
                                if (anim_r || anim_g || anim_b || anim_a)
                                {
                                    changedSpriteFramesKV[childPath] = sprites[z];
                                }
                            }
                        }

                        SpriteMesh[] spriteMeshs = node.GetComponentsInChildren <SpriteMesh>();
                        if (spriteMeshs != null)
                        {
                            for (int z = 0; z < spriteMeshs.Length; ++z)
                            {
                                string childPath = path + "/" + spriteMeshs[z].name;
                                bool   anim_r    = SetColorCurve <SpriteMesh>(childPath, clip, color_rcurve, "m_color.r", isHaveCurve, da, animSubData.frameDatas);
                                bool   anim_g    = SetColorCurve <SpriteMesh>(childPath, clip, color_gcurve, "m_color.g", isHaveCurve, dg, animSubData.frameDatas);
                                bool   anim_b    = SetColorCurve <SpriteMesh>(childPath, clip, color_bcurve, "m_color.b", isHaveCurve, db, animSubData.frameDatas);
                                bool   anim_a    = SetColorCurve <SpriteMesh>(childPath, clip, color_acurve, "m_color.a", isHaveCurve, da, animSubData.frameDatas);
                                if (anim_r || anim_g || anim_b || anim_a)
                                {
                                    changedSpriteMeshsKV[childPath] = spriteMeshs[z];
                                }
                            }
                        }
                    }

                    for (int r = 0; r < renderCurves.Length; ++r)
                    {
                        AnimationCurve ac           = renderCurves[r];
                        Renderer       render       = renders[r];
                        float          defaultValue = render.enabled? 1: 0;
                        if (ac.keys != null && ac.keys.Length > 0 && CheckCurveValid(ac, defaultValue))
                        {
                            clip.SetCurve(path + "/" + render.name, typeof(GameObject), "m_IsActive", ac);                      //m_Enabled
                        }
                    }

                    if (isffd && vertexcurvexArray != null)
                    {
                        for (int k = 0; k < vertexcurvexArray.Count; ++k)
                        {
                            Transform ffdNode = node.GetChild(k);
                            if (ffdNode.name == animSubData.name)
                            {
                                changedSpriteMeshsKV[path + "/" + ffdNode.name] = ffdNode.GetComponent <SpriteMesh>();

                                AnimationCurve[] vertex_xcurves = vertexcurvexArray[k];
                                AnimationCurve[] vertex_ycurves = vertexcurveyArray[k];
                                for (int r = 0; r < vertex_xcurves.Length; ++r)
                                {
                                    AnimationCurve vertex_xcurve = vertex_xcurves[r];
                                    AnimationCurve vertex_ycurve = vertex_ycurves[r];
                                    Transform      v             = ffdNode.GetChild(r);
                                    string         ctrlPath      = path + "/" + ffdNode.name + "/" + v.name;

                                    CurveExtension.OptimizesCurve(vertex_xcurve);
                                    CurveExtension.OptimizesCurve(vertex_ycurve);

                                    bool vcurveFlag = false;
                                    if (vertex_xcurve.keys != null && vertex_xcurve.keys.Length > 0 && CheckCurveValid(vertex_xcurve, v.localPosition.x))
                                    {
                                        vcurveFlag = true;
                                    }
                                    if (vertex_ycurve.keys != null && vertex_ycurve.keys.Length > 0 && CheckCurveValid(vertex_ycurve, v.localPosition.y))
                                    {
                                        vcurveFlag = true;
                                    }
                                    if (vcurveFlag)
                                    {
                                        if (isHaveCurve)
                                        {
                                            SetCustomCurveTangents(vertex_xcurve, animSubData.frameDatas);
                                        }
                                        CurveExtension.UpdateAllLinearTangents(vertex_xcurve);
                                        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.x"), vertex_xcurve);
                                        if (isHaveCurve)
                                        {
                                            SetCustomCurveTangents(vertex_ycurve, animSubData.frameDatas);
                                        }
                                        CurveExtension.UpdateAllLinearTangents(vertex_ycurve);
                                        AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve(ctrlPath, typeof(Transform), "m_LocalPosition.y"), vertex_ycurve);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#25
0
        static void CreateSlotAnim(ArmatureEditor armatureEditor, AnimationClip clip, DragonBoneData.AnimSubData[] subDatas, Dictionary <string, Transform> transformKV)
        {
            for (int i = 0; i < subDatas.Length; ++i)
            {
                DragonBoneData.AnimSubData animSubData = subDatas[i];
                string    slotName = string.IsNullOrEmpty(animSubData.slot) ? animSubData.name : animSubData.slot;
                Transform slotNode = transformKV[slotName];
                DragonBoneData.SlotData  defaultSlotData  = armatureEditor.slotsDataKV[slotName];
                DragonBoneData.ColorData defaultColorData = defaultSlotData.color;

                AnimationCurve color_rcurve = new AnimationCurve();
                AnimationCurve color_gcurve = new AnimationCurve();
                AnimationCurve color_bcurve = new AnimationCurve();
                AnimationCurve color_acurve = new AnimationCurve();

                Renderer[]       renders      = slotNode.GetComponentsInChildren <Renderer>();
                AnimationCurve[] renderCurves = new AnimationCurve[renders.Length];
                for (int r = 0; r < renderCurves.Length; ++r)
                {
                    renderCurves[r] = new AnimationCurve();
                }

                float during      = animSubData.offset;
                float perKeyTime  = 1f / armatureEditor.armatureData.frameRate;
                bool  isHaveCurve = false;
                for (int j = 0; j < animSubData.frameDatas.Length; ++j)
                {
                    DragonBoneData.AnimFrameData frameData = animSubData.frameDatas[j];

                    float   prevTweeneasing = float.PositiveInfinity;                  //前一帧的tweenEasing
                    float[] prevCurves      = null;
                    if (j > 0)
                    {
                        prevTweeneasing = animSubData.frameDatas[j - 1].tweenEasing;
                        prevCurves      = animSubData.frameDatas[j - 1].curve;
                    }
                    TangentMode tanModeL = GetPrevFrameTangentMode(prevTweeneasing, prevCurves);
                    TangentMode tanModeR = TangentMode.Linear;

                    if (frameData.curve != null && frameData.curve.Length > 0)
                    {
                        tanModeR    = TangentMode.Editable;
                        isHaveCurve = true;
                    }
                    else
                    {
                        if (frameData.tweenEasing == float.PositiveInfinity)
                        {
                            tanModeR = TangentMode.Stepped;
                        }
                        else if (frameData.tweenEasing == 0)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                        else if (frameData.tweenEasing == 1)
                        {
                            tanModeR = TangentMode.Smooth;
                        }
                        else if (frameData.tweenEasing == 2)
                        {
                            tanModeR = TangentMode.Linear;
                        }
                    }

                    if (frameData.color != null)
                    {
                        if (defaultColorData == null)
                        {
                            defaultColorData = new DragonBoneData.ColorData();
                        }
                        Color c = new Color(
                            frameData.color.rM + frameData.color.r0,
                            frameData.color.gM + frameData.color.g0,
                            frameData.color.bM + frameData.color.b0,
                            frameData.color.aM + frameData.color.a0
                            );
                        color_rcurve.AddKey(KeyframeUtil.GetNew(during, c.r, tanModeL, tanModeR));
                        color_gcurve.AddKey(KeyframeUtil.GetNew(during, c.g, tanModeL, tanModeR));
                        color_bcurve.AddKey(KeyframeUtil.GetNew(during, c.b, tanModeL, tanModeR));
                        color_acurve.AddKey(KeyframeUtil.GetNew(during, c.a, tanModeL, tanModeR));
                    }

                    //改displyindex
                    if (frameData.displayIndex == -1)
                    {
                        for (int r = 0; r < renders.Length; ++r)
                        {
                            renderCurves[r].AddKey(new Keyframe(during, 0f, float.PositiveInfinity, float.PositiveInfinity));
                        }
                    }
                    else
                    {
                        for (int r = 0; r < renders.Length; ++r)
                        {
                            if (r != frameData.displayIndex)
                            {
                                renderCurves[r].AddKey(new Keyframe(during, 0f, float.PositiveInfinity, float.PositiveInfinity));
                            }
                            else
                            {
                                renderCurves[r].AddKey(new Keyframe(during, 1f, float.PositiveInfinity, float.PositiveInfinity));
                            }
                        }
                    }
                    during += frameData.duration * perKeyTime;
                }

                CurveExtension.OptimizesCurve(color_rcurve);
                CurveExtension.OptimizesCurve(color_gcurve);
                CurveExtension.OptimizesCurve(color_bcurve);
                CurveExtension.OptimizesCurve(color_acurve);

                string path = "";
                if (slotPathKV.ContainsKey(slotName))
                {
                    path = slotPathKV[slotName];
                }
                else
                {
                    path = GetNodeRelativePath(armatureEditor, slotNode);
                    slotPathKV[slotNode.name] = path;
                }

                if (defaultColorData == null)
                {
                    defaultColorData = new DragonBoneData.ColorData();
                }

                float da = defaultColorData.aM + defaultColorData.a0;
                float dr = defaultColorData.rM + defaultColorData.r0;
                float dg = defaultColorData.gM + defaultColorData.g0;
                float db = defaultColorData.bM + defaultColorData.b0;
                if (armatureEditor.useUnitySprite)
                {
                    SpriteRenderer[] sprites = slotNode.GetComponentsInChildren <SpriteRenderer>();
                    if (sprites != null)
                    {
                        for (int z = 0; z < sprites.Length; ++z)
                        {
                            string childPath = path + "/" + sprites[z].name;
                            SetColorCurve <SpriteRenderer>(childPath, clip, color_rcurve, "m_Color.r", isHaveCurve, dr, animSubData.frameDatas);
                            SetColorCurve <SpriteRenderer>(childPath, clip, color_gcurve, "m_Color.g", isHaveCurve, dg, animSubData.frameDatas);
                            SetColorCurve <SpriteRenderer>(childPath, clip, color_bcurve, "m_Color.b", isHaveCurve, db, animSubData.frameDatas);
                            SetColorCurve <SpriteRenderer>(childPath, clip, color_acurve, "m_Color.a", isHaveCurve, da, animSubData.frameDatas);
                        }
                    }
                }
                else
                {
                    SpriteFrame[] sprites = slotNode.GetComponentsInChildren <SpriteFrame>();
                    if (sprites != null)
                    {
                        for (int z = 0; z < sprites.Length; ++z)
                        {
                            string childPath = path + "/" + sprites[z].name;
                            bool   anim_r    = SetColorCurve <SpriteFrame>(childPath, clip, color_rcurve, "m_color.r", isHaveCurve, dr, animSubData.frameDatas);
                            bool   anim_g    = SetColorCurve <SpriteFrame>(childPath, clip, color_gcurve, "m_color.g", isHaveCurve, dg, animSubData.frameDatas);
                            bool   anim_b    = SetColorCurve <SpriteFrame>(childPath, clip, color_bcurve, "m_color.b", isHaveCurve, db, animSubData.frameDatas);
                            bool   anim_a    = SetColorCurve <SpriteFrame>(childPath, clip, color_acurve, "m_color.a", isHaveCurve, da, animSubData.frameDatas);
                            if (anim_r || anim_g || anim_b || anim_a)
                            {
                                changedSpriteFramesKV[childPath] = sprites[z];
                            }
                        }
                    }

                    SpriteMesh[] spriteMeshs = slotNode.GetComponentsInChildren <SpriteMesh>();
                    if (spriteMeshs != null)
                    {
                        for (int z = 0; z < spriteMeshs.Length; ++z)
                        {
                            string childPath = path + "/" + spriteMeshs[z].name;
                            bool   anim_r    = SetColorCurve <SpriteMesh>(childPath, clip, color_rcurve, "m_color.r", isHaveCurve, da, animSubData.frameDatas);
                            bool   anim_g    = SetColorCurve <SpriteMesh>(childPath, clip, color_gcurve, "m_color.g", isHaveCurve, dg, animSubData.frameDatas);
                            bool   anim_b    = SetColorCurve <SpriteMesh>(childPath, clip, color_bcurve, "m_color.b", isHaveCurve, db, animSubData.frameDatas);
                            bool   anim_a    = SetColorCurve <SpriteMesh>(childPath, clip, color_acurve, "m_color.a", isHaveCurve, da, animSubData.frameDatas);
                            if (anim_r || anim_g || anim_b || anim_a)
                            {
                                changedSpriteMeshsKV[childPath] = spriteMeshs[z];
                            }
                        }
                    }
                }

                for (int r = 0; r < renderCurves.Length; ++r)
                {
                    AnimationCurve ac           = renderCurves[r];
                    Renderer       render       = renders[r];
                    float          defaultValue = render.enabled? 1: 0;
                    if (ac.keys != null && ac.keys.Length > 0 && CheckCurveValid(ac, defaultValue))
                    {
                        clip.SetCurve(path + "/" + render.name, typeof(GameObject), "m_IsActive", ac);                  //m_Enabled
                    }
                }
            }
        }