public static SetProgressbarTips ( string rText ) : void | ||
rText | string | |
리턴 | void |
IEnumerator LoadSceneInternal() { displayProgress = 5; LoadingLayer.SetProgressbarTips("Scene Initialize ..."); LoadingLayer.SetProgressbarValue(displayProgress); async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(loadSceneName); //Application.LoadLevelAsync(loadSceneName); IsLoading = true; async.allowSceneActivation = false; while (async.progress < 0.9f) { progress = (int)async.progress * 100; while (displayProgress < progress) { ++displayProgress; LoadingLayer.SetProgressbarValue(displayProgress); yield return(new WaitForEndOfFrame()); } yield return(new WaitForEndOfFrame()); } progress = 90; while (displayProgress < progress) { ++displayProgress; LoadingLayer.SetProgressbarValue(displayProgress); yield return(new WaitForEndOfFrame()); } async.allowSceneActivation = true; InitializeScene(); IsLoading = false; }
static void AssetsUpdateEnd() { if (OnAssetsUpdateComplete != null) { OnAssetsUpdateComplete.Invoke(); OnAssetsUpdateComplete = null; } LoadingLayer.SetProgressbarTips("资源解包完成,准备初始化"); }
void ResourceUpdateEnd() { if (OnResourceUpdateComplete != null) { OnResourceUpdateComplete.Invoke(); OnResourceUpdateComplete = null; } LoadingLayer.SetProgressbarTips("资源解包完成,准备初始化"); }
void LoadAssetbundleManifest() { LoadingLayer.SetProgressbarTips("游戏初始化中"); LoadingLayer.SetProgressbarValue(5); string bundlName = AppPlatform.GetAssetBundleDirName(); Global.AssetLoadManager.DownloadingURL = AppPlatform.GetRuntimeAssetBundleUrl(); Global.AssetLoadManager.LoadManifest(bundlName, () => { onStartupFunc(); }); }
IEnumerator LoadSceneBundle() { LoadingLayer.SetProgressbarTips("Loading Scene..."); LoadingLayer.SetProgressbarValue(1); var rUrl = AppPlatform.GetRuntimeSceneBundleUrl() + loadSceneName.ToLower() + "." + Global.BundleExtName; Debug.Log("[DownloadSceneBundle]:>" + rUrl); var download = new WWW(rUrl); yield return(download); if (download.error != null) { Debug.LogError(download.error); yield break; } sceneBundle = download.assetBundle; StartCoroutine(LoadSceneInternal()); }
static IEnumerator OnUnpackAssets() { LoadingLayer.SetProgressbarTips("开始解包资源"); //解包config server string infile = Application.streamingAssetsPath + "/" + "server.ini"; string outfile = AppPlatform.RuntimeAssetsPath + "server.ini"; if (infile != outfile) { if (File.Exists(outfile)) { File.Delete(outfile); } if (AppPlatform.PlatformCurrent == Platform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(null); } else { File.Copy(infile, outfile, true); } DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile); yield return(new WaitForEndOfFrame()); } //解包config user if (infile != outfile) { infile = Application.streamingAssetsPath + "/" + "user.ini"; outfile = AppPlatform.RuntimeAssetsPath + "user.ini"; if (File.Exists(outfile)) { File.Delete(outfile); } if (AppPlatform.PlatformCurrent == Platform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(null); } else { File.Copy(infile, outfile, true); } DebugConsole.Log("[extracting config]:>" + infile + "[TO]" + outfile); yield return(new WaitForEndOfFrame()); } //检查是否有预装package需要解包 bool needExtractPackage = true; if (AppPlatform.PlatformCurrent == Platform.Android) { var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName; WWW www = new WWW(ver); yield return(www); if (www.error != null) { DebugConsole.Log("没有预装的Package"); www.Dispose(); needExtractPackage = false; } } else { var ver = AppPlatform.GetPackagePath() + Global.PackageVersionFileName; if (!File.Exists(ver)) { DebugConsole.Log("没有预装的Package"); needExtractPackage = false; } } if (needExtractPackage) { //清理package文件夹 if (Directory.Exists(AppPlatform.GetRuntimePackagePath())) { Directory.Delete(AppPlatform.GetRuntimePackagePath(), true); } Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath()); //解包package的checklist infile = AppPlatform.GetPackagePath() + Global.PackageManifestFileName; outfile = AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName; if (File.Exists(outfile)) { File.Delete(outfile); } if (AppPlatform.PlatformCurrent == Platform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(null); } else { File.Copy(infile, outfile, true); } DebugConsole.Log("[extracting checklist]:>" + infile + "[TO]" + outfile); yield return(new WaitForEndOfFrame()); //解包package string[] files = File.ReadAllLines(outfile); float downloadedCount = 0f; for (int i = 0; i < files.Length; i++) { var file = files[i]; string[] rKeyValue = file.Split('|'); infile = AppPlatform.GetPackagePath() + rKeyValue[0]; outfile = AppPlatform.GetRuntimePackagePath() + rKeyValue[0]; DebugConsole.Log("[extracting package]:>" + infile + "[TO]" + outfile); string rDirName = Path.GetDirectoryName(outfile); if (!Directory.Exists(rDirName)) { Directory.CreateDirectory(rDirName); } if (AppPlatform.PlatformCurrent == Platform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(0); } else { if (File.Exists(outfile)) { File.Delete(outfile); } File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); downloadedCount++; float p = (downloadedCount / (float)files.Length) * 100f; p = Mathf.Clamp(p, 0, 100); LoadingLayer.SetProgressbarValue((int)p); } } LoadingLayer.SetProgressbarTips("解包资源文件完成"); yield return(new WaitForSeconds(0.1f)); Global.TaskManager.StartTask(OnUpdatePackage()); }
static IEnumerator OnUpdatePackage() { if (!Global.IsUpdateMode) { AssetsUpdateEnd(); yield break; } LoadingLayer.SetProgressbarTips("开始更新资源"); //比对服务器版本 WWW www = new WWW(Global.ServerPackageVersionURL); yield return(www); if (www.error != null) { DebugConsole.Log("未在服务器上找到最新版本文件"); www.Dispose(); yield break; } var lastestVer = www.text; var curVer = ""; if (File.Exists(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName)) { curVer = FileUtil.ReadFile(AppPlatform.GetRuntimePackagePath() + Global.PackageVersionFileName); } if (curVer == lastestVer) { DebugConsole.Log("当前package已是最新版本,无需更新"); www.Dispose(); yield break; } // 获取更新文件列表 string listUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + Global.PackageManifestFileName; www = new WWW(listUrl); yield return(www); if (www.error != null) { DebugConsole.Log("未在服务器上找到checklist"); www.Dispose(); yield break; } if (!Directory.Exists(AppPlatform.GetRuntimePackagePath())) { Directory.CreateDirectory(AppPlatform.GetRuntimePackagePath()); } File.WriteAllBytes(AppPlatform.GetRuntimePackagePath() + Global.PackageManifestFileName, www.bytes); //按照更新列表增量更新文件 string fileslist = www.text; string[] files = fileslist.Split('\n'); float downloadedCount = 0f; for (int i = 0; i < files.Length; i++) { if (string.IsNullOrEmpty(files[i])) { continue; } string[] keyValue = files[i].Split('|'); string fileName = keyValue[0]; string localfilePath = (AppPlatform.GetRuntimePackagePath() + fileName).Trim(); string path = Path.GetDirectoryName(localfilePath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } //检查是否可以更新这个文件 bool canUpdate = !File.Exists(localfilePath); if (!canUpdate) { string remoteMd5 = keyValue[1].Trim(); string localMd5 = Util.MD5File(localfilePath); canUpdate = !remoteMd5.Equals(localMd5); if (canUpdate) { File.Delete(localfilePath); } } //可以更新这个文件 if (canUpdate) { string fileUrl = Global.PackageUpdateURL + lastestVer + "/" + AppPlatform.GetPackageName() + "/" + fileName; Debug.Log(fileUrl); www = new WWW(fileUrl); yield return(www); if (www.error != null) { Debug.Log(www.error + path); yield break; } File.WriteAllBytes(localfilePath, www.bytes); downloadedCount++; float p = (downloadedCount / (float)files.Length) * 100f; p = Mathf.Clamp(p, 0, 100); LoadingLayer.SetProgressbarValue((int)p); } } www.Dispose(); LoadingLayer.SetProgressbarTips("更新资源完成"); yield return(new WaitForEndOfFrame()); AssetsUpdateEnd(); }