Task/UniTask-based
Main Thread dispatcher classes, no GameObjects involved.
- Simple to use: call
MainThreadTask.Runand that's it, your action will run on the Main Thread! asyncmethodMainThreadTask.RunAsync, so you canawaitfor execution to complete- TaskScheduler and TaskFactory used for running Tasks on the Main Thread are available
- UniTask-based implementation in
MainThreadUniTaskclass, conditionally compiled if UniTask is detected in project System.Actionextension methodsInvokeOnMainThreadandInvokeOnMainThreadAsync- No
GameObjects involved - Simple implementations with around 50 lines of code each
Either:
- Install via Unity Package Manager using the following URL:
https://github.com/gilzoide/unity-main-thread-task.git#1.0.0
-
Copy the implementation file Runtime/MainThreadTask.cs and/or Runtime/MainThreadUniTask.cs to your project.
If using UniTask, either remove the
#if/#endiflines fromMainThreadUniTask.csor defineHAVE_UNITASKin your project's scripting define symbols.