https://github.com/gilzoide/unity-main-thread-task
Task/UniTask-based Main Thread dispatcher classes, no GameObjects involved
https://github.com/gilzoide/unity-main-thread-task
main-thread mainthread task unitask unity unity3d
Last synced: 4 months ago
JSON representation
Task/UniTask-based Main Thread dispatcher classes, no GameObjects involved
- Host: GitHub
- URL: https://github.com/gilzoide/unity-main-thread-task
- Owner: gilzoide
- License: unlicense
- Created: 2022-08-25T21:37:44.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-25T23:20:50.000Z (almost 3 years ago)
- Last Synced: 2024-12-21T11:09:42.732Z (6 months ago)
- Topics: main-thread, mainthread, task, unitask, unity, unity3d
- Language: C#
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Main Thread Task
[Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task)/[UniTask](https://github.com/Cysharp/UniTask)-based
Main Thread dispatcher classes, no `GameObject`s involved.## Features
- Simple to use: call `MainThreadTask.Run` and that's it, your action will run on the Main Thread!
- `async` method `MainThreadTask.RunAsync`, so you can `await` for execution to complete
- [TaskScheduler](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskscheduler)
and [TaskFactory](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.taskfactory)
used for running Tasks on the Main Thread are available
- UniTask-based implementation in `MainThreadUniTask` class, conditionally compiled if UniTask is
detected in project
- `System.Action` extension methods `InvokeOnMainThread` and `InvokeOnMainThreadAsync`
- No `GameObject`s involved
- Simple implementations with around 50 lines of code each## How to install
Either:- Install via [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui-giturl.html)
using the following URL:```
https://github.com/gilzoide/unity-main-thread-task.git#1.0.0
```- Copy the implementation file [Runtime/MainThreadTask.cs](Runtime/MainThreadTask.cs) and/or [Runtime/MainThreadUniTask.cs](Runtime/MainThreadUniTask.cs) to your project.
If using UniTask, either remove the `#if/#endif` lines from `MainThreadUniTask.cs` or define `HAVE_UNITASK` in your project's scripting define symbols.