From 28b29013e12032ad402b38e48544a224900ecc13 Mon Sep 17 00:00:00 2001 From: Acid Bubbles Date: Tue, 22 Nov 2022 23:13:09 -0500 Subject: [PATCH] Record from current scrubber position (clears keyframes after) and remain in position after record stop --- .../Operations/KeyframesOperations.cs | 5 +++-- .../Operations/RecordOperations.cs | 16 +++++++++------- src/UI/Screens/RecordScreen.cs | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/AtomAnimations/Operations/KeyframesOperations.cs b/src/AtomAnimations/Operations/KeyframesOperations.cs index 3a4480a9..d9eab359 100644 --- a/src/AtomAnimations/Operations/KeyframesOperations.cs +++ b/src/AtomAnimations/Operations/KeyframesOperations.cs @@ -20,14 +20,15 @@ public void RemoveAll(IEnumerable targets) } } - public void RemoveAll(IAtomAnimationTarget target, bool includeEdges = false) + public void RemoveAll(IAtomAnimationTarget target, bool includeEdges = false, float fromTime = 0f) { target.StartBulkUpdates(); try { foreach (var time in target.GetAllKeyframesTime()) { - if (!includeEdges && (time == 0f || time == _clip.animationLength)) continue; + if (time < fromTime) continue; + if (!includeEdges && (time <= 0f || time >= _clip.animationLength)) continue; target.DeleteFrame(time); } } diff --git a/src/AtomAnimations/Operations/RecordOperations.cs b/src/AtomAnimations/Operations/RecordOperations.cs index d899c17a..f505896e 100644 --- a/src/AtomAnimations/Operations/RecordOperations.cs +++ b/src/AtomAnimations/Operations/RecordOperations.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -35,8 +34,11 @@ public IEnumerator StartRecording( yield break; } - _animation.StopAndReset(); - _animation.Sample(); + if (_animation.isPlaying) + { + SuperController.LogError("Timeline: Stop playback before recording"); + yield break; + } ShowText("Preparing to record..."); @@ -165,7 +167,7 @@ private void BeforeRecording(List targets, bool recordExt foreach (var target in targets) { - keyframesOps.RemoveAll(target); + keyframesOps.RemoveAll(target, fromTime: _clip.clipTime); } if (isEmpty) @@ -210,13 +212,12 @@ private void AfterRecording(List targets) _animation.RestoreTemporaryTimeMode(); _peerManager.SendStopRecording(); - var resizeOp = new ResizeAnimationOperations(); - _animation.StopAndReset(); ShowText(null); if (_clip.infinite) { _clip.infinite = false; + var resizeOp = new ResizeAnimationOperations(); resizeOp.CropOrExtendEnd(_clip, _clip.GetAllCurveTargets().Select(t => t.GetLeadCurve().duration).Max()); } @@ -227,6 +228,7 @@ private void AfterRecording(List targets) } GC.Collect(); + _clip.clipTime = Mathf.Min(_clip.animationLength, _clip.clipTime).Snap(); } private static void ClearAllGrabbedControllers(IEnumerable targets) diff --git a/src/UI/Screens/RecordScreen.cs b/src/UI/Screens/RecordScreen.cs index 1f471f0c..e4a17071 100644 --- a/src/UI/Screens/RecordScreen.cs +++ b/src/UI/Screens/RecordScreen.cs @@ -202,14 +202,12 @@ private IEnumerator OnRecordCo(int timeMode, bool recordExtendsLength, bool hide if (_recordButton != null) _recordButton.button.interactable = true; - animationEditContext.Stop(); // This is a hack, not sure why it's necessary to update the keyframes yield return 0; current.DirtyAll(); yield return 0; animationEditContext.ResetScrubberRange(); - animationEditContext.clipTime = 0f; if (hideMenuDuringRecording) SuperController.singleton.ShowMainHUDAuto(); }