示例#1
0
 /// <summary>
 /// ロード済シーンルートを追加する(SceneRootが自己申告).
 /// </summary>
 public void AddLoadedSceneRoot(SceneRoot sceneRoot)
 {
     if (loadedSceneRootList.Contains(sceneRoot) == false)
     {
         loadedSceneRootList.Add(sceneRoot);
     }
 }
        void CorrectMyName()
        {
            SceneRoot obj = target as SceneRoot;
            //string sceneName = EditorApplication.currentScene;
            string sceneName = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;

            //while (true)
            //{
            //    int index = sceneName.IndexOf("/");
            //    if (index >= 0)
            //    {
            //        sceneName = sceneName.Remove(0, index + 1);
            //    }
            //    else
            //    {
            //        break;
            //    }
            //}
            //sceneName = sceneName.Substring(0, sceneName.LastIndexOf("."));
            target.name = SceneManager.SCENE_ROOT_NAME_HEADER + sceneName;
            Undo.RecordObject(obj, "CorrectMyName");
            EditorUtility.SetDirty(target);
        }
示例#3
0
        /// <summary>
        /// シーンのアクティブ状態を変更する.
        /// </summary>
        IEnumerator ChangeSceneActivation(string SceneName)
        {
            // 現在のシーンをディアクティブにする.
            if (currentSceneRoot)
            {
                currentSceneRoot.SetSceneDeactive();
            }

            // デバッグだったらダミー遅延.
            if (isDebug)
            {
                float startTime = Time.time;
                while (Time.time - startTime < DEBGUG_DUMMY_LOAD_TIME)
                {
                    yield return(null);
                }
            }

            // 偽の読み込み時間分待機
            if (currentSceneRoot != null)
            {
                if (currentSceneRoot.GetSceneName() != "demo")
                {
                    yield return(new WaitForSeconds(DUMMY_LOAD_TIME));
                }
            }

            // Sceneがすでにロードされているなら、そのシーンをアクティブにする.
            bool isLoaded = false;

            foreach (SceneRoot root in loadedSceneRootList)
            {
                if (root.GetSceneName() == SceneName)
                {
                    root.SetSceneActive();
                    currentSceneRoot = root;
                    isLoaded         = true;
#if USE_POOL_MANAGER
                    // プールマネージャー初期化.
                    foreach (KeyValuePair <string, SpawnPool> pool in PoolManager.Pools)
                    {
                        pool.Value.DespawnAll();
                    }
#endif

                    break;
                }
            }

            //ロードされていなかったらAddiveLoadする.
            if (isLoaded == false)
            {
                // シーンが読み込まれるまでの進行度を取得
                AsyncOperation async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(SceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);

                // シーンの有効化を許可
                async.allowSceneActivation = true;

                // 動作が終了していなかったら待機
                while (async.isDone == false || async.progress < 1.0f)
                {
                    yield return(LibBridgeInfo.WaitForEndOfFrame);
                }

                // ロードが終了しているシーンルートを取得
                GameObject sceneRootObj = GetLoadedSceneRoot(SCENE_ROOT_NAME_HEADER + SceneName);
                // 待機時間
                int waitCnt = 0;

                // シーンルートが取得できていない場合は一定時間まで探し続ける
                while (sceneRootObj == null && waitCnt < 120)
                {
                    ++waitCnt;
                    sceneRootObj = GetLoadedSceneRoot(SCENE_ROOT_NAME_HEADER + SceneName);
                    yield return(LibBridgeInfo.WaitForEndOfFrame);
                }

                // まだシーンルートが取得できていない場合
                if (sceneRootObj == null)
                {
                    // エラーを出してロード済シーンルートをダンプ
                    Debug.LogError("Scene root not found:" + SCENE_ROOT_NAME_HEADER + SceneName + " waited" + waitCnt + "frame.");
                    DumpLoadedSceneRoot();

                    // 再度ロードが終了しているシーンルートを取得
                    UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(SceneName, UnityEngine.SceneManagement.LoadSceneMode.Single);
                    sceneRootObj = GetLoadedSceneRoot(SCENE_ROOT_NAME_HEADER + SceneName);

                    // それでもなかったらエラーを出してロード済シーンルートをダンプ
                    if (sceneRootObj == null)
                    {
                        Debug.LogError("no sync load but Scene root not found:" + SCENE_ROOT_NAME_HEADER + SceneName);
                        DumpLoadedSceneRoot();
                    }
                }
                sceneRootObj.transform.parent = gameObject.transform;
                SceneRoot root = sceneRootObj.GetComponent <SceneRoot>();
                currentSceneRoot = root;
                currentSceneRoot.SetSceneActive();
            }

            // unityシーンをアクティブにする.
            if (UnityEngine.SceneManagement.SceneManager.SetActiveScene(UnityEngine.SceneManagement.SceneManager.GetSceneByName(SceneName)) == false)
            {
                Debug.Log("active scene fail");
            }
        }