async/await
Each script supports asynchronous wait by async / await.
Asynchronous wait method
The implemented asynchronous wait method is as follows.
- PlayableBehaviour.Yield
Wait until the next OnUpdate call. - ActionBehaviour.WaitForExecute
Wait until the next OnExecute call.
After waiting, it will be treated the same as in OnExecute, so you can call FinishExecute.
Yield usage example
|
|
When this script is executed, await Yield();
is executed 10 times, and then 9
is output to Console for transition.
Note that in this example, the OnStateBegin call and the first await Yield ();
call will be in the same frame.
CancellationTokenOnEnd
PlayableBehaviour.CancellationTokenOnEnd
A token that cancels asynchronous waits when exiting a node or destroying an instance.
The Yield and WaitForExecute methods are now canceled with this token.
Use this cancel token if necessary if you want other methods to perform asynchronous wait processing.
If canceled, a System.OperationCanceledException
will be thrown.
The caller should catch the exception and cancel it appropriately.
UniTask
If you have UniTask installed, you can convert it to UniTask type with Yeild().ToUniTask()
.
See Use of UniTask to enable the ToUniTask method.