Example #1
0
    // 异步载入场景
    private static IEnumerator NonsyncLoad(string sceneName, ILoading loading)
    {
        App.log.Trace("SceneM.cs", "开始异步载入场景{0}", sceneName);



        // 取得载入器
        IScene scene = sceneLoadControl[sceneName];

        s_preScene      = s_CurIScene;
        s_loadingIScene = scene;

        // 1 播放开始载入的动画,并等待其播放完毕
        if (loading != null)
        {
            App.log.Trace("SceneM.cs", "播放载入开始动画");
            loading.FadeIn();
            while (loading.IsFadingIn())
            {
                yield return(null);
            }
        }

        // 欲载入的处理
        scene.PrepareLoad();


        // 2 产生事件并清理旧的场景
        if (eventUnload != null)
        {
            eventUnload(s_preScene);
        }
        if (s_preScene != null)
        {
            s_preScene.Clear();
        }



        // 3 载入新的场景
        scene.Load();

        if (sceneLoadingAnim.ContainsKey(sceneName))
        {
            sceneLoadingAnim[sceneName].SetAsyncLoading(scene.AsyncLoading);
        }

        if (sceneLoadControl.ContainsKey(CombatScene.GetSceneName()))
        {
            IScene sceneCombat = sceneLoadControl[CombatScene.GetSceneName()];
            // 清理内存资源
            if (scene != sceneCombat && s_preScene != sceneCombat)
            {
                Resources.UnloadUnusedAssets();
                System.GC.Collect();
            }
        }

        // 1 播放开始载入的动画,并等待其播放完毕
        if (loading != null)
        {
            App.log.Trace("SceneM.cs", "播放载入开始动画");
            loading.Load();
            while (loading.IsLoading())
            {
                yield return(null);
            }
        }
        yield return(new WaitForMSeconds(100f));


        // 等待载入完成
        while (!scene.IsEnd())
        {
            yield return(null);
        }

        // 场景载入完成(一定要在load完毕后才能替换,此时的环境才能称得上载入完成)
        s_CurIScene = scene;


        bLoading = false;

        // 6 发出载入完毕的事件
        if (eventLoaded != null)
        {
            eventLoaded(scene);
        }
        //载入完成。
        scene.BuildScene();
        scene.Start();

        // 4 播放载入完成的动画,并等待其播放完毕
        if (loading != null)
        {
            App.log.Trace("SceneM.cs", "播放载入完成动画");
            loading.FadeOut();
            while (loading.IsFadingOut())
            {
                yield return(null);
            }

            loading.TryDestroy();
        }

        // 载入完成
        App.log.Trace("SceneM.cs", "异步载入场景{0}完成", sceneName);
    }
Example #2
0
    // 异步载入场景
    private static IEnumerator NonsyncLoad(string sceneName, SceneData data)
    {
        // 取得载入器
        IScene scene = sceneLoadControl[sceneName];

        s_preScene      = s_CurIScene;
        s_loadingIScene = scene;


        if (s_preScene != null)
        {
            s_preScene.Clear();
        }
        // 1 播放开始载入的动画,并等待其播放完毕
        ILoading loading = null;

        WndManager.CreateWnd <LoadingWnd>(WndType.NormalWnd, false, false, (wnd) => {
            loading = (wnd as LoadingWnd);
            loading.Load();
        });
        yield return(Yielders.GetWaitForSeconds(0.5f));

        // 欲载入的处理
        scene.PrepareLoad();
        // 3 载入新的场景
        scene.Load(data);

        // 等待loading入场动作,设定2秒钟哦。正常是不会这样处理的。
        float waitTime      = 0;
        float totalWaitTime = 1.5f;

        int            displayProgress = 0;
        int            toProgress      = 0;
        AsyncOperation op = scene.AsyncLoading;

        if (scene.AsyncLoading != null)
        {
            // 等待载入完成
            while (!scene.IsEnd())
            {
                toProgress = (int)(op.progress * 100);
                while (displayProgress < toProgress)
                {
                    waitTime += Time.deltaTime;
                    ++displayProgress;
                    if (loading != null)
                    {
                        loading.Play(displayProgress);
                    }
                    yield return(g_wait);
                }
            }
            toProgress = 100;
            while (displayProgress < toProgress)
            {
                waitTime += Time.deltaTime;
                ++displayProgress;
                if (loading != null)
                {
                    loading.Play(displayProgress);
                }
                yield return(g_wait);
            }
        }
        // 场景载入完成(一定要在load完毕后才能替换,此时的环境才能称得上载入完成)
        s_CurIScene = scene;
        //
        scene.Awake();
        //
        while (waitTime < totalWaitTime)
        {
            waitTime += Time.deltaTime;
            yield return(g_wait);
        }

        if (loading != null)
        {
            loading.TryDestroy();
        }

        bLoading = false;

        yield return(Yielders.GetWaitForSeconds(0.5f));

        //载入完成。
        scene.BuildScene();
        scene.Start();
        // 载入完成
    }
Example #3
0
    // 异步载入场景
    private static IEnumerator NonsyncLoad(string sceneName, ILoading loading)
    {
        // 取得载入器
        IScene scene = sceneLoadControl[sceneName];

        s_preScene      = s_CurIScene;
        s_loadingIScene = scene;


        // 欲载入的处理
        scene.PrepareLoad();

        if (s_preScene != null)
        {
            s_preScene.Clear();
        }



        // 3 载入新的场景
        scene.Load();

        /*if (sceneLoadingAnim.ContainsKey(sceneName))
         * {
         *      sceneLoadingAnim[sceneName].SetAsyncLoading(scene.AsyncLoading);
         * }*/

        // 1 播放开始载入的动画,并等待其播放完毕
        if (loading != null)
        {
            loading.Load();
            while (loading.IsLoading())
            {
                yield return(null);
            }
        }
        yield return(new ND.WaitForMSeconds(100f));


        // 等待载入完成
        while (!scene.IsEnd())
        {
            yield return(null);
        }
        // 场景载入完成(一定要在load完毕后才能替换,此时的环境才能称得上载入完成)
        s_CurIScene = scene;


        bLoading = false;

        //载入完成。
        scene.BuildScene();
        scene.Start();

        // 4 播放载入完成的动画,并等待其播放完毕
        if (loading != null)
        {
            loading.FadeOut();
            while (loading.IsFadingOut())
            {
                yield return(null);
            }

            loading.TryDestroy();
        }

        // 载入完成
    }