private SceneTransition SetupTransition(SceneTransition transition, SceneTransition.Directions direction)
 {
     transition                  = (transition == null) ? EmptyTransition.Create() : transition;
     transition.Direction        = direction;
     transition.gameObject.name += direction.ToString();
     transition.gameObject.SetActive(false);
     transition.Transform.parent = this.Transform;
     return(transition);
 }
 private void DestroyNavigationElements(SceneTransition transitionOut, SceneTransition transitionIn, LoadingIndicator progressIndicator)
 {
     if (transitionOut)
     {
         GameObject.Destroy(transitionOut.gameObject);
         transitionOut = null;
     }
     if (transitionIn)
     {
         GameObject.Destroy(transitionIn.gameObject);
         transitionIn = null;
     }
     if (progressIndicator)
     {
         GameObject.Destroy(progressIndicator.gameObject);
         progressIndicator = null;
     }
 }
        private IEnumerator RunTransitionIn(
            SceneController sceneController,
            SceneTransition transitionOut,
            SceneTransition transitionIn,
            LoadingIndicator loader
            )
        {
            transitionIn.OnSceneWillTransitionIn(sceneController, transitionIn);
            transitionOut.OnSceneWillTransitionIn(sceneController, transitionIn);
            loader.OnSceneWillTransitionIn(sceneController, transitionIn);

            if (sceneController)
            {
                sceneController.OnSceneWillTransitionIn(sceneController, transitionIn);
            }

            if (this.OnSceneWillTransitionIn != null)
            {
                this.OnSceneWillTransitionIn(sceneController, transitionIn);
            }

            yield return(StartCoroutine(transitionIn.Run()));

            this.State = SceneNavigator.States.Ready;

            if (this.OnSceneDidTransitionIn != null)
            {
                this.OnSceneDidTransitionIn(sceneController, transitionIn);
            }

            if (sceneController)
            {
                sceneController.OnSceneDidTransitionIn(sceneController, transitionIn);
            }

            loader.OnSceneDidTransitionIn(sceneController, transitionIn);
            transitionOut.OnSceneDidTransitionIn(sceneController, transitionIn);
            transitionIn.OnSceneDidTransitionIn(sceneController, transitionIn);
        }
        /*
         * public void NavigateToScene(string sceneName) {
         *      NavigateToScene(sceneName, null, true);
         * }
         *
         * public void NavigateToScene(string sceneName, bool unloadCurrentScene) {
         *      NavigateToScene(sceneName, null, unloadCurrentScene);
         * }
         *
         * public void NavigateToScene(string sceneName, LoadingIndicator progressIndicator) {
         *      NavigateToScene(sceneName, progressIndicator, true);
         * }
         *
         * public void NavigateToScene(string sceneName, LoadingIndicator progressIndicator, bool unloadCurrentScene) {
         *      NavigateToScene(sceneName, FadeTransition.Create(), FadeTransition.Create(), progressIndicator, unloadCurrentScene);
         * }
         *
         * public void NavigateToScene(string sceneName, SceneTransition transitionOut, SceneTransition transitionIn) {
         *      NavigateToScene(sceneName, transitionOut, transitionIn, null, true);
         * }
         *
         * public void NavigateToScene(string sceneName, SceneTransition transitionOut, SceneTransition transitionIn, bool unloadCurrentScene) {
         *      NavigateToScene(sceneName, transitionOut, transitionIn, null, unloadCurrentScene);
         * }
         *
         * public void NavigateToScene(string sceneName, SceneTransition transitionOut, SceneTransition transitionIn, LoadingIndicator progressIndicator) {
         *      NavigateToScene(sceneName, transitionOut, transitionIn, progressIndicator, true);
         * }
         *
         * public void NavigateToScene(string sceneName, SceneTransition transitionOut, SceneTransition transitionIn, LoadingIndicator progressIndicator, bool unloadCurrentScene) {
         *      NavigateToScene(sceneName, transitionOut, transitionIn, progressIndicator, unloadCurrentScene, unloadCurrentScene);
         * }
         */

        public void NavigateToScene(
            SceneReference sceneReference,
            SceneTransition transitionOut,
            SceneTransition transitionIn,
            LoadingIndicator progressIndicator,
            bool unloadCurrentScene,
            bool unloadUnusedAssets
            )
        {
            if (this.CurrentScene.Equals(sceneReference))
            {
                DestroyNavigationElements(transitionOut, transitionIn, progressIndicator);
                Debug.LogWarning(string.Format(
                                     "SceneNavigator : NavigateToScene \"{0}\" aborted because it is the current scene.",
                                     sceneReference.ScenePath
                                     ));
                return;
            }

            if (this.IsBusy)
            {
                DestroyNavigationElements(transitionOut, transitionIn, progressIndicator);
                Debug.LogWarning(string.Format(
                                     "SceneNavigator : NavigateToScene \"{0}\" aborted because a navigation is already in progress.",
                                     sceneReference.ScenePath
                                     ));
                return;
            }

            StartCoroutine(RunNavigateToScene(
                               sceneReference,
                               transitionOut,
                               transitionIn,
                               progressIndicator,
                               unloadCurrentScene,
                               unloadUnusedAssets
                               ));
        }
