Пример #1
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()));
            }
        }
Пример #2
0
        /// @param sceneName
        ///     Name of the scene to switch to
        /// @param transitionPrefabName
        ///     Name of the prefab inside the default transition folder to use for the transition screen
        /// @param [optional] callback
        ///     Function to call when the transiton is done
        ///
        public void SwitchToScene(string sceneName, string transitionPrefabName, Action callback = null)
        {
            m_scenes.Clear();
            AsyncOperation      loadSceneOperation = SceneManager.LoadSceneAsync(sceneName);
            SceneTransitionView transitionView     = CreateTransitionView(transitionPrefabName);

            GlobalDirector.ExecuteCoroutine(StartTransition(loadSceneOperation, transitionView, callback));
        }
Пример #3
0
        /// @param transitionPrefabName
        ///     Name of the transition prefab to load and instantiate
        ///
        /// @return The SceneTransitionView of the transitionUI object
        ///
        private SceneTransitionView CreateTransitionView(string transitionPrefabName)
        {
            SceneTransitionView transitionView = null;
            string fullPath           = k_pathTransitionUI + transitionPrefabName;
            var    transitionUIPrefab = Resources.Load(fullPath) as GameObject;

            if (transitionUIPrefab == null)
            {
                Debug.LogError(string.Format("Failed to load transition UI at '{0}'", fullPath));
            }
            else
            {
                var transitionObject = GameObject.Instantiate(transitionUIPrefab);
                GameObject.DontDestroyOnLoad(transitionObject);
                transitionObject.SetActive(false);
                transitionView = transitionObject.GetComponent <SceneTransitionView>();

                var canvas = transitionObject.GetComponent <Canvas>();
                canvas.sortingOrder = k_defaultCanvasSortOrder;
            }

            return(transitionView);
        }