https://github.com/coryleach/UnityAsync
Task and Async Utility Package for Unity. Start co-routines from anywhere.
https://github.com/coryleach/UnityAsync
async async-utility coroutine openupm package package-manager tasks unity unity-package unity-scripts unity-thread unity3d unity3d-plugin unitypackage upm
Last synced: 8 months ago
JSON representation
Task and Async Utility Package for Unity. Start co-routines from anywhere.
- Host: GitHub
- URL: https://github.com/coryleach/UnityAsync
- Owner: coryleach
- License: apache-2.0
- Created: 2019-08-29T21:38:45.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-08-30T17:28:59.000Z (over 2 years ago)
- Last Synced: 2024-11-12T17:03:01.261Z (about 1 year ago)
- Topics: async, async-utility, coroutine, openupm, package, package-manager, tasks, unity, unity-package, unity-scripts, unity-thread, unity3d, unity3d-plugin, unitypackage, upm
- Language: C#
- Homepage:
- Size: 85 KB
- Stars: 85
- Watchers: 2
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
Gameframe.Async 👋

[](https://openupm.com/packages/com.gameframe.async/)
[](https://github.com/coryleach/UnityAsync/blob/master/LICENSE)
[](https://twitter.com/coryleach)
> Async task utility package for Unity
> Helper methods for starting tasks on the Unity thread.
> Start and await coroutines from any thread.
## Quick Package Install
#### Using UnityPackageManager (for Unity 2019.3 or later)
Open the package manager window (menu: Window > Package Manager)
Select "Add package from git URL...", fill in the pop-up with the following link:
https://github.com/coryleach/UnityAsync.git#1.0.7
#### Using UnityPackageManager (for Unity 2019.1 or later)
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```js
{
"dependencies": {
"com.gameframe.async": "https://github.com/coryleach/UnityAsync.git#1.0.7",
...
},
}
```
### Using OpenUPM
The package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).
```console
openupm add com.gameframe.async
```
## Quick Start
### Start and Await a coroutine from anywhere
```c#
//Start a coroutine from anywhere without a monobehaviour
//Your coroutine will run on the main thread
var task = CoroutineRunner.RunAsync(MyCoroutine());
//You can await the returned task which will complete when the coroutine is done
await task;
```
### Start a Task on the main unity thread from anywhere
```c#
//This will execute MyMethod on the main Unity thread
var task = UnityTaskUtil.RunOnUnityThreadAsync(MyMethod);
//A task is returned that you can await
await task;
```
### Switch between Main thread and Background thread in any task
```c#
// Currently on main thread
await Awaiters.BackgroundThread;
//You should now be on a background thread
//Await one frame
await Awaiters.NextFrame;
//Currently on a background thread
await Awaiters.MainUnityThread;
//Task is now running on the Unity main thread
```
## Author
👤 **Cory Leach**
* Twitter: [@coryleach](https://twitter.com/coryleach)
* Github: [@coryleach](https://github.com/coryleach)
## Show your support
Give a ⭐️ if this project helped you!
***
_This README was generated with ❤️ by [Gameframe.Packages](https://github.com/coryleach/unitypackages)_