Пример #1
0
    } // Start

    private void OnNewSceneLoaded(EScenes newScene)
    {
        if (newScene == EScenes.Game)
        {
            InitGame();
        }
    } // OnNewSceneLoaded
        /// <summary>
        /// Load the scene.
        /// </summary>
        /// <param name="scene">Scene.</param>
        /// <param name="sceneData">Data.</param>
        /// <param name="additiveLoadScenes">Additive load scenes.</param>
        /// <param name="autoTransition">If set to <c>true</c> auto move.</param>
        public static void LoadScene(EScenes scene, SceneDataPackBase sceneData = null, EScenes[] additiveLoadScenes = null, bool autoTransition = true)
        {
            // Send default scene data.
            if (sceneData == null)
            {
                sceneData = new SceneDataPackBase(TransitionManagerInstance.CurrentGameScene, additiveLoadScenes);
            }

            TransitionManagerInstance.StartTransition(scene, sceneData, additiveLoadScenes, autoTransition);
        }
Пример #3
0
    private void SceneTransitionLoadWithPause(EScenes nextScene, string nextSceneName)
    {
        SceneFadeIn();

        if (this.currentSceneState == ESceneState.IN)
        {
            StopAllCoroutines();
            return;
        }
        else if (this.currentSceneState == ESceneState.PLAY)
        {
            if (!_isLoadSceneAsync)
            {
                this.loadFinish      = false;
                this.pauseTransition = true;
                StartCoroutine(LoadNewScene(HasNextScene() ? this.nextSceneName : nextSceneName));
            }
            else
            {
                progress = this._async.progress;
                if (this.progress >= 0.9F)
                {
                    this.loadFinish = true;
                    if (!this.pauseTransition)
                    {
                        ClosingScene(this.timeToClosePaused > 0 ? this.timeToClosePaused : 1.0F);
                    }
                }
                return;
            }
        }
        else if (this.currentSceneState == ESceneState.OUT)
        {
            SceneFadeOut();
        }

        if (this.currentSceneState == ESceneState.OUT &&
            this._fadeController.fadeState == FadeController.EFadeState.OUT_COMPLETE)
        {
            this.currentSceneState = ESceneState.IN;
            this.currentScene      = HasNextScene() ? this.nextScene : nextScene;
            print("Cena: " + currentScene.ToString());
            this._fadeController.CleanFade();
            this._async.allowSceneActivation = true;
            this.loadFinish = false;

            if (this.nextScene != EScenes.NONE && this.nextSceneName != "")
            {
                this.nextScene     = EScenes.NONE;
                this.nextSceneName = "";
            }
        }
    }
    } // LoadNewScene

    private int ESceneToIndex(EScenes scene)
    {
        switch (scene)
        {
        case EScenes.Logo: return(0);

        case EScenes.MainMenu: return(1);

        case EScenes.Game: return(2);
        }
        return(0);
    } // ESceneToIndex
    public void LoadNewScene(EScenes scene)
    {
        _currentScene = scene;

        int sceneIndex = ESceneToIndex(scene);

        UnityEngine.SceneManagement.SceneManager.LoadScene(sceneIndex);

        if (OnNewSceneLoaded != null)
        {
            OnNewSceneLoaded(scene);
        }
    } // LoadNewScene
        /// <summary>
        /// Starts the transition.
        /// </summary>
        /// <param name="nextScene">Next scene.</param>
        /// <param name="sceneData">Scene data.</param>
        /// <param name="additiveLoadScenes">Additive load scenes.</param>
        /// <param name="autoTransition">If set to <c>true</c> auto transition.</param>
        public void StartTransition(
            EScenes nextScene,
            SceneDataPackBase sceneData,
            EScenes[] additiveLoadScenes,
            bool autoTransition
            )
        {
            if (isRunning)
            {
                return;
            }

            StartCoroutine(TransitionCoroutine(nextScene, sceneData, additiveLoadScenes, autoTransition));
        }
