So I would like to make a simple thing: Display a text with a clip, if the mouse is clicked, I want to skip to the end of the clip, and when I reach the end of the clip, if the mouse wasn’t clicked yet, I pause the director until the click finally happens.
Here’s what I have thus far. When the behaviour starts playing, I start a coroutine that waits for the click and skips to the end when it happens.
now I would like to find a way to check at the end of the clip if the mouse was pressed, and if it wasn’t, pause (until it’s finally pressed).
There’s unfortunately no such thing as an “OnBehaviourEnd” callback, so I have no idea how to do this.
Pretty sure checking for the current time in ProcessFrame is a bad idea because it will probably never be called exactly at the end of the clip.
public class WaitForClickBehaviour : PlayableBehaviour
{
public PlayableDirector director;
private bool _wasCLicked = false;
private bool _skipped = false;
private PlayableGraph graph;
private Playable thisPlayable;
public override void OnPlayableCreate(Playable playable)
{
graph = playable.GetGraph();
thisPlayable = playable;
}
public override void OnBehaviourPlay(Playable playable, FrameData info)
{
GameManager.Instance.StartCoroutine(WaitForClick());
}
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
}
private IEnumerator WaitForClick()
{
while (Input.GetMouseButtonDown(0) == false)
{
yield return null;
}
_wasCLicked = true;
JumpToEndofPlayable();
}
private void JumpToEndofPlayable()
{
graph.GetRootPlayable(0).SetTime(graph.GetRootPlayable(0).GetTime() + thisPlayable.GetDuration());
}
}