Exemple #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);
            }
        }
Exemple #2
0
        public static Task <SceneInstance> LoadSceneAsync(
            string sceneName,
            LoadSceneMode mode  = LoadSceneMode.Single,
            bool activateOnLoad = true)
        {
            if (!SceneManagementSingleton.IsSceneLoadedOrInBackground(sceneName))
            {
                var ao = Addressables.LoadSceneAsync(sceneName, mode, activateOnLoad);

                return(ao.Task);
            }
            else
            {
                return(Task.FromResult <SceneInstance>(default));
Exemple #3
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);
            }
        }