Пример #7
0
    private void AutomaticSceneTransitionNoFade(EScenes nextScene, string nextSceneName)
    {
        this.currentSceneState = ESceneState.IN;
        Application.LoadLevel(HasNextScene() ? this.nextSceneName : nextSceneName);
        this.currentScene = HasNextScene() ? this.nextScene : nextScene;
        print("Cena: " + currentScene.ToString());
        this._fadeController.CleanFade();

        if (this.nextScene != EScenes.NONE && this.nextSceneName != "")
        {
            this.nextScene     = EScenes.NONE;
            this.nextSceneName = "";
        }
    }
        /// <summary>
        /// Awake this instance.
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            DontDestroyOnLoad(gameObject);

            try
            {
                currentGameScene = (EScenes)SceneManager.GetActiveScene().buildIndex;
            }
            catch
            {
                Debug.Log("Failed get current scene");
                // Fill any scene.
                currentGameScene = EScenes.Title;
            }
        }
Пример #9
0
    private void SceneTransition(EScenes nextScene, string nextSceneName)
    {
        if (this.currentSceneState == ESceneState.PLAY)
        {
            return;
        }

        if (this.currentSceneState == ESceneState.OUT &&
            (this._fadeController.fadeState == FadeController.EFadeState.NONE ||
             this._fadeController.fadeState == FadeController.EFadeState.DISABLED))
        {
            this.currentSceneState = ESceneState.IN;
        }

        SceneFadeIn();

        if (this.currentSceneState == ESceneState.IN)
        {
            return;
        }

        if (this.currentSceneState == ESceneState.OUT)
        {
            SceneFadeOut();
        }

        if (this.currentSceneState == ESceneState.OUT &&
            this._fadeController.fadeState == FadeController.EFadeState.OUT_COMPLETE)
        {
            this.currentSceneState = ESceneState.IN;
            Application.LoadLevel(HasNextScene() ? this.nextSceneName : nextSceneName);
            this.currentScene = HasNextScene() ? this.nextScene : nextScene;
            print("Cena: " + currentScene.ToString());
            this._fadeController.CleanFade();

            if (this.nextScene != EScenes.NONE && this.nextSceneName != "")
            {
                this.nextScene     = EScenes.NONE;
                this.nextSceneName = "";
            }
        }
    }
Пример #10
0
    private void AutomaticSceneTransition(EScenes nextScene, string nextSceneName, float timeFade)
    {
        if (Input.GetKey(KeyCode.Escape))
        {
            this.currentSceneState = ESceneState.OUT;
        }

        SceneFadeIn();

        if (this.currentSceneState == ESceneState.IN)
        {
            StopAllCoroutines();
            return;
        }
        else if (this.currentSceneState == ESceneState.PLAY)
        {
            StartCoroutine(WaitToClosing(timeFade));
        }
        else if (this.currentSceneState == ESceneState.OUT)
        {
            SceneFadeOut();
        }

        if (this.currentSceneState == ESceneState.OUT &&
            this._fadeController.fadeState == FadeController.EFadeState.OUT_COMPLETE)
        {
            this.currentSceneState = ESceneState.IN;
            Application.LoadLevel(HasNextScene() ? this.nextSceneName : nextSceneName);
            this.currentScene = HasNextScene() ? this.nextScene : nextScene;
            print("Cena: " + currentScene.ToString());
            this._fadeController.CleanFade();

            if (this.nextScene != EScenes.NONE && this.nextSceneName != "")
            {
                this.nextScene     = EScenes.NONE;
                this.nextSceneName = "";
            }
        }
    }
        /// <summary>
        /// Transition coroutine.
        /// </summary>
        /// <returns>The coroutine.</returns>
        /// <param name="nextScene">Next scene.</param>
        /// <param name="sceneData">Scene data.</param>
        /// <param name="additiveLoadScenes">Additive load scenes.</param>
        /// <param name="autoTransition">If set to <c>true</c> auto transition.</param>
        private IEnumerator TransitionCoroutine(
            EScenes nextScene,
            SceneDataPackBase sceneData,
            EScenes[] additiveLoadScenes,
            bool autoTransition
            )
        {
            isRunning = true;

            CanEndTransition.Value = autoTransition;

            if (fade == null)
            {
                Initialize();
                yield return(null);
            }

            // Start transition.
            fade.FadeIn(1.0f);

            // Wait for transition animation.
            yield return(onTransitionFinishedInternal.FirstOrDefault().ToYieldInstruction());

            // Set data what gave by previous scene.
            SceneLoader.PreviousSceneData = sceneData;

            // Load main scene as single scene.
            yield return(SceneManager.LoadSceneAsync(nextScene.ToString(), LoadSceneMode.Single));

            // Load sub scenes.
            if (additiveLoadScenes != null)
            {
                yield return(additiveLoadScenes.Select(scene =>
                                                       SceneManager.LoadSceneAsync((int)scene, LoadSceneMode.Additive)
                                                       .AsObservable()).WhenAll().ToYieldInstruction());
            }
            yield return(null);

            // Release unused assets memories.
            Resources.UnloadUnusedAssets();
            GC.Collect();

            yield return(null);

            // Set current scene.
            currentGameScene = nextScene;

            // Publish notification of scene loaded.
            onAllSceneLoaded.OnNext(Unit.Default);

            if (!autoTransition)
            {
                // Wait for OpenLoadedNextScene function.
                yield return(CanEndTransition.FirstOrDefault(x => x).ToYieldInstruction());
            }

            CanEndTransition.Value = false;


            // Start fadeout animation.
            fade.FadeOut(1.0f);

            // Wait for completed to open fade.
            yield return(onTransitionFinishedInternal.FirstOrDefault().ToYieldInstruction());

            // Publish notification of finished scene transition.
            onTransitionAnimationFinishedSubject.OnNext(Unit.Default);

            isRunning = false;
        }
