Example #1
0
 void Start()
 {
     if (SceneManager.GetActiveScene().name == "Gameover")
     {
         _nowScene = GameObject.Find("nowScene").GetComponent <NowScene> ();
         scenename = _nowScene.scenename;
     }
 }
Example #2
0
        /// <summary>
        /// シーン切り替え処理
        /// </summary>
        /// <returns></returns>
        IEnumerator SceneChange()
        {
            // シーンを非アクティブで読み込み開始
            loadingSceneOperations[loadingSceneOperationCount] = SceneManager.LoadSceneAsync(NextScene.ToString(), LoadSceneMode.Additive);
            loadingSceneOperations[loadingSceneOperationCount].allowSceneActivation = false;
            loadingSceneOperationCount++;

            // フェードアウト
            yield return(Fade.StartFade(Fade.FadeStateType.Out, fadeTime, true));

            // 不要になったシーンを解放する
            if (NowScene != SceneType.None)
            {
                unloadSceneOperations[unloadSceneCount] = SceneManager.UnloadSceneAsync(NowScene.ToString());
                unloadSceneCount++;
            }
            if (loadedStageName.Length > 0)
            {
                unloadSceneOperations[unloadSceneCount] = SceneManager.UnloadSceneAsync(loadedStageName);
                unloadSceneCount++;
                loadedStageName = "";
            }

            // シーン切り替え
            NowScene  = NextScene;
            NextScene = SceneType.None;

            // シーンをアクティブにする
            loadingSceneOperations[0].allowSceneActivation = true;

            // シーンの解放の完了を待つ
            for (int i = 0; i < unloadSceneCount; i++)
            {
                if (!unloadSceneOperations[i].isDone)
                {
                    yield return(unloadSceneOperations[i]);
                }
            }

            // ゲームならステージ読み込み
            if (NowScene == SceneType.Game)
            {
                loadedStageName = GameParams.StageName;
                loadingSceneOperations[loadingSceneOperationCount] = SceneManager.LoadSceneAsync(loadedStageName, LoadSceneMode.Additive);
                loadingSceneOperationCount++;
            }

            // シーンの読み込みと解放の完了を待つ
            for (int i = 0; i < loadingSceneOperationCount; i++)
            {
                if (!loadingSceneOperations[i].isDone)
                {
                    yield return(loadingSceneOperations[i]);
                }
            }
            // シーンの初期化を待つ
            while (loadingSceneManagerCount < loadingSceneOperationCount)
            {
                yield return(null);
            }
            // フェードアウト完了処理を呼び出す
            for (int i = 0; i < loadingSceneManagerCount; i++)
            {
                loadingSceneManagers[i].OnFadeOutDone();
            }

            // フェードイン
            yield return(Fade.StartFade(Fade.FadeStateType.In, fadeTime));

            // フェードイン完了処理を呼び出す
            for (int i = 0; i < loadingSceneManagerCount; i++)
            {
                loadingSceneManagers[i].OnFadeInDone();
            }

            // シーン切り替え完了
            loadingSceneOperationCount = 0;
            loadingSceneManagerCount   = 0;
            unloadSceneCount           = 0;

            IsChanging = false;
            isBooting  = false;
            enabled    = false;
        }