コード例 #1
0
        /// <summary>
        /// insertEnd: 为false时, 加到后台列表的最前, 切回后台场景时会优先显示该场景.  为true时反之
        /// needNewScene: true时会新建一个Scene结点, 防止新场景还没加载好, 其他地方取不到Scene报错.
        /// </summary>
        /// <param name="insertEnd"></param>
        private void CurSceneInToBack(bool insertEnd = false, bool needNewScene = true)
        {
            if (pCurScene == null)
            {
                return;
            }

            BackSceneData pBackSceneData = new BackSceneData();

            pBackSceneData.backScene     = pCurScene;
            pBackSceneData.backSceneName = sCurSenceName;
            pBackSceneData.backSceneMono = _sceneMono;
            if (insertEnd)
            {
                _backSeneList.Add(pBackSceneData);
            }
            else
            {
                _backSeneList.Insert(0, pBackSceneData);
            }
            pCurScene.transform.name = "BackScene";
            pCurScene.SetActive(false);
            if (needNewScene)
            {
                pCurScene = new GameObject("Scene");
                pCurScene.transform.position = Vector3.zero;
            }
        }
コード例 #2
0
        //切回到后台场景
        public void ChageToBackScene(string sceneName = "")
        {
            if (pCurScene != null)
            {
                //DestroyImmediate(pCurScene);
                //pCurScene = null;
                //SceneManager.UnloadScene(sCurSenceName);
                //Resources.UnloadUnusedAssets();
                CurSceneInToBack(true, false);
            }
            if (_backSeneList.Count == 0)
            {
                return;
            }

            int backSceneIndex = 0;

            if (string.IsNullOrEmpty(sceneName))
            {
                backSceneIndex = 0;//默认第一个
            }
            else
            {
                bool bFound = false;
                for (int i = 0; i < _backSeneList.Count; i++)
                {
                    BackSceneData pBackData = _backSeneList[i];
                    if (pBackData.backSceneName == sceneName)
                    {
                        backSceneIndex = i;
                        bFound         = true;
                        break;
                    }

                    if (!bFound)
                    {
                        return;
                    }
                }
            }

            BackSceneData pData = _backSeneList[backSceneIndex];

            pData.backScene.transform.name = "Scene";
            pData.backScene.SetActive(true);
            pCurScene      = pData.backScene;
            sCurSenceName  = pData.backSceneName;
            _sceneMono     = pData.backSceneMono;
            sceneCameraObj = pCurScene.transform.FindChild(("Cameras/SceneCamera")).gameObject;
            _backSeneList.RemoveAt(backSceneIndex);
        }
コード例 #3
0
        public bool IsInBackScene(string sceneName)
        {
            if (string.IsNullOrEmpty(sceneName))
            {
                return(false);
            }

            for (int i = 0; i < _backSeneList.Count; i++)
            {
                BackSceneData pBackData = _backSeneList[i];
                if (pBackData.backSceneName == sceneName)
                {
                    return(true);
                }
            }
            return(false);
        }