Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Core/ReplayPlayback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void HandlePlayback()

if (elapsedPlaybackTime >= currentReplay.Frames[^1].Time)
{
SetPlaybackTime(currentReplay.Frames[^1].Time);
UpdatePlayback(currentReplay.Frames[^1].Time);

if (Main.instance.StopReplayWhenDone.Value)
StopReplay();
Expand All @@ -116,15 +116,15 @@ public void HandlePlayback()

if (elapsedPlaybackTime <= 0f)
{
SetPlaybackTime(0f);
UpdatePlayback(0f);

if (Main.instance.StopReplayWhenDone.Value)
StopReplay();

return;
}

SetPlaybackTime(elapsedPlaybackTime);
UpdatePlayback(elapsedPlaybackTime);

ReplayPlaybackControls.timeline?.GetComponent<MeshRenderer>()?.material?.SetFloat("_BP_Current", elapsedPlaybackTime * 1000f);

Expand Down Expand Up @@ -606,6 +606,8 @@ private IEnumerator SpawnClones(Action done = null)
temp.gameObject.SetActive(true);
PlaybackPlayers[i] = temp;
temp.Controller.transform.SetParent(replayPlayers.transform);

ReplayAPI.CloneSpawnedInternal(temp);
}

done?.Invoke();
Expand Down Expand Up @@ -1553,6 +1555,8 @@ public void SetPlaybackSpeed(float newSpeed)
ReplayPlaybackControls.playbackSpeedText.text = label;
ReplayPlaybackControls.playbackSpeedText.ForceMeshUpdate();
}

ReplayAPI.ReplaySpeedChangedInternal(newSpeed);
}

public void AddPlaybackSpeed(float delta, float minSpeed = -8f, float maxSpeed = 8f)
Expand All @@ -1579,6 +1583,11 @@ public void SetPlaybackFrame(int frame)
}

public void SetPlaybackTime(float time)
{
UpdatePlayback(time);
}

public void UpdatePlayback(float time)
{
float oldTime = elapsedPlaybackTime;

Expand Down
20 changes: 19 additions & 1 deletion src/Replay/ReplayAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public static class ReplayAPI
/// Invoked when the playback time changes (seek or progression).
/// </summary>
public static event Action<float> onReplayTimeChanged;

/// <summary>
/// Invoked when the playback time changes (seek only).
/// </summary>
public static event Action<float> onReplaySeeked;

/// <summary>
/// Invoked when the playback speed changes.
/// </summary>
public static event Action<float> onSpeedChanged;

/// <summary>
/// Invoked when playback is paused or resumed, along with the new toggle state.
Expand Down Expand Up @@ -93,6 +103,11 @@ public static class ReplayAPI
/// </summary>
public static event Action<ReplaySerializer.ReplayHeader, string> onReplayRenamed;

/// <summary>
/// Invoked as a clone is spawned or reset.
/// </summary>
public static event Action<ReplayPlayback.Clone> onCloneSpawned;

private static void InvokeSafe(Delegate action, params object[] args)
{
if (action == null)
Expand Down Expand Up @@ -126,15 +141,18 @@ private static void InvokeSafe(Delegate action, params object[] args)
internal static void RecordingStartedInternal() => InvokeSafe(onRecordingStarted);
internal static void RecordingStoppedInternal() => InvokeSafe(onRecordingStopped);
internal static void ReplayTimeChangedInternal(float time) => InvokeSafe(onReplayTimeChanged, time);
internal static void ReplaySeekedInternal(float time) => InvokeSafe(onReplaySeeked, time);
internal static void ReplayPauseChangedInternal(bool paused) => InvokeSafe(onReplayPauseChanged, paused);

internal static void ReplaySpeedChangedInternal(float time) => InvokeSafe(onSpeedChanged, time);
internal static void OnPlaybackFrameInternal(Frame frame, Frame nextFrame) => InvokeSafe(OnPlaybackFrame, frame, nextFrame);
internal static void OnRecordFrameInternal(Frame frame, bool isBuffer) => InvokeSafe(OnRecordFrame, frame, isBuffer);

internal static void ReplaySavedInternal(ReplayInfo info, bool isBuffer, string path) => InvokeSafe(onReplaySaved, info, isBuffer, path);
internal static void ReplayDeletedInternal(string path) => InvokeSafe(onReplayDeleted, path);
internal static void ReplayRenamedInternal(ReplaySerializer.ReplayHeader header, string newPath) => InvokeSafe(onReplayRenamed, header, newPath);

internal static void CloneSpawnedInternal(ReplayPlayback.Clone clone) => InvokeSafe(onCloneSpawned, clone);

/// <summary>
/// Gets whether a recording is currently active.
/// This is enabled when a user manually starts recording.
Expand Down
Loading