예제 #1
0
        IEnumerator LoadAsyncScene(SceneName sceneName)
        {
            LoadSceneResult result;
            AsyncOperation  asyncLoad;

            try
            {
                asyncLoad = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(e);

                result = LoadSceneResult.Failed;
                OnSceneLoadEndedEvent?.Invoke(result, sceneName);
                yield break;
            }

            // Wait until the asynchronous scene fully loads.
            while (!asyncLoad.isDone)
            {
                OnSceneLoadPercentChangedEvent?.Invoke(asyncLoad.progress);
                yield return(null);
            }

            result = LoadSceneResult.Success;
            OnSceneLoadEndedEvent?.Invoke(result, sceneName);
        }
예제 #2
0
        public void ChangeScene(SceneName sceneName, bool async = true)
        {
            LoadSceneResult result;

            if (_loadRoutine != null)
            {
                result = LoadSceneResult.Interrupted;

                StopCoroutine(_loadRoutine);
                OnSceneLoadEndedEvent?.Invoke(result, sceneName);
            }

            OnSceneLoadStartedEvent?.Invoke(sceneName);

            if (async)
            {
                _loadRoutine = StartCoroutine(LoadAsyncScene(sceneName));
            }
            else
            {
                try
                {
                    UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName.ToString());
                }
                catch (Exception e)
                {
                    Debug.LogError(e);

                    result = LoadSceneResult.Failed;
                    OnSceneLoadEndedEvent?.Invoke(result, sceneName);
                    return;
                }

                result = LoadSceneResult.Success;
                OnSceneLoadEndedEvent?.Invoke(result, sceneName);
            }
        }