Synchronization is a Unity3D package which allow to execute synchronized tasks.
- Execute synchronized tasks
- Execute asynchronized tasks
- Define ordered tasks queue with synchronization
Define your task by extending Executable
class:
public class MyTask : Executable {
}
For asynchronized task, implements Execute
parameters less method :
public override void Execute() {
// Do async task
}
Next task in the queue will be executed right after this method execution.
For synchronized task, implements Execute
with parameters method :
public override void Execute(TaskCompletionSource<bool> completion)
{
// Do sync task
}
When your synchronized task is completed, set completion result to true. It will trigger the next task.
completion.SetResult(true);
Add SynchronizedTaskExecutor class to a gameobject, and define your queue by adding task to ExecutableParameters
variable.
You can choose execution mode for each task:
Then run the Execute
method of SynchronizedTaskExecutor from a script or from Unity Inspector.
For example with a Button:
Clone or download this repository.
MIT