// 异步加载场景,把异步封装成了同步+回调 public void LoadSceneAsync(string bundleName, string sceneName, LoadSceneMode mode = LoadSceneMode.Single, OnSceneLoadedAction action = null) { StartCoroutine(Cor_LoadSceneAsync(bundleName, sceneName, mode, action)); }
IEnumerator Cor_LoadSceneAsync(string bundleName, string sceneName, LoadSceneMode mode, OnSceneLoadedAction action) { if (loadingPanel != null) { loadingPanel.ShowProgress("Loading", 0); } yield return(null); #if UNITY_EDITOR // Editor+Develop模式下不加载bundle,直接读场景文件(需要将场景加到BuildSettings,打包时取消勾选) if (EZFrameworkSettings.Instance.runMode != EZFrameworkSettings.RunMode.Develop) #endif yield return(Cor_LoadBundleAsync(bundleName, null)); AsyncOperation opr = SceneManager.LoadSceneAsync(sceneName, mode); while (!opr.isDone) { if (loadingPanel != null) { loadingPanel.ShowProgress("Loading", opr.progress + 0.1f); } yield return(null); } yield return(null); if (loadingPanel != null) { loadingPanel.LoadComplete(); } if (action != null) { action(); } }
IEnumerator Cor_LoadSceneAsync(string bundleName, string sceneName, LoadSceneMode mode, OnSceneLoadedAction action) { if (loadingPanel != null) { loadingPanel.ShowProgress("Loading", 0); } yield return(null); if (!(EZFrameworkSettings.Instance.runMode == EZFrameworkSettings.RunMode.Develop)) { yield return(Cor_LoadBundleAsync(bundleName, null)); } AsyncOperation opr = SceneManager.LoadSceneAsync(sceneName, mode); while (!opr.isDone) { if (loadingPanel != null) { loadingPanel.ShowProgress("Loading", opr.progress + 0.1f); } yield return(null); } yield return(null); if (loadingPanel != null) { loadingPanel.LoadComplete(); } if (action != null) { action(); } }