Last active
August 14, 2023 11:39
-
-
Save restush/cdd2dbc12a544dd98e8a309b046e7a7d to your computer and use it in GitHub Desktop.
UniTask Unity Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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