Beispiel #1
0
        public static void RemoveCurve(UnityEngine.Object target, IEnumerable <PropertyModification> modifications, WindowState state)
        {
            AnimationClip clip    = null;
            double        keyTime = 0;
            var           inRange = false; // not used for curves

            if (!GetClipAndRelativeTime(target, state, out clip, out keyTime, out inRange))
            {
                return;
            }

            TimelineUndo.PushUndo(clip, "Remove Curve");
            foreach (var mod in modifications)
            {
                EditorCurveBinding temp;
                if (HasBinding(target, mod, clip, out temp))
                {
                    if (temp.isPPtrCurve)
                    {
                        AnimationUtility.SetObjectReferenceCurve(clip, temp, null);
                    }
                    else
                    {
                        AnimationUtility.SetEditorCurve(clip, temp, null);
                    }
                }
            }

            state.ResetPreviewMode();
        }
Beispiel #2
0
        public static void RemoveKey(UnityEngine.Object target, IEnumerable <PropertyModification> modifications,
                                     WindowState state)
        {
            AnimationClip clip;
            double        keyTime;
            bool          inRange;

            if (!GetClipAndRelativeTime(target, state, out clip, out keyTime, out inRange) || !inRange)
            {
                return;
            }
            var refreshPreview = false;

            TimelineUndo.PushUndo(clip, "Remove Key");
            foreach (var mod in modifications)
            {
                EditorCurveBinding temp;
                if (HasBinding(target, mod, clip, out temp))
                {
                    if (temp.isPPtrCurve)
                    {
                        CurveEditUtility.RemoveObjectKey(clip, temp, keyTime);
                        if (CurveEditUtility.GetObjectKeyCount(clip, temp) == 0)
                        {
                            refreshPreview = true;
                        }
                    }
                    else
                    {
                        AnimationCurve curve = AnimationUtility.GetEditorCurve(clip, temp);
                        if (curve != null)
                        {
                            CurveEditUtility.RemoveKeyFrameFromCurve(curve, (float)keyTime, clip.frameRate);
                            AnimationUtility.SetEditorCurve(clip, temp, curve);
                            if (curve.length == 0)
                            {
                                AnimationUtility.SetEditorCurve(clip, temp, null);
                                refreshPreview = true;
                            }
                        }
                    }
                }
            }

            if (refreshPreview)
            {
                state.ResetPreviewMode();
            }
        }