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
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ private void StepBack()
if (!sequencerController.IsPlaying)
PlaySequence();

// Always uses GotoWithCallbacks() rather than GoTo() to ensure Set steps work as intended.
sequencerController.PlayingSequence.GotoWithCallbacks((sequencerController.PlayingSequence.ElapsedPercentage() -
0.01f) * sequencerController.PlayingSequence.Duration());
}
Expand All @@ -451,6 +452,7 @@ private void StepNext()
if (!sequencerController.IsPlaying)
PlaySequence();

// Always uses GotoWithCallbacks() rather than GoTo() to ensure Set steps work as intended.
sequencerController.PlayingSequence.GotoWithCallbacks((sequencerController.PlayingSequence.ElapsedPercentage() +
0.01f) * sequencerController.PlayingSequence.Duration());
}
Expand Down Expand Up @@ -550,6 +552,7 @@ private void SetProgress(float tweenProgress)
if (!sequencerController.IsPlaying)
PlaySequence();

// Always uses GotoWithCallbacks() rather than GoTo() to ensure Set steps work as intended.
sequencerController.PlayingSequence.GotoWithCallbacks(tweenProgress *
sequencerController.PlayingSequence.Duration());
}
Expand All @@ -566,6 +569,7 @@ private float GetCurrentSequencerProgress()

private void SetCurrentSequenceProgress(float progress)
{
// Always uses GotoWithCallbacks() rather than GoTo() to ensure Set steps work as intended.
sequencerController.PlayingSequence.GotoWithCallbacks(progress *
sequencerController.PlayingSequence.Duration());
}
Expand Down
39 changes: 24 additions & 15 deletions Scripts/Runtime/Core/AnimationSequencerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,22 @@ public virtual void PlayBackwards(bool completeFirst = true, Action onCompleteCa
playingSequence.PlayBackwards();
}

public virtual void SetTime(float seconds, bool andPlay = true)
public virtual void SetTime(float seconds, bool andPlay = true, bool withCallbacks = false)
{
if (playingSequence == null)
Play();

// Prepare for GotoWithCallbacks().
PrepareStepsForTimeChange(withCallbacks: withCallbacks, isSkippingToEnd: false);

playingSequence.Goto(seconds, andPlay);
// Always uses GotoWithCallbacks() rather than GoTo() to ensure Set steps work as intended.
playingSequence.GotoWithCallbacks(seconds, andPlay);

// Reset.
ResetStepsAfterTimeChange();
}

public virtual void SetProgress(float targetProgress, bool andPlay = true)
public virtual void SetProgress(float targetProgress, bool andPlay = true, bool withCallbacks = false)
{
if (playingSequence == null)
Play();
Expand All @@ -212,7 +219,7 @@ public virtual void SetProgress(float targetProgress, bool andPlay = true)

float duration = playingSequence.Duration();
float finalTime = targetProgress * duration;
SetTime(finalTime, andPlay);
SetTime(finalTime, andPlay, withCallbacks);
}

public virtual void TogglePause()
Expand Down Expand Up @@ -246,31 +253,33 @@ public virtual void Complete(bool withCallbacks = true)
return;

// Prepare for Complete().
for (int i = 0; i < animationSteps.Length; i++)
{
AnimationStepBase animationStepBase = animationSteps[i];
animationStepBase.IsSkippingToEnd = true;
if (animationStepBase is InvokeCallbackAnimationStep invokeCallbackStep)
{
invokeCallbackStep.AllowCallbacks = withCallbacks;
}
}
PrepareStepsForTimeChange(withCallbacks: withCallbacks, isSkippingToEnd: true);

// Always fire callbacks so the Set steps are always fired.
playingSequence.Complete(withCallbacks: true);

// Reset.
ResetStepsAfterTimeChange();
}

private void PrepareStepsForTimeChange(bool withCallbacks, bool isSkippingToEnd)
{
for (int i = 0; i < animationSteps.Length; i++)
{
AnimationStepBase animationStepBase = animationSteps[i];
animationStepBase.IsSkippingToEnd = false;
animationStepBase.IsSkippingToEnd = isSkippingToEnd;
if (animationStepBase is InvokeCallbackAnimationStep invokeCallbackStep)
{
invokeCallbackStep.AllowCallbacks = true;
invokeCallbackStep.AllowCallbacks = withCallbacks;
}
}
}

private void ResetStepsAfterTimeChange()
{
PrepareStepsForTimeChange(withCallbacks: true, isSkippingToEnd: false);
}

public virtual void Rewind(bool includeDelay = true)
{
if (playingSequence == null)
Expand Down