Exemple #1
0
        /// Coroutine to handle unloading a scene
        ///
        /// @param scene
        ///     Scene to unload
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        private IEnumerator StartUnloadScene(Scene scene, Action callback = null)
        {
            var            sceneName     = scene.name;
            AsyncOperation loadOperation = SceneManager.UnloadSceneAsync(scene);

            yield return(loadOperation);

            callback.SafeInvoke();

            // Scene unloaded is a one-off callback
            if (m_unloadedDelegates.ContainsKey(sceneName) == true)
            {
                m_unloadedDelegates[sceneName].SafeInvoke();
                m_unloadedDelegates.Remove(sceneName);
            }

            // Make sure the correct scene is set active
            for (int index = m_scenes.Count - 1; index >= 0; --index)
            {
                if (m_scenes[index] == sceneName)
                {
                    m_scenes.RemoveAt(index);

                    if (m_scenes.Count > 0)
                    {
                        SetActiveScene(m_scenes.GetLast());
                    }
                    break;
                }
            }

            OnSceneActive.SafeInvoke(GetActiveScene());
        }
Exemple #2
0
        /// Coroutine to handle transitioning to a scene with a transition screen
        ///
        /// @param sceneLoadOperation
        ///     AsyncOperation for the scene loading
        /// @param transitionView
        ///     SceneTransitionView to use as the transition screen
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        private IEnumerator StartTransition(AsyncOperation sceneLoadOperation, SceneTransitionView transitionView, Action callback = null)
        {
            sceneLoadOperation.allowSceneActivation = false;

            if (transitionView != null)
            {
                yield return(GlobalDirector.ExecuteCoroutine(transitionView.Show()));
            }

            sceneLoadOperation.allowSceneActivation = true;
            yield return(new WaitUntil(() => sceneLoadOperation.isDone));

            LocalDirector[] localDirectors = GameObject.FindObjectsOfType <LocalDirector>();
            foreach (LocalDirector localDirector in localDirectors)
            {
                yield return(new WaitUntil(() => localDirector.IsReady()));
            }

            callback.SafeInvoke();
            OnSceneActive.SafeInvoke(GetActiveScene());

            if (transitionView != null)
            {
                yield return(GlobalDirector.ExecuteCoroutine(transitionView.Hide()));
            }
        }
Exemple #3
0
        /// @param sceneName
        ///     Name of the scene to load
        /// @param loadSceneMode
        ///     Way to load the scene (additively to the scene or as a scene switch)
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        private IEnumerator StartLoadScene(string sceneName, LoadSceneMode loadSceneMode, Action callback = null)
        {
            AsyncOperation loadOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);

            yield return(loadOperation);

            m_scenes.Add(sceneName);
            SetActiveScene(sceneName);
            callback.SafeInvoke();
            OnSceneActive.SafeInvoke(GetActiveScene());
        }