Пример #12
0
 public void SetNextScene(EScenes nextScene, string nextSceneName)
 {
     this.nextScene     = nextScene;
     this.nextSceneName = nextSceneName;
 }
Пример #13
0
    private void SceneTransitionLoadWithCommand(EScenes nextScene, string nextSceneName)
    {
        if (!HasNextScene() && !canLoadNextScene)
        {
            if (this.currentSceneState == ESceneState.PLAY)
            {
                return;
            }

            if (this.currentSceneState == ESceneState.OUT &&
                (this._fadeController.fadeState == FadeController.EFadeState.NONE ||
                 this._fadeController.fadeState == FadeController.EFadeState.DISABLED))
            {
                this.currentSceneState = ESceneState.IN;
            }

            SceneFadeIn();

            if (this.currentSceneState == ESceneState.IN)
            {
                StopAllCoroutines();
                return;
            }
        }

        if (this.canLoadNextScene)
        {
            if (!_isLoadSceneAsync)
            {
                this.loadFinish      = false;
                this.pauseTransition = true;
                StartCoroutine(LoadNewScene(HasNextScene() ? this.nextSceneName : nextSceneName));
            }
            else
            {
                progress = this._async.progress;
                if (this.progress >= 0.9F)
                {
                    this.loadFinish = true;
                }
                return;
            }
        }

        if (this.currentSceneState == ESceneState.OUT)
        {
            SceneFadeOut();
        }

        if (this.currentSceneState == ESceneState.OUT &&
            this._fadeController.fadeState == FadeController.EFadeState.OUT_COMPLETE)
        {
            this.currentSceneState = ESceneState.IN;
            this.currentScene      = HasNextScene() ? this.nextScene : nextScene;
            if (HasNextScene())
            {
                Application.LoadLevel(HasNextScene() ? this.nextSceneName : nextSceneName);
            }
            print("Cena: " + currentScene.ToString());
            this._fadeController.CleanFade();
            this._async.allowSceneActivation = true;
            this.loadFinish = false;

            if (this.nextScene != EScenes.NONE && this.nextSceneName != "")
            {
                this.nextScene     = EScenes.NONE;
                this.nextSceneName = "";
            }

            this.canLoadNextScene = false;
        }
    }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:SceneDataPackBase"/> class.
 /// </summary>
 /// <param name="previousScene">Previous scene.</param>
 /// <param name="previousAdditiveScenes">Previous additive scenes.</param>
 /// <param name="additiveScenes">Additive scenes.</param>
 public SceneDataPackBase(EScenes previousScene, EScenes[] previousAdditiveScenes)
 {
     this.previousScene          = previousScene;
     this.previousAdditiveScenes = previousAdditiveScenes;
 }