Exemplo n.º 1
0
        private static IEnumerator _LoadScene(AbstractSceneInfo newScene, Action onLeaveOldScene, Action onEnterNewScene)
        {
            //throw new Exception("SceneMgr_LoadScene");
            //开始加载下一个场景
            var async = SceneManager.LoadSceneAsync(newScene.sceneName);

            if (null == async)
            {
                throw new Exception($"Scene【{newScene.sceneName}】还没有build把");
            }

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

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

//            Debug.Log(0);

            onLeaveOldScene?.Invoke();

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

//            Debug.Log(1);
            //允许场景切换
            async.allowSceneActivation = true;

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

//            Debug.Log(2);
            sceneNameBefore  = currentSceneName;
            currentSceneName = newScene.sceneName;

//            Debug.Log(3);
            newScene.OnSceneLoad();

            onEnterNewScene?.Invoke();

            yield return(null);
//            Debug.Log("SceneMgr_LoadScene_end");
        }
Exemplo n.º 2
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;
            }

            sceneNameBefore  = currentSceneName;
            currentSceneName = newScene.sceneName;

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

            newScene.OnSceneLoad();

            onEnterNewScene?.Invoke();
        }