ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

生成AB包清单

生成AB包清单 我们使用AssetDatabase.GetAllAssetBundleNames();获得项目所有AB包名。我们不在导出文件夹遍历所有文件因为如果之前打包的资源现在不打包了打包又没有勾选清空文件夹还是会生成已经不用的包信息。通过AssetDatabase.GetAllAssetBundleNames();获得所有报名需要额外生成主包的信息。public static void MakeABCheckList(string fileName, string folder) { folder folder.Replace(\\, /); if (!Directory.Exists(folder)) { Debug.LogError($没有创建{folder}文件夹); return; } DirectoryInfo directoryInfo new DirectoryInfo(folder); ABCheckList abList new(); string mainAB Path.GetFileName(folder); ABInfo info new ABInfo(); info.name mainAB; string fullPath ${folder}/{mainAB}; ; var file new FileInfo(fullPath); info.byteNum (uint)file.Length; info.MD5 MyTools.GetMD5(fullPath); abList.ABInfos[mainAB] info; var arr AssetDatabase.GetAllAssetBundleNames(); foreach (var ab in arr) { fullPath ${folder}/{ab}; string name Path.GetFileName(ab); abList.ABInfos.Add(name, new()); info abList.ABInfos[name]; info.name ab; file new FileInfo(fullPath); info.byteNum (uint)file.Length; info.MD5 MyTools.GetMD5(fullPath); } string json JsonConvert.SerializeObject(abList, Formatting.Indented); File.WriteAllText(Path.Combine(folder, fileName), json); Debug.Log(AB清单文件生成完成); AssetDatabase.Refresh(); }public static string GetMD5(string path) { using (FileStream file new FileStream(path, FileMode.Open)) { MD5 md5 new MD5CryptoServiceProvider(); byte[] bytes md5.ComputeHash(file); file.Close(); StringBuilder builder new(); for (int i 0; i bytes.Length; i) { //将一个数字转换为小写的十六进制字符串并且确保输出至少为两位数不足时在前面补 0 builder.Append(bytes[i].ToString(x2)); } return builder.ToString(); } }
返回列表