Exemple #5
0
 virtual public void OnSceneDidTransitionIn(SceneController sceneController, SceneTransition transition)
 {
 }
Exemple #6
0
 //
 // ISceneTransitionObserver
 //
 virtual public void OnSceneWillTransitionOut(SceneController sceneController, SceneTransition transition)
 {
 }
 virtual public void OnSceneDidTransitionIn(SceneController sceneController, SceneTransition transition)
 {
     Destroy(this.gameObject);
 }
 override public void OnSceneWillTransitionIn(SceneController sceneController, SceneTransition transition)
 {
     if (this.Direction == SceneTransition.Directions.In)
     {
         if (sceneController)
         {
             sceneController.Content.SetActive(true);
         }
         if (this.PreviousSceneController)
         {
             this.PreviousSceneController.Content.SetActive(false);
         }
     }
     else
     {
         gameObject.SetActive(false);
     }
 }
 //
 // ISceneTransitionObserver
 //
 override public void OnSceneDidTransitionOut(SceneController sceneController, SceneTransition transition)
 {
     if (this.Direction == SceneTransition.Directions.In)
     {
         gameObject.SetActive(true);
         if (sceneController)
         {
             this.PreviousSceneController = sceneController;
         }
     }
 }
 //
 // ISceneTransitionObserver
 //
 override public void OnSceneDidTransitionOut(SceneController sceneController, SceneTransition transition)
 {
     if (this.Direction == SceneTransition.Directions.In)
     {
         gameObject.SetActive(true);
     }
     if (sceneController)
     {
         sceneController.Content.SetActive(false);
     }
 }
        //
        // Scene Navigation
        //
        private IEnumerator RunNavigateToScene(
            SceneReference sceneReference,
            SceneTransition transitionOut,
            SceneTransition transitionIn,
            LoadingIndicator loader,
            bool unloadCurrentScene,
            bool unloadUnusedAssets
            )
        {
            this.State       = SceneNavigator.States.Busy;
            this.TargetScene = sceneReference;

            LoadScene(this.TargetScene, true);

            transitionIn  = SetupTransition(transitionIn, SceneTransition.Directions.In);
            transitionOut = SetupTransition(transitionOut, SceneTransition.Directions.Out);
            loader        = SetupLoadingIndicator(loader);

            SceneController prevSceneController;

            prevSceneController = this.CurrentSceneController;
            yield return(StartCoroutine(RunTransitionOut(prevSceneController, transitionOut, transitionIn, loader)));

            yield return(StartCoroutine(AwaitSceneLoadComplete(sceneReference)));

            this.PreviousScene = this.CurrentScene;
            this.CurrentScene  = this.TargetScene;

            SceneController nextSceneController;

            nextSceneController = this.CurrentSceneController;

            if (nextSceneController == null)
            {
                throw new System.InvalidOperationException(string.Format(
                                                               "SceneNavigator : Scene \"{0}\" was loaded but did not register with SceneNavigator.",
                                                               sceneReference.ScenePath
                                                               ));
            }

            // April 7, 2016
            //
            // We're moving scene unloading from after the next scene transitions in to between the transition in
            // and transition out. This solves some issues with load times caused by UnloadUnusedAssets() fighting
            // with things being loaded by the next scene.
            //
            // IMPORTANT: Moving the unloading prevents us from creating transitions where the scenes
            // overlap (like cross-fading between scenes), which should be find because we've never
            // actually implemented a transition that requires both scenes to exist.

            if (prevSceneController && unloadCurrentScene)
            {
                yield return(UnloadScene(prevSceneController.Scene, unloadUnusedAssets));
            }

            if (this.OnWillNavigateToScene != null)
            {
                this.OnWillNavigateToScene(nextSceneController);
            }

            nextSceneController.Content.SetActive(true);
            yield return(StartCoroutine(AwaitSceneReady(nextSceneController)));

            SceneManager.SetActiveScene(nextSceneController.gameObject.scene);
            yield return(StartCoroutine(RunTransitionIn(nextSceneController, transitionOut, transitionIn, loader)));

            if (this.OnDidNavigateToScene != null)
            {
                this.OnDidNavigateToScene(nextSceneController);
            }
        }