Skip to content

Commit

Permalink
Record from current scrubber position (clears keyframes after) and re…
Browse files Browse the repository at this point in the history
…main in position after record stop
  • Loading branch information
acidbubbles committed Nov 23, 2022
1 parent 1225d86 commit 28b2901
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/AtomAnimations/Operations/KeyframesOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ public void RemoveAll(IEnumerable<IAtomAnimationTarget> 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);
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/AtomAnimations/Operations/RecordOperations.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -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...");

Expand Down Expand Up @@ -165,7 +167,7 @@ private void BeforeRecording(List<ICurveAnimationTarget> targets, bool recordExt

foreach (var target in targets)
{
keyframesOps.RemoveAll(target);
keyframesOps.RemoveAll(target, fromTime: _clip.clipTime);
}

if (isEmpty)
Expand Down Expand Up @@ -210,13 +212,12 @@ private void AfterRecording(List<ICurveAnimationTarget> 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());
}

Expand All @@ -227,6 +228,7 @@ private void AfterRecording(List<ICurveAnimationTarget> targets)
}

GC.Collect();
_clip.clipTime = Mathf.Min(_clip.animationLength, _clip.clipTime).Snap();
}

private static void ClearAllGrabbedControllers(IEnumerable<ICurveAnimationTarget> targets)
Expand Down
2 changes: 0 additions & 2 deletions src/UI/Screens/RecordScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 28b2901

Please sign in to comment.