예제 #1
0
        /// <summary>
        /// 加载场景,并加载新UI
        /// </summary>
        /// <param name="newSceneName"></param>
        /// <param name="newPanelName"></param>
        public static void LoadScene(string newSceneName, string newPanelName)
        {
            if (currentSceneName == newSceneName)
            {
                return;
            }

            MainLoop.Instance.StartCoroutine(_LoadScene(AbstractSceneInfo.GetScene(newSceneName),
                                                        null,
                                                        () => PanelMgr.PushPanel(newPanelName)));
        }
예제 #2
0
        /// <summary>
        /// 无资源加载场景(伪同步)
        /// </summary>
        /// <param name="newSceneName">新场景名字</param>
        /// <param name="onLeaveOldScene">离开原场景回调</param>
        /// <param name="onEnterNewScene">进入新场景回调</param>
        public static void LoadScene(string newSceneName, Action onLeaveOldScene = null, Action onEnterNewScene = null)
        {
            if (currentSceneName == newSceneName)
            {
                return;
            }

            MainLoop.Instance.StartCoroutine(_LoadScene(AbstractSceneInfo.GetScene(newSceneName),
                                                        onLeaveOldScene,
                                                        onEnterNewScene));
        }
예제 #3
0
        /// <summary>
        /// 异步无资源加载场景
        /// </summary>
        /// <param name="newSceneName">新场景名字</param>
        /// <param name="onLoading">正在加载的回调</param>
        /// <param name="onLeaveOldScene">离开原场景回调</param>
        /// <param name="onEnterNewScene">进入新场景回调</param>
        public static void LoadSceneAsync(string newSceneName, bool stopTime = true, Action <int> onLoading = null, Action onLeaveOldScene = null, Action onEnterNewScene = null)
        {
            if (currentSceneName == newSceneName)
            {
                return;
            }

            MainLoop.Instance.StartCoroutine(_LoadSceneAsync(AbstractSceneInfo.GetScene(newSceneName),
                                                             stopTime,
                                                             onLoading,
                                                             onLeaveOldScene,
                                                             onEnterNewScene));
        }
예제 #4
0
        private static IEnumerator _LoadScene(AbstractSceneInfo newScene, Action onLeaveOldScene, Action onEnterNewScene)
        {
            //throw new Exception("SceneMgr_LoadScene");
            //开始加载下一个场景
            var async = SceneManager.LoadSceneAsync(newScene.sceneName);

            //暂时不进入下一个产经
            async.allowSceneActivation = false;

            while (async.progress < 0.9f)
            {
                yield return(new WaitForFixedUpdate());
            }

            onLeaveOldScene?.Invoke();

            if (!string.IsNullOrEmpty(currentSceneName))
            {
                AbstractSceneInfo.GetScene(currentSceneName).OnSceneUnLoaded();
            }

            //允许场景切换
            async.allowSceneActivation = true;

            //等待场景真正加载完毕
            while (!async.isDone)
            {
                yield return(new WaitForFixedUpdate());
            }

            currentSceneName = newScene.sceneName;

            newScene.OnSceneLoad();

            onEnterNewScene?.Invoke();
        }
예제 #5
0
 /// <summary>
 /// 打开已经开启的场景
 /// </summary>
 public static void LoadActiveScene()
 {
     currentSceneName = SceneManager.GetActiveScene().name;
     AbstractSceneInfo.GetScene(currentSceneName).OnSceneLoad();
 }
예제 #6
0
        private static IEnumerator _LoadSceneAsync(AbstractSceneInfo newScene, bool stopTime, Action <int> onLoading, Action onLeaveOldScene, Action onEnterNewScene)
        {
            if (stopTime)
            {
                Time.timeScale = 0;
            }

            //显示用的进度
            int displayPro = 0;

            //实际的进度
            int realPro = 0;

            //开始加载下一个场景
            var async = SceneManager.LoadSceneAsync(newScene.sceneName);

            //暂时不进入下一个产经
            async.allowSceneActivation = false;



            //在加载不足90%时,进度条缓慢增长动画
            while (async.progress < 0.9f)
            {
                realPro = (int)(async.progress * 100.0f);

                //如果显示进度尚未达到实际进度,每帧增加1%
                while (displayPro < realPro)
                {
                    displayPro++;

                    onLoading?.Invoke(displayPro);

                    yield return(new WaitForEndOfFrame());
                }
            }

            //加载最后一段
            realPro = 100;
            while (displayPro < realPro)
            {
                displayPro++;

                onLoading?.Invoke(displayPro);

                yield return(new WaitForEndOfFrame());
            }


            onLeaveOldScene?.Invoke();

            if (!string.IsNullOrEmpty(currentSceneName))
            {
                AbstractSceneInfo.GetScene(currentSceneName).OnSceneUnLoaded();
            }


            //允许场景切换
            async.allowSceneActivation = true;

            //等待场景真正加载完毕
            while (!async.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (stopTime)
            {
                Time.timeScale = 1;
            }

            currentSceneName = newScene.sceneName;

            //throw new Exception("!!!!!");

            newScene.OnSceneLoad();

            onEnterNewScene?.Invoke();
        }