Saga Documentation 0.9.434-4

Conventions and Common Usage Patterns

Table of Contents

Async

Many of the functions included in this package are async UniTask. To use these in your MonoBehaviour, make sure to prefix lifetime methods with async:

async UniTaskVoid Start() { ... } 

WebGL

If targeting WebGL, all async/await functions should use UniTask. UniTask runs all tasks asynchronously on the main thread, which is required by WebGL builds.

Singleton

If Unity only need to access one Saga instance as one user, a global singleton may be useful.


private static Client _saga;
private static Mutex _mut = new Mutex();

public static async UniTask<Client> Saga() {
    _mut.WaitOne();

    if (_saga == null) {
        var result = await Client.Create(...);
        if (!result.IsSuccess) throw new Exception();
        
        _saga = result.Data;
    }
    
    return _saga;
}