/// <summary> /// Use this method to specify where in the replay sequence the playback should start. /// This method accepts normalized offsets values between 0 and 1 and performs validation before using the value. /// </summary> /// <param name="normalizedOffset">The normalized value representing the offset from the specified origin to start the playback from</param> /// <param name="origin">The playback node to take the offset from. If <see cref="PlaybackOrigin.End"/> is specified then the offset value will be used as a negative offset</param> public static void SetPlaybackFrameNormalized(float normalizedOffset, PlaybackOrigin origin = PlaybackOrigin.Start) { // Make sure we have a manager if (Instance == null) { return; } // Move our current sequence frame to the normalized value ReplaySnapshot frame = Instance.sequence.SeekPlayback(normalizedOffset, origin, true); // Check for a valid frame if (frame != null) { // Restore the scene state Instance.scene.RestoreSnapshot(frame, Target.InitialStateBuffer); // Call the reset event ReplayBehaviour.Events.CallReplayResetEvents(); // This calls 'updateReplay' on all replay obejcts in the scene ReplayBehaviour.Events.CallReplayUpdateEvents(); } }
// Methods public ReplaySnapshot SeekPlayback(float offset, PlaybackOrigin origin, bool normalized) { // Check for normalized if (normalized == false) { // Check for seek mode switch (origin) { case PlaybackOrigin.Start: playbackTime = offset; break; case PlaybackOrigin.End: playbackTime = target.Duration - offset; break; case PlaybackOrigin.Current: playbackTime += offset; break; } } else { // Clamp the input valid offset = Mathf.Clamp01(offset); // Check for seek mode switch (origin) { case PlaybackOrigin.Start: playbackTime = MapScale(offset, 0, 1, 0, target.Duration); break; case PlaybackOrigin.End: playbackTime = MapScale(offset, 1, 0, 0, target.Duration); break; case PlaybackOrigin.Current: playbackTime = MapScale(offset, 0, 1, playbackTime, target.Duration); break; } } // Clamp to valid range playbackTime = Mathf.Clamp(playbackTime, 0, target.Duration); // Restore the scene state current = target.RestoreSnapshot(playbackTime); // Check for change if (current != last) { // Update the replay time ReplayTime.Time = playbackTime; if (last != null && current != null) { // Check for backwards if (last.TimeStamp <= current.TimeStamp) { // Forward ReplayTime.Delta = MapScale(playbackTime, last.TimeStamp, current.TimeStamp, 0, 1); } else { // Backward ReplayTime.Delta = -MapScale(playbackTime, last.TimeStamp, current.TimeStamp, 1, 0); } } } //else //{ // ReplayTime.Delta = 0; //} // Store current frame last = current; return(current); }