Skip to content

Instantly share code, notes, and snippets.

@restush
Last active August 14, 2023 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save restush/cdd2dbc12a544dd98e8a309b046e7a7d to your computer and use it in GitHub Desktop.
Save restush/cdd2dbc12a544dd98e8a309b046e7a7d to your computer and use it in GitHub Desktop.
UniTask Unity Cheat Sheet
/// Example Usage
{
...
var operation = await LoadSceneOperation(nameOfScene, (progress)=>slider.value = progress);
...
...
operation.allowSceneActivation = true;
...
}
/// Method
public static async UniTask<AsyncOperation> LoadSceneOperation(string sceneName, System.Action<float> callback=null)
{
var operation = SceneManager.LoadSceneAsync(sceneName);
operation.allowSceneActivation = false;
while (operation.progress <0.9f && callback != null)
{
callback?.Invoke(operation.progress);
}
return await new UniTask<AsyncOperation>(operation);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment