IEnumerator LoadPatch() { string platfrom = GetPlatformName(); if (string.IsNullOrEmpty(platfrom)) { platfrom = Application.platform.ToString(); } step = Step.Check; string fullURL = gameURL + "patch/index2.php?" + HTTPQueryStr; // He platform=" + platfrom + "&v=" + Application.version + "&t=" + versionTag; Debug.LogFormat(fullURL); WWW www = new WWW(fullURL); yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); message.text = "加载补丁列表失败"; if (reloadButton != null && (versionTag == "test" || versionTag == "dev")) { reloadButton.SetActive(true); } yield break; } #if UNITY_EDITOR if (!AssetManager.SimulateMode) #endif { ResourceBundle.Clear(); AssetManager.Clear(); } LoadingInfo info = JsonUtility.FromJson <LoadingInfo>(www.text); Debug.Log(www.text); if (!string.IsNullOrEmpty(info.bundleURL)) { bundleURL = info.bundleURL; } server_list = info.server_list; serverTag = info.tag; if (string.IsNullOrEmpty(info.asset_version)) { info.asset_version = AssetVersion.Version; } versionString = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version); versionText.text = versionString; Debug.Log("version:" + versionString); Dictionary <string, string> localbundles = new Dictionary <string, string>(); do { #if UNITY_EDITOR if (AssetManager.SimulateMode) { break; } #endif if (AssetVersion.Version == info.asset_version) { break; } List <PatchInfo> lpds = GetLocalBundles(info, ref localbundles); total_count = lpds.Count; loaded_count = 0; int patchDownLoadTotalSize = 0; for (int i = 0; i < total_count; ++i) { patchDownLoadTotalSize += lpds[i].size; } OSTools.AlertDialog("提示", string.Format("您将下载 {0} MB 的资源", patchDownLoadTotalSize / 1024 / 1024), "确认", () => { patchDownLoadTotalSize = 0; }, "取消", () => { Application.Quit(); }); while (patchDownLoadTotalSize > 0) { yield return(null); } for (int i = 0; i < total_count; ++i) { var patch = lpds[i]; string url = patch.file; if (!url.StartsWith("http://")) { url = info.patchURL + "/" + url; } step = Step.Down; // current_file = patch.file; Debug.LogFormat("down patch {0}", url); loading_www = new WWW(url); yield return(loading_www); if (loading_www.error != null && !loading_www.error.Equals("")) { message.text = "下载补丁文件失败"; yield break; } if (loading_www.bytesDownloaded != patch.size) { Debug.LogError("down load patch error, patch file:" + patch.file); break; } step = Step.Unzip; message.text = "解压文件..."; process = 1; yield return(new WaitForSeconds(0.1f)); List <string> files = new List <string>(); unzipFile(loading_www.bytes, Application.persistentDataPath + "/" + patch.version, (string name) => { files.Add(name); }); step = Step.Install; message.text = "安装补丁..."; process = 0; yield return(new WaitForSeconds(0.1f)); bool flag = false; AssetVersion.StartAddBundle(patch.version); int c = 0; foreach (var p in files) { if (!MergePatch(p, patch, ref localbundles)) { flag = true; break; } AssetVersion.AddBundle(p.Replace(".patch", "")); message.text = string.Format("正在安装补丁:{0}/{1}", ++c, files.Count); process = c / (float)files.Count; yield return(null); } AssetVersion.EndAddBundle(); message.text = "安装补丁结束"; process = 1; yield return(null); if (flag) { AssetVersion.ClearBundle(patch.version); break; } AssetVersion.Version = patch.version; AssetVersion.Flush(); loaded_count += 1; } if (loaded_count != total_count) { break; } versionText.text = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version); loading_www = null; Caching.ClearCache(); } while (false); if (loaded_count != total_count || total_count == 0) { localbundles.Clear(); GetLocalBundles(info, ref localbundles); } foreach (var iter in localbundles) { var v = iter.Value; string bundlename = iter.Key; string abrepath = v + "/" + bundlename; string fullpath = Application.persistentDataPath + "/" + abrepath; if (Path.GetFileName(abrepath).StartsWith("hotfix")) { ResourceBundle.Replace(bundlename, fullpath); } else { if (PatchFiles.ContainsKey(bundlename)) { PatchFiles[bundlename] = v; } else { PatchFiles.Add(bundlename, v); } } } SetVersionList(info); Statistics.GetCache(this); AssetManager.Init(); message.text = total_count != 0 && loaded_count != total_count ? "补丁更新失败,正在使用本地版本进入游戏" : "加载游戏中..."; step = Step.Enter; process = 0; versionString = string.Format("{0}:{1}:{2}", Application.version, AssetVersion.Version, info.asset_version); yield return(new WaitForSeconds(0.22f)); patch_is_ready = true; StartCoroutine(BundleManager.DownAndLoadThread()); StartCoroutine(AssetManager.CheckMemoryThread()); }