Пример #1
0
 public static void SaveModifiedCurve(AnimationWindowCurve curve, AnimationClip clip)
 {
     curve.m_Keyframes.Sort((AnimationWindowKeyframe a, AnimationWindowKeyframe b) => a.time.CompareTo(b.time));
     if (curve.isPPtrCurve)
     {
         ObjectReferenceKeyframe[] array = curve.ToObjectCurve();
         if (array.Length == 0)
         {
             array = null;
         }
         AnimationUtility.SetObjectReferenceCurve(clip, curve.binding, array);
     }
     else
     {
         AnimationCurve animationCurve = curve.ToAnimationCurve();
         if (animationCurve.keys.Length == 0)
         {
             animationCurve = null;
         }
         else
         {
             QuaternionCurveTangentCalculation.UpdateTangentsFromMode(animationCurve, clip, curve.binding);
         }
         AnimationUtility.SetEditorCurve(clip, curve.binding, animationCurve);
     }
 }
 public void SaveCurve(AnimationWindowCurve curve)
 {
     curve.m_Keyframes.Sort((AnimationWindowKeyframe a, AnimationWindowKeyframe b) => a.time.CompareTo(b.time));
     Undo.RegisterCompleteObjectUndo(this.m_ActiveAnimationClip, "Edit Curve");
     if (curve.isPPtrCurve)
     {
         ObjectReferenceKeyframe[] array = curve.ToObjectCurve();
         if (array.Length == 0)
         {
             array = null;
         }
         AnimationUtility.SetObjectReferenceCurve(this.m_ActiveAnimationClip, curve.binding, array);
     }
     else
     {
         AnimationCurve animationCurve = curve.ToAnimationCurve();
         if (animationCurve.keys.Length == 0)
         {
             animationCurve = null;
         }
         else
         {
             QuaternionCurveTangentCalculation.UpdateTangentsFromMode(animationCurve, this.m_ActiveAnimationClip, curve.binding);
         }
         AnimationUtility.SetEditorCurve(this.m_ActiveAnimationClip, curve.binding, animationCurve);
     }
     this.Repaint();
 }
        public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, Type type, AnimationKeyTime time)
        {
            AnimationWindowKeyframe animationWindowKeyframe = curve.FindKeyAtTime(time);
            AnimationWindowKeyframe result;

            if (animationWindowKeyframe != null)
            {
                animationWindowKeyframe.value = value;
                result = animationWindowKeyframe;
            }
            else
            {
                AnimationWindowKeyframe animationWindowKeyframe2 = null;
                if (curve.isPPtrCurve)
                {
                    animationWindowKeyframe2       = new AnimationWindowKeyframe();
                    animationWindowKeyframe2.time  = time.time;
                    animationWindowKeyframe2.value = value;
                    animationWindowKeyframe2.curve = curve;
                    curve.AddKeyframe(animationWindowKeyframe2, time);
                }
                else if (type == typeof(bool) || type == typeof(float))
                {
                    animationWindowKeyframe2 = new AnimationWindowKeyframe();
                    AnimationCurve animationCurve = curve.ToAnimationCurve();
                    Keyframe       key            = new Keyframe(time.time, (float)value);
                    if (type == typeof(bool))
                    {
                        AnimationUtility.SetKeyLeftTangentMode(ref key, AnimationUtility.TangentMode.Constant);
                        AnimationUtility.SetKeyRightTangentMode(ref key, AnimationUtility.TangentMode.Constant);
                        AnimationUtility.SetKeyBroken(ref key, true);
                        animationWindowKeyframe2.m_TangentMode = key.tangentMode;
                        animationWindowKeyframe2.m_InTangent   = float.PositiveInfinity;
                        animationWindowKeyframe2.m_OutTangent  = float.PositiveInfinity;
                    }
                    else
                    {
                        int num = animationCurve.AddKey(key);
                        if (num != -1)
                        {
                            CurveUtility.SetKeyModeFromContext(animationCurve, num);
                            animationWindowKeyframe2.m_TangentMode = animationCurve[num].tangentMode;
                        }
                    }
                    animationWindowKeyframe2.time  = time.time;
                    animationWindowKeyframe2.value = value;
                    animationWindowKeyframe2.curve = curve;
                    curve.AddKeyframe(animationWindowKeyframe2, time);
                }
                result = animationWindowKeyframe2;
            }
            return(result);
        }
        public static CurveWrapper GetCurveWrapper(AnimationWindowCurve curve, AnimationClip clip)
        {
            CurveWrapper curveWrapper = new CurveWrapper();

            curveWrapper.renderer = (CurveRenderer) new NormalCurveRenderer(curve.ToAnimationCurve());
            curveWrapper.renderer.SetWrap(WrapMode.Once, !clip.isLooping ? WrapMode.Once : WrapMode.Loop);
            curveWrapper.renderer.SetCustomRange(clip.startTime, clip.stopTime);
            curveWrapper.binding = curve.binding;
            curveWrapper.id      = CurveUtility.GetCurveID(clip, curve.binding);
            curveWrapper.color   = CurveUtility.GetPropertyColor(curve.propertyName);
            curveWrapper.hidden  = false;
            return(curveWrapper);
        }
 public static void RenameCurvePath(AnimationWindowCurve curve, EditorCurveBinding newBinding, AnimationClip clip)
 {
     if (curve.isPPtrCurve)
     {
         AnimationUtility.SetObjectReferenceCurve(clip, curve.binding, null);
         AnimationUtility.SetObjectReferenceCurve(clip, newBinding, curve.ToObjectCurve());
     }
     else
     {
         AnimationUtility.SetEditorCurve(clip, curve.binding, null);
         AnimationUtility.SetEditorCurve(clip, newBinding, curve.ToAnimationCurve());
     }
 }
