Home

Awesome

<p align="center"> <img align="center" src="https://raw.githubusercontent.com/coryleach/UnityPackages/master/Documentation/GameframeFace.gif" /> </p> <h1 align="center">Gameframe.Async 👋</h1> <!-- BADGE-START -->

GitHub release (latest by date including pre-releases) openupm license twitter

<!-- BADGE-END -->

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)<br/> Select "Add package from git URL...", fill in the pop-up with the following link:<br/> https://github.com/coryleach/UnityAsync.git#1.0.7<br/>

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:

{
  "dependencies": {
    "com.gameframe.async": "https://github.com/coryleach/UnityAsync.git#1.0.7",
    ...
  },
}
<!-- DOC-START --> <!-- Changes between 'DOC START' and 'DOC END' will not be modified by readme update scripts -->

Using OpenUPM

The package is available on the openupm registry. It's recommended to install it via openupm-cli.

openupm add com.gameframe.async

Quick Start

Start and Await a coroutine from anywhere

//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

//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


// 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

<!-- DOC-END -->

Author

👤 Cory Leach

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by Gameframe.Packages