Saturday, July 18, 2015

AsyncCoroutines - Rather Easy Multithreading for Unity

This is a tiny little library to help you use your multicore CPU in Unity3D.
I've made a brief video overview and the package will be available on the asset store very soon.
It includes a task viewer, which is similar to the process viewer on your operating system. It shows which coroutines are running in the background and foreground, which coroutines are waiting for execution, and how many CPU ticks each coroutine consumes per frame.


To use, make sure you have:
using AsyncCoroutines;
at the top of your script file. Below is an example of a coroutine method which can be started using:
gameObject.StartTask(MyCoroutine());
IEnumerator MyCoroutine() {
    //this statement will move the execution to the background thread
    //pool.
    yield return Schedule.GotoBackground;
    //Do some work here
        
    //This statement will move the execution back into the main unity
    //foreground thread.
    yield return Schedule.GotoForeground;

    //When the coroutine is running in the main thread, yield statements
    //will work as normal.
    yield return null;
    yield return WaitForSeconds(1);
}

No comments:

Popular Posts