예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }
 public static UniTask ConfigureAwait(this AsyncOperation operation, Action <float> onProgress, CancellationToken ct)
 => operation.ConfigureAwait(new ProgressHandler(onProgress), cancellation: ct);