static public void ProcessModifications(IAnimationRecordingState state, UndoPropertyModification[] modifications) { AnimationClip clip = state.activeAnimationClip; GameObject root = state.activeRootGameObject; // Record modified properties for (int i = 0; i < modifications.Length; i++) { EditorCurveBinding binding = new EditorCurveBinding(); PropertyModification prop = modifications[i].previousValue; Type type = AnimationUtility.PropertyModificationToEditorCurveBinding(prop, root, out binding); if (type != null) { object currentValue = CurveBindingUtility.GetCurrentValue(root, binding); object previousValue = null; if (!ValueFromPropertyModification(prop, binding, out previousValue)) { previousValue = currentValue; } state.AddPropertyModification(binding, prop, modifications[i].keepPrefabOverride); AddKey(state, binding, type, previousValue, currentValue); } } }
static private void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis, float scale = 1.0f) { var binding = baseBinding; binding.propertyName = binding.propertyName.Remove(binding.propertyName.Length - 1, 1) + axis; object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, binding); var previousModification = modification.previousValue; if (previousModification == null) { // create dummy previousModification = new PropertyModification(); previousModification.target = target; previousModification.propertyPath = binding.propertyName; previousModification.value = ((float)currentValue).ToString(CultureInfo.InvariantCulture.NumberFormat); } object previousValue = currentValue; ValueFromPropertyModification(previousModification, binding, out previousValue); state.AddPropertyModification(binding, previousModification, modification.keepPrefabOverride); if (scale != 1.0f) { previousValue = (object)((float)previousValue / scale); currentValue = (object)((float)currentValue / scale); } AddKey(state, binding, typeof(float), previousValue, currentValue); }
private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row) { bool curvesChanged = false; if (node is AnimationWindowHierarchyPropertyNode) { AnimationWindowCurve[] curves = node.curves; if (curves == null || curves.Length == 0) { return; } // We do valuefields for dopelines that only have single curve AnimationWindowCurve curve = curves[0]; object objectValue = CurveBindingUtility.GetCurrentValue(state, curve); if (objectValue is float) { float value = (float)objectValue; Rect valueFieldDragRect = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide - k_ValueFieldDragWidth, rect.y, k_ValueFieldDragWidth, rect.height); Rect valueFieldRect = new Rect(rect.xMax - k_ValueFieldOffsetFromRightSide, rect.y, k_ValueFieldWidth, rect.height); if (Event.current.type == EventType.MouseMove && valueFieldRect.Contains(Event.current.mousePosition)) { s_WasInsideValueRectFrame = Time.frameCount; } EditorGUI.BeginChangeCheck(); if (curve.valueType == typeof(bool)) { value = GUI.Toggle(valueFieldRect, m_HierarchyItemValueControlIDs[row], value != 0, GUIContent.none, EditorStyles.toggle) ? 1 : 0; } else { int id = m_HierarchyItemValueControlIDs[row]; bool enterInTextField = (EditorGUIUtility.keyboardControl == id && EditorGUIUtility.editingTextField && Event.current.type == EventType.KeyDown && (Event.current.character == '\n' || (int)Event.current.character == 3)); // Force back keyboard focus to float field editor when editing it. // TreeView forces keyboard focus on itself at mouse down and we lose focus here. if (EditorGUI.s_RecycledEditor.controlID == id && Event.current.type == EventType.MouseDown && valueFieldRect.Contains(Event.current.mousePosition)) { GUIUtility.keyboardControl = id; } value = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, valueFieldRect, valueFieldDragRect, id, value, "g5", m_AnimationSelectionTextField, true); if (enterInTextField) { GUI.changed = true; Event.current.Use(); } } if (float.IsInfinity(value) || float.IsNaN(value)) { value = 0; } if (EditorGUI.EndChangeCheck()) { string undoLabel = "Edit Key"; AnimationKeyTime newAnimationKeyTime = AnimationKeyTime.Time(state.currentTime, curve.clip.frameRate); AnimationWindowKeyframe existingKeyframe = null; foreach (AnimationWindowKeyframe keyframe in curve.m_Keyframes) { if (Mathf.Approximately(keyframe.time, state.currentTime)) { existingKeyframe = keyframe; } } if (existingKeyframe == null) { AnimationWindowUtility.AddKeyframeToCurve(curve, value, curve.valueType, newAnimationKeyTime); } else { existingKeyframe.value = value; } state.SaveCurve(curve.clip, curve, undoLabel); curvesChanged = true; } } } if (curvesChanged) { state.ResampleAnimation(); } }