/// <summary> /// 使用在Constants中配置的路径 /// </summary> /// <param name="mono"></param> /// <param name="gameModuleList"></param> /// <param name="isUpdate"></param> /// <param name="onProcess"></param> /// <param name="onComplete"></param> public static void UpdateGameModules(this MonoBehaviour mono, List <string> gameModuleList, bool isUpdate, System.Action <string, long, long> onProcess, System.Action <string, JSONObject> onComplete) { string src = isUpdate ? Constants.UpdateUrl : Constants.StreamingAssetsDataPath; string des = Constants.DataPath; if (isUpdate) {//热更新 阿里云 上的资源的情况 int localVersionCode = GetLocalVersionControlCode(); src = InsertUpdateUrlWithVersionCode(src, localVersionCode + ""); mono.UpdateGameModules(src, des, gameModuleList, isUpdate, onProcess, (error, config) => {//进行点击下载的时候,如果出现下载错误, 就重新下载 if (error != null) { Debug.LogError("下载出错了 : " + error); mono.Delay(15f, () => mono.UpdateGameModules(gameModuleList, isUpdate, onProcess, onComplete));//如果下载出错了 没有下载完,那么重新下载 } else { if (onComplete != null) { onComplete(error, config); } } }); } else {//解压的情况 mono.UpdateGameModules(src, des, gameModuleList, isUpdate, onProcess, onComplete); } }
public static void DownloadCloudAssets(this MonoBehaviour mono, System.Action <string, long, long> onProcess, System.Action <string, bool> onComplete) { string src = Constants.UpdateUrl;//调用热更新地址是会自动切换地址 string des = Constants.DownloadPath; GetVersionUpdateControl((versionCode) => { #if UNITY_EDITOR if (SimpleFramework.Manager.GameManager._VersionControl_ali > 0) { versionCode = SimpleFramework.Manager.GameManager._VersionControl_ali; } #endif if (versionCode <= 0) {//versionCode > 0 才是有效的 Debug.LogError("下载出错了 : 阿里云上的版本号为 0"); mono.Delay(30f, () => mono.DownloadCloudAssets(onProcess, onComplete));//如果下载出错了 没有下载完,那么重新下载 } else { //JSONObject localConfig = GetLocalConfigJson(Constants.DataPath); //int localVersionCode = System.Convert.ToInt32(localConfig[Constants.InstantUpdate_VersionCode]); //if (localVersionCode == versionCode) //{//版本号相同, 不用热更新 // onComplete(null, false); // return; //} //localConfig.RemoveField(Constants.InstantUpdate_VersionTime); //localConfig.RemoveField(Constants.InstantUpdate_VersionCode); //List<string> localGameModuleList = localConfig.keys; List <string> localGameModuleList = GetLocalModuleList(); src = InsertUpdateUrlWithVersionCode(src, versionCode + "");//插入 热更新版本号 if (!File.Exists(des + Constants.Config_File)) { Copy(Constants.DataPath + Constants.Config_File, des); } mono.UpdateGameModules(src, des, localGameModuleList, true, onProcess, (error, config) => { if (error != null) { Debug.LogError("下载出错了 : " + error); mono.Delay(30f, () => mono.DownloadCloudAssets(onProcess, onComplete));//如果下载出错了 没有下载完,那么重新下载 } else { //if (config.IsAvailable()) //有需要更新的资源 // mono.StartCoroutine(mono.DoCheckDownloadComplete(src,des,onProcess, onComplete)); //else //没有需要更新的资源 // if (onComplete != null) onComplete(null,false);//无资源更新,第二个参数为false if (onComplete != null) { onComplete(null, config.IsAvailable()); } } }); } }); }