public static UniTask LoadSceneAsync( string sceneName, LoadSceneMode mode = LoadSceneMode.Single, Action <AsyncOperation> onStarted = null, Action onCompleted = null, bool allowSceneActivation = true, AsyncOperationProgress onProgress = null) { if (!string.IsNullOrEmpty(sceneName) && !SceneManagementSingleton.IsSceneLoadedOrInBackground(sceneName)) { AsyncOperation ao = SceneManager.LoadSceneAsync(sceneName, mode); ao.allowSceneActivation = allowSceneActivation; onStarted?.Invoke(ao); if (onCompleted != null) { ao.completed += (ctx) => onCompleted.Invoke(); } return(ao.ConfigureAwait(Progress.Create <float>(x => onProgress?.Invoke(x)))); } else { onCompleted?.Invoke(); return(UniTask.CompletedTask); } }
public static UniTask UnloadSceneAsync( string sceneName, Action <AsyncOperation> onCompleted = null, UnloadSceneOptions options = UnloadSceneOptions.None, AsyncOperationProgress onProgress = null) { if (!string.IsNullOrEmpty(sceneName) && SceneManagementSingleton.IsSceneLoadedOrInBackground(sceneName)) { AsyncOperation ao = SceneManager.UnloadSceneAsync(sceneName, options); if (onCompleted != null) { ao.completed += onCompleted; } return(ao.ConfigureAwait(Progress.Create <float>(x => onProgress?.Invoke(x)))); } else { onCompleted?.Invoke(null); return(UniTask.CompletedTask); } }