// 异步载入场景 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(); // 载入完成 }