static private UndoPropertyModification[] FilterModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications) { GameObject rootGameObject = state.activeRootGameObject; List <UndoPropertyModification> discardedModifications = new List <UndoPropertyModification>(); List <UndoPropertyModification> outModifications = new List <UndoPropertyModification>(); for (int i = 0; i < modifications.Length; ++i) { UndoPropertyModification modification = modifications[i]; PropertyModification prop = modification.previousValue; if (state.DiscardModification(prop)) { discardedModifications.Add(modification); continue; } var binding = new EditorCurveBinding(); if (AnimationUtility.PropertyModificationToEditorCurveBinding(prop, rootGameObject, out binding) != null) { outModifications.Add(modification); } else { discardedModifications.Add(modification); } } if (discardedModifications.Count > 0) { modifications = outModifications.ToArray(); } return(discardedModifications.ToArray()); }
public void AddKey(PropertyModification[] modifications) { var undoModifications = new UndoPropertyModification[modifications.Length]; for (int i = 0; i < modifications.Length; ++i) { var modification = modifications[i]; undoModifications[i].previousValue = modification; undoModifications[i].currentValue = modification; } BeginKeyModification(); var recordingState = new RecordingState(state, RecordingStateMode.ManualKey); AnimationRecording.Process(recordingState, undoModifications); EndKeyModification(); RemoveFromCandidates(modifications); ResampleAnimation(); state.Repaint(); }
private static void CollectRotationModifications(IAnimationRecordingState state, ref UndoPropertyModification[] modifications, ref Dictionary <object, AnimationRecording.RotationModification> rotationModifications) { List <UndoPropertyModification> list = new List <UndoPropertyModification>(); UndoPropertyModification[] array = modifications; for (int i = 0; i < array.Length; i++) { UndoPropertyModification undoPropertyModification = array[i]; EditorCurveBinding editorCurveBinding = default(EditorCurveBinding); PropertyModification previousValue = undoPropertyModification.previousValue; AnimationUtility.PropertyModificationToEditorCurveBinding(previousValue, state.activeRootGameObject, out editorCurveBinding); if (editorCurveBinding.propertyName.StartsWith("m_LocalRotation")) { AnimationRecording.RotationModification rotationModification; if (!rotationModifications.TryGetValue(previousValue.target, out rotationModification)) { rotationModification = new AnimationRecording.RotationModification(); rotationModifications[previousValue.target] = rotationModification; } if (editorCurveBinding.propertyName.EndsWith("x")) { rotationModification.x = undoPropertyModification; } else if (editorCurveBinding.propertyName.EndsWith("y")) { rotationModification.y = undoPropertyModification; } else if (editorCurveBinding.propertyName.EndsWith("z")) { rotationModification.z = undoPropertyModification; } else if (editorCurveBinding.propertyName.EndsWith("w")) { rotationModification.w = undoPropertyModification; } rotationModification.lastQuatModification = undoPropertyModification; } else if (previousValue.propertyPath.StartsWith("m_LocalEulerAnglesHint")) { AnimationRecording.RotationModification rotationModification2; if (!rotationModifications.TryGetValue(previousValue.target, out rotationModification2)) { rotationModification2 = new AnimationRecording.RotationModification(); rotationModifications[previousValue.target] = rotationModification2; } rotationModification2.useEuler = true; if (previousValue.propertyPath.EndsWith("x")) { rotationModification2.eulerX = undoPropertyModification; } else if (previousValue.propertyPath.EndsWith("y")) { rotationModification2.eulerY = undoPropertyModification; } else if (previousValue.propertyPath.EndsWith("z")) { rotationModification2.eulerZ = undoPropertyModification; } } else { list.Add(undoPropertyModification); } } if (rotationModifications.Count > 0) { modifications = list.ToArray(); } }
private static void AddRotationPropertyModification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification) { if (modification.previousValue != null) { EditorCurveBinding binding = baseBinding; binding.propertyName = modification.previousValue.propertyPath; AnimationMode.AddPropertyModification(binding, modification.previousValue, modification.keepPrefabOverride); } }
// Test if this modification position or rotation internal static bool IsPositionOrRotation(UndoPropertyModification modification) { return(IsPosition(modification) || IsRotation(modification)); }
private static void SetupPropertyModification(string name, float value, UndoPropertyModification prop) { prop.previousValue.propertyPath = "material." + name; prop.previousValue.value = value.ToString(); }
static void ProcessAnimatorModification(IAnimationRecordingState state, Animator animator, UndoPropertyModification modification, string name, float value, float scale) { AnimationClip clip = state.activeAnimationClip; if ((clip.hideFlags & HideFlags.NotEditable) != 0) { return; } float prevValue = value; object oValue; if (ValueFromPropertyModification(modification.currentValue, new EditorCurveBinding(), out oValue)) { value = (float)oValue; } if (ValueFromPropertyModification(modification.previousValue, new EditorCurveBinding(), out oValue)) { prevValue = (float)oValue; } value = Mathf.Abs(scale) > Mathf.Epsilon ? value / scale : value; prevValue = Mathf.Abs(scale) > Mathf.Epsilon ? prevValue / scale : prevValue; var binding = new EditorCurveBinding(); binding.propertyName = name; binding.path = ""; binding.type = typeof(Animator); var prop = new PropertyModification(); prop.target = animator; prop.propertyPath = binding.propertyName; prop.value = value.ToString(); state.AddPropertyModification(binding, prop, modification.keepPrefabOverride); AnimationWindowCurve curve = new AnimationWindowCurve(clip, binding, typeof(float)); if (state.addZeroFrame && state.currentFrame != 0 && curve.length == 0) { AnimationWindowUtility.AddKeyframeToCurve(curve, prevValue, typeof(float), AnimationKeyTime.Frame(0, clip.frameRate)); } AnimationWindowUtility.AddKeyframeToCurve(curve, value, typeof(float), AnimationKeyTime.Frame(state.currentFrame, clip.frameRate)); state.SaveCurve(curve); }
static private void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis) { var binding = baseBinding; var property = modification.previousValue; binding.propertyName = binding.propertyName.Remove(binding.propertyName.Length - 1, 1) + axis; if (property == null) { // create dummy property = new PropertyModification(); property.target = target; property.propertyPath = binding.propertyName; object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, binding); property.value = ((float)currentValue).ToString(); } state.AddPropertyModification(binding, property, modification.keepPrefabOverride); AddKey(state, binding, typeof(float), property); }
static private void AddRotationPropertyModification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification) { if (modification.previousValue == null) { return; } // case 817356. Reuse baseBinding as basis for rotation binding. // This is needed to register valid bindings for m_LocalEulerAnglesHint // that cannot be converted to EditorCurveBinding otherwise. EditorCurveBinding binding = baseBinding; binding.propertyName = modification.previousValue.propertyPath; state.AddPropertyModification(binding, modification.previousValue, modification.keepPrefabOverride); }
static bool ProcessPlayableAssetRecording(UndoPropertyModification mod, WindowState state, ICurvesOwner curvesOwner, bool allowAdd) { if (mod.currentValue == null) { return(false); } if (!curvesOwner.IsParameterAnimatable(mod.currentValue.propertyPath)) { return(false); } // only animate items with existing curves if (!allowAdd && !curvesOwner.IsParameterAnimated(mod.currentValue.propertyPath)) { return(false); } var localTime = state.editSequence.time; var timelineClip = curvesOwner as TimelineClip; if (timelineClip != null) { // don't use time global to local since it will possibly loop. localTime = timelineClip.ToLocalTimeUnbound(state.editSequence.time); } if (localTime < 0) { return(false); } if (state.playing) { return(true); //absorb undo but don't record during playback } // grab the value from the current modification float fValue; if (!ExpressionEvaluator.Evaluate(mod.currentValue.value, out fValue)) { // case 916913 -- 'Add Key' menu item will passes 'True' or 'False' (instead of 1, 0) // so we need a special case to parse the boolean string bool bValue; if (!bool.TryParse(mod.currentValue.value, out bValue)) { Debug.Assert(false, "Invalid type in PlayableAsset recording"); return(false); } fValue = bValue ? 1 : 0; } var added = curvesOwner.AddAnimatedParameterValueAt(mod.currentValue.propertyPath, fValue, (float)localTime); if (added && AnimationMode.InAnimationMode()) { EditorCurveBinding binding = curvesOwner.GetCurveBinding(mod.previousValue.propertyPath); AnimationMode.AddPropertyModification(binding, mod.previousValue, true); curvesOwner.targetTrack.SetShowInlineCurves(true); if (state.GetWindow() != null && state.GetWindow().treeView != null) { state.GetWindow().treeView.CalculateRowRects(); } } return(added); }
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 static void AddRotationPropertyModification(IAnimationRecordingState state, UndoPropertyModification modification) { if (modification.previousValue == null) { return; } EditorCurveBinding binding = default(EditorCurveBinding); if (AnimationUtility.PropertyModificationToEditorCurveBinding(modification.previousValue, state.activeRootGameObject, out binding) != null) { AnimationMode.AddPropertyModification(binding, modification.previousValue, modification.keepPrefabOverride); } }
private static void ProcessAnimatorModification(IAnimationRecordingState state, Animator animator, UndoPropertyModification modification, string name, float value, float scale) { AnimationClip activeAnimationClip = state.activeAnimationClip; if ((activeAnimationClip.hideFlags & HideFlags.NotEditable) == HideFlags.None) { float num = value; object obj; if (AnimationRecording.ValueFromPropertyModification(modification.currentValue, default(EditorCurveBinding), out obj)) { value = (float)obj; } if (AnimationRecording.ValueFromPropertyModification(modification.previousValue, default(EditorCurveBinding), out obj)) { num = (float)obj; } value = ((Mathf.Abs(scale) <= Mathf.Epsilon) ? value : (value / scale)); num = ((Mathf.Abs(scale) <= Mathf.Epsilon) ? num : (num / scale)); EditorCurveBinding binding = default(EditorCurveBinding); binding.propertyName = name; binding.path = ""; binding.type = typeof(Animator); PropertyModification propertyModification = new PropertyModification(); propertyModification.target = animator; propertyModification.propertyPath = binding.propertyName; propertyModification.value = value.ToString(); state.AddPropertyModification(binding, propertyModification, modification.keepPrefabOverride); AnimationWindowCurve animationWindowCurve = new AnimationWindowCurve(activeAnimationClip, binding, typeof(float)); if (state.addZeroFrame && state.currentFrame != 0 && animationWindowCurve.length == 0) { AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, num, typeof(float), AnimationKeyTime.Frame(0, activeAnimationClip.frameRate)); } AnimationWindowUtility.AddKeyframeToCurve(animationWindowCurve, value, typeof(float), AnimationKeyTime.Frame(state.currentFrame, activeAnimationClip.frameRate)); state.SaveCurve(animationWindowCurve); } }
private static void ProcessVector3Modification(IAnimationRecordingState state, EditorCurveBinding baseBinding, UndoPropertyModification modification, Transform target, string axis) { EditorCurveBinding editorCurveBinding = baseBinding; PropertyModification propertyModification = modification.previousValue; editorCurveBinding.propertyName = editorCurveBinding.propertyName.Remove(editorCurveBinding.propertyName.Length - 1, 1) + axis; if (propertyModification == null) { propertyModification = new PropertyModification(); propertyModification.target = target; propertyModification.propertyPath = editorCurveBinding.propertyName; object currentValue = CurveBindingUtility.GetCurrentValue(state.activeRootGameObject, editorCurveBinding); propertyModification.value = ((float)currentValue).ToString(); } state.AddPropertyModification(editorCurveBinding, propertyModification, modification.keepPrefabOverride); AnimationRecording.AddKey(state, editorCurveBinding, typeof(float), propertyModification); }