// Curve editor changes curves, but we are in charge of saving them into the clip private void SaveChangedCurvesFromCurveEditor() { m_State.SaveKeySelection(AnimationWindowState.kEditCurveUndoLabel); var curvesToUpdate = new Dictionary <AnimationClip, ChangedCurvesPerClip>(); var changedCurves = new ChangedCurvesPerClip(); for (int i = 0; i < m_CurveEditor.animationCurves.Length; ++i) { CurveWrapper curveWrapper = m_CurveEditor.animationCurves[i]; if (curveWrapper.changed) { if (!curveWrapper.animationIsEditable) { Debug.LogError("Curve is not editable and shouldn't be saved."); } if (curveWrapper.animationClip != null) { if (curvesToUpdate.TryGetValue(curveWrapper.animationClip, out changedCurves)) { changedCurves.bindings.Add(curveWrapper.binding); changedCurves.curves.Add(curveWrapper.curve.length > 0 ? curveWrapper.curve : null); } else { changedCurves.bindings = new List <EditorCurveBinding>(); changedCurves.curves = new List <AnimationCurve>(); changedCurves.bindings.Add(curveWrapper.binding); changedCurves.curves.Add(curveWrapper.curve.length > 0 ? curveWrapper.curve : null); curvesToUpdate.Add(curveWrapper.animationClip, changedCurves); } } curveWrapper.changed = false; } } if (curvesToUpdate.Count > 0) { foreach (var kvp in curvesToUpdate) { Undo.RegisterCompleteObjectUndo(kvp.Key, AnimationWindowState.kEditCurveUndoLabel); AnimationUtility.SetEditorCurves(kvp.Key, kvp.Value.bindings.ToArray(), kvp.Value.curves.ToArray()); } m_State.ResampleAnimation(); } }
private void SaveChangedCurvesFromCurveEditor() { this.m_State.SaveKeySelection("Edit Curve"); Dictionary <AnimationClip, AnimEditor.ChangedCurvesPerClip> dictionary = new Dictionary <AnimationClip, AnimEditor.ChangedCurvesPerClip>(); AnimEditor.ChangedCurvesPerClip value = default(AnimEditor.ChangedCurvesPerClip); for (int i = 0; i < this.m_CurveEditor.animationCurves.Length; i++) { CurveWrapper curveWrapper = this.m_CurveEditor.animationCurves[i]; if (curveWrapper.changed) { if (!curveWrapper.animationIsEditable) { Debug.LogError("Curve is not editable and shouldn't be saved."); } if (curveWrapper.animationClip != null) { if (dictionary.TryGetValue(curveWrapper.animationClip, out value)) { value.bindings.Add(curveWrapper.binding); value.curves.Add(curveWrapper.curve); } else { value.bindings = new List <EditorCurveBinding>(); value.curves = new List <AnimationCurve>(); value.bindings.Add(curveWrapper.binding); value.curves.Add(curveWrapper.curve); dictionary.Add(curveWrapper.animationClip, value); } } curveWrapper.changed = false; } } if (dictionary.Count > 0) { foreach (KeyValuePair <AnimationClip, AnimEditor.ChangedCurvesPerClip> current in dictionary) { Undo.RegisterCompleteObjectUndo(current.Key, "Edit Curve"); AnimationUtility.SetEditorCurves(current.Key, current.Value.bindings.ToArray(), current.Value.curves.ToArray()); } this.m_State.ResampleAnimation(); } }