/// <summary> /// 制作 AssetBundles Hash File , /// </summary> /// <param name="package_root_path">packages根目录</param> /// <param name="folder_path">当前直接能索引到assetbundle name的目录</param> /// <param name="assetbundleNames"></param> public void MakeAssetBundleFilesHash(string package_root_path, string folder_path, List <string> assetbundleNames) { List <FilesHashBook.FileHash> Infos = new List <FilesHashBook.FileHash>(); foreach (var ab in assetbundleNames) { var full_path = Path.Combine(folder_path, ab); if (File.Exists(full_path)) { var hashInfo = new FilesHashBook.FileHash(); hashInfo.p = ab; hashInfo.h = XFile.GetMD5(full_path, true); Infos.Add(hashInfo); } } var hashbook = new FilesHashBook(); hashbook.Files = Infos.ToArray(); string save_path = base.GetAssetBundleHashsFilePath(package_root_path); XConfig.SaveJson(hashbook, save_path, AssetLoadType.SystemIO); }
/// <summary> /// 下载补丁包 /// </summary> /// <param name="patchs">补丁包信息们</param> /// <param name="OnFinish">所有补丁包下载完成</param> private void Download_Patchs(StaticUpgradeConfigJsonTpl.PatchInfo[] patchs, Action <E_UpgradeResults> OnFinish) { int index = -1; void Download_one() //处理一个下载,递归 { index++; if (patchs.Length < (index + 1)) { //全部下载完成 //Debug.Log("全部下载并处理完成"); //删掉全部补丁包 foreach (var item in patchs) { var cur_path = Path.Combine(mPatchDownloadTempDir, "patch_" + item.version + ".xpk"); if (File.Exists(cur_path)) { File.Delete(cur_path); } } //Debug.Log("下载流程开始回调"); OnFinish(E_UpgradeResults.success); return; } var patch_path = Path.Combine(mPatchDownloadTempDir, "patch_" + patchs[index].version + ".xpk"); //Debug.Log("处理:" + patch_path); //处理这个patch的下载任务 var flag_exist = false; //看看这个文件会不会已经存在了 if (File.Exists(patch_path)) { //哇还真的存在了 //文件名一样的话,验证一下md5,要是md5一下那就不用再下载了 if (patchs[index].md5.IsNullOrEmpty()) { //服务端没有给MD5信息,就当验证通过了 flag_exist = true; } else { if (XFile.GetMD5(patch_path).ToLower() == patchs[index].md5) { //相等 flag_exist = true; } else { flag_exist = false; } } } if (flag_exist) { Download_one(); } else { //处理当前的下载任务 //Debug.Log(" 准备下载它"); var task = Get_A_File(patchs[index].url, data => { //Debug.Log(" 下载好了"); if (data == null) { //Debug.Log(" 下载结果:失败"); //某个文件下载失败; OnFinish(E_UpgradeResults.connect_lost); return; } else { //下载成功,写出这个文件 //Debug.Log("写出文件"); if (File.Exists(patch_path)) { File.Delete(patch_path); } File.WriteAllBytes(patch_path, data); //验证MD5 if (patchs[index].md5.IsNullOrEmpty()) { //服务端没有给MD5信息,就当验证通过了 } else { if (XFile.GetMD5(patch_path).ToLower() == patchs[index].md5) { //相等,验证通过 } else { //诶呀,md5不一样,是哪儿出问题了呢? OnFinish(E_UpgradeResults.files_check_fail); return; } } //解压 //Debug.Log("解压目录:" + AssetsMgr.I.GetVFSPersistentDataPath()); //if (!Directory.Exists(AssetsMgr.I.GetVFSPersistentDataPath())) //{ // Directory.CreateDirectory(AssetsMgr.I.GetVFSPersistentDataPath()); //} //TinaX.IO.XFile.Unzip(patch_path, AssetsMgr.I.GetVFSPersistentDataPath()); InstallPatchFromLocal(patch_path, true); Download_one(); } }); } } Download_one(); }
public void RefreshAssetBundleSign() { /* * Unity目前提供的API对应的打包方法是: * 1. 给全局的文件加上assetbundle标记 * 2. 整体打包 */ //获取到所有组的文件白名单目录 refreshProfileInfos(); if (EnableTipsGUI) { EditorUtility.DisplayProgressBar("VFS Builder", "Handle AssetBundle signs ...", 0f); } var _whiteLists_folder = VFSManagerEditor.GetAllFolderPaths(); string ab_extension = Config.AssetBundleFileExtension; //没有点开头的后缀名 if (ab_extension.StartsWith(".")) { ab_extension = ab_extension.Substring(1, ab_extension.Length - 1); } ab_extension = ab_extension.ToLower(); List <string> _whiteLists_folder_list_temp = new List <string>(); foreach (var path in _whiteLists_folder) { if (!IsAssetFolderExists(path)) { Debug.LogError("[TinaX][VFS]Folder path in vfs config is not exists: \"" + path + "\""); } else { if (path.EndsWith("/")) { _whiteLists_folder_list_temp.Add(path.Substring(0, path.Length - 1)); } else { _whiteLists_folder_list_temp.Add(path); } } } var _whitelist_folder_temp = _whiteLists_folder_list_temp.ToArray(); string[] guids = AssetDatabase.FindAssets("", _whitelist_folder_temp); string[] asset_paths = VFSManagerEditor.GetAllWithelistAssetsPaths(); List <string> asset_guids = new List <string>(); foreach (var item in asset_paths) { var myguid = AssetDatabase.AssetPathToGUID(item); if (!myguid.IsNullOrEmpty()) { asset_guids.Add(myguid); } } if (asset_guids.Count > 0) { ArrayUtil.Combine(ref guids, asset_guids.ToArray()); } ArrayUtil.RemoveDuplicationElements(ref guids); asset_paths = null; asset_guids = null; asset_hash_book.Clear(); dict_asset_hash_book.Clear(); int counter = 0; int counter_t = 0; int totalLength = guids.Length; foreach (var guid in guids) { string cur_asset_path = AssetDatabase.GUIDToAssetPath(guid); if (VFSManagerEditor.QueryAsset(cur_asset_path, Config, out AssetsStatusQueryResult result, true)) { //查询到了信息,但是并不是所有情况都需要设置assetbundle记录, bool sign_flag = true; if (result.DevType == FolderBuildDevelopType.editor_only) { sign_flag = false; //该资源仅在编辑器下被加载,不参与打包。 } if (result.DevType == FolderBuildDevelopType.develop_mode_only) { if (!mDevelopMode) { sign_flag = false; //资源应该仅在develop模式下使用,但是当前Profile的设置并不是develop } } if (result.ExtensionGroup) { if (curProfile.IsDisabledGroup(result.GroupName)) { sign_flag = false; } } if (sign_flag) { var importer = AssetImporter.GetAtPath(cur_asset_path); if (!XPath.IsFolder(cur_asset_path) && !result.AssetBundleFileNameWithoutExtension.IsNullOrEmpty()) { string assetBundleName_without_extension = result.AssetBundleFileNameWithoutExtension; void InvokePipeline(BuilderPipelineContext ctx) { if (ctx != null && ctx.Handler != null) { bool b = ctx.Handler.BeforeSetAssetBundleSign(ref assetBundleName_without_extension, ref result); if (b && ctx.Next != null) { InvokePipeline(ctx.Next); } } } if (mUsePipeline) { InvokePipeline(mPipeline.First); } //正式设置AssetBundle importer.SetAssetBundleNameAndVariant(assetBundleName_without_extension, ab_extension); //记录Asset原始hash(用于补丁版本检索) if (result.ExtensionGroup) { //记录到字典里 if (!dict_asset_hash_book.ContainsKey(result.GroupName)) { dict_asset_hash_book.Add(result.GroupName, new List <FilesHashBook.FileHash>()); } dict_asset_hash_book[result.GroupName].Add(new FilesHashBook.FileHash() { p = cur_asset_path, h = XFile.GetMD5(cur_asset_path, true) }); } else { asset_hash_book.Add(new FilesHashBook.FileHash() { p = cur_asset_path, h = XFile.GetMD5(cur_asset_path, true) }); } //记录AssetBundle名 string final_ab_name = assetBundleName_without_extension + "." + ab_extension; if (!mDict_Group_AssetBundleNames.ContainsKey(result.GroupName)) { mDict_Group_AssetBundleNames.Add(result.GroupName, new List <string>()); } if (!mDict_Group_AssetBundleNames[result.GroupName].Contains(final_ab_name)) { mDict_Group_AssetBundleNames[result.GroupName].Add(final_ab_name); } } } } if (EnableTipsGUI) { counter++; if (totalLength < 100) { EditorUtility.DisplayProgressBar("VFS Builder", $"Handle AssetBundle signs : {counter} / {totalLength}", counter / totalLength); } else { counter_t++; if (counter_t > 50) { counter_t = 0; EditorUtility.DisplayProgressBar($"VFS Builder", "Handle AssetBundle signs : {counter} / {totalLength}", counter / totalLength); } } } } AssetDatabase.SaveAssets(); if (EnableTipsGUI) { EditorUtility.ClearProgressBar(); } }