Пример #6
0
        public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, Type type, AnimationKeyTime time)
        {
            AnimationWindowKeyframe keyframe = curve.FindKeyAtTime(time);

            if (keyframe != null)
            {
                keyframe.value = value;
                return(keyframe);
            }
            AnimationWindowKeyframe key = new AnimationWindowKeyframe {
                time = time.time
            };

            if (curve.isPPtrCurve)
            {
                key.value = value;
                key.curve = curve;
                curve.AddKeyframe(key, time);
                return(key);
            }
            if ((type == typeof(bool)) || (type == typeof(float)))
            {
                AnimationCurve curve2    = curve.ToAnimationCurve();
                Keyframe       keyframe3 = new Keyframe(time.time, (float)value);
                if (type == typeof(bool))
                {
                    CurveUtility.SetKeyTangentMode(ref keyframe3, 0, TangentMode.Stepped);
                    CurveUtility.SetKeyTangentMode(ref keyframe3, 1, TangentMode.Stepped);
                    CurveUtility.SetKeyBroken(ref keyframe3, true);
                    key.m_TangentMode = keyframe3.tangentMode;
                    key.m_InTangent   = float.PositiveInfinity;
                    key.m_OutTangent  = float.PositiveInfinity;
                }
                else
                {
                    int keyIndex = curve2.AddKey(keyframe3);
                    if (keyIndex != -1)
                    {
                        CurveUtility.SetKeyModeFromContext(curve2, keyIndex);
                        Keyframe keyframe4 = curve2[keyIndex];
                        key.m_TangentMode = keyframe4.tangentMode;
                    }
                }
                key.value = value;
                key.curve = curve;
                curve.AddKeyframe(key, time);
            }
            return(key);
        }
        public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve curve, object value, System.Type type, AnimationKeyTime time)
        {
            AnimationWindowKeyframe keyAtTime = curve.FindKeyAtTime(time);

            if (keyAtTime != null)
            {
                keyAtTime.value = value;
                return(keyAtTime);
            }
            AnimationWindowKeyframe key1 = new AnimationWindowKeyframe();

            key1.time = time.time;
            if (curve.isPPtrCurve)
            {
                key1.value = value;
                key1.curve = curve;
                curve.AddKeyframe(key1, time);
            }
            else if (type == typeof(bool) || type == typeof(float))
            {
                AnimationCurve animationCurve = curve.ToAnimationCurve();
                Keyframe       key2           = new Keyframe(time.time, (float)value);
                if (type == typeof(bool))
                {
                    CurveUtility.SetKeyTangentMode(ref key2, 0, TangentMode.Stepped);
                    CurveUtility.SetKeyTangentMode(ref key2, 1, TangentMode.Stepped);
                    CurveUtility.SetKeyBroken(ref key2, true);
                    key1.m_TangentMode = key2.tangentMode;
                    key1.m_InTangent   = float.PositiveInfinity;
                    key1.m_OutTangent  = float.PositiveInfinity;
                }
                else
                {
                    int keyIndex = animationCurve.AddKey(key2);
                    if (keyIndex != -1)
                    {
                        CurveUtility.SetKeyModeFromContext(animationCurve, keyIndex);
                        key1.m_TangentMode = animationCurve[keyIndex].tangentMode;
                    }
                }
                key1.value = value;
                key1.curve = curve;
                curve.AddKeyframe(key1, time);
            }
            return(key1);
        }
 public static void RenameCurvePath(AnimationWindowCurve curve, EditorCurveBinding newBinding, AnimationClip clip)
 {
     AnimationUtility.SetEditorCurve(clip, curve.binding, (AnimationCurve)null);
     AnimationUtility.SetEditorCurve(clip, newBinding, curve.ToAnimationCurve());
 }