Hello, I've basically created a Custom Command called "doMoveAnimation" that moves a character based on a provided sequence. I have a parameter called "pause" that indicates that the next Naninovel lines can only be read after the movement has been completed.
In the case above, I would execute the first two lines and then wait for the characters to finish their movement before reading the lines with IDs 103 and 104. Can you help me with any ideas on how to solve this issue?
[CommandAlias("doMoveAnimation")]
public class TreatingInputMove : Command
{
//...
//Other Parameters...
//...
public BooleanParameter Pause; // Control whether to pause or not
//UniTaskCompletionSource to handle asynchronous task completion
private readonly UniTaskCompletionSource<object> completionSource = new UniTaskCompletionSource<object>();
public override async UniTask ExecuteAsync(AsyncToken asyncToken = default)
{
//...
//Some code That will call other Scripts...
//...
if(Assigned(Pause) && Pause)//Checking if the Pause is assigned and if is true
{
CommandsQueue.OnEndCommand += CommandCompleted;//Attaching CommandCompleted to the OnEndCommand event
await completionSource.Task; //Waiting for the task to completion
}
else // If Pause is not assigned or if Pause is false, we complete the task immediately
await UniTask.CompletedTask;
}
//When OnEndCommand is triggered we inform that we can continue with the naninovel script...
public void CommandCompleted()
{
completionSource.TrySetResult(null); //task is completed
}
}