/// <summary> /// 计算若干个文件合并成的md5码 /// </summary> public string ComputeMd5WithDependencies(string[] assetPaths) { List <byte> list = new List <byte>(); foreach (var p in assetPaths) { byte[] buffer = ReadAssetBytes(p); if (buffer != null) { list.AddRange(buffer); } } // 依赖项 string[] dependencies = AssetDatabase.GetDependencies(assetPaths); byte[] bufferOfD; foreach (var d in dependencies) { bufferOfD = null; bufferOfD = ReadAssetBytes(d); if (bufferOfD != null) { list.AddRange(bufferOfD); } } return(TypeConvertUtility.ByteToMd5(list.ToArray())); }
static void SaveLoadingListFile(List <BaseAssetManager> managerList, string path) { StringBuilder sb = new StringBuilder(); string itemPath, name, md5; int startIndex; byte[] bytes; for (int i = 0, j = 0; i < managerList.Count; i++) { for (j = 0; j < managerList[i].items.Length; j++) { var item = managerList[i].items[j]; if (item.flag == AssetFlag.NoChange) { itemPath = string.Format("{0}/{1}", BuildConfig.buildingAssetBundlesFolder, item.assetBundleName); } else { itemPath = string.Format("{0}/{1}", BuildConfig.tempbuildingAssetBundlesFolder, item.assetBundleName); } startIndex = BuildConfig.buildingAssetBundlesFolder.Length + 1; name = itemPath.Substring(startIndex); bytes = null; bytes = File.ReadAllBytes(itemPath); md5 = TypeConvertUtility.ByteToMd5(bytes); sb.AppendFormat("{0},{1},{2};", name, md5, bytes.Length); } } File.WriteAllText(path, sb.ToString()); }
/// <summary> /// 计算单个资源的md5码 /// </summary> public string ComputeMd5(string assetPath) { byte[] buffer = ReadAssetBytes(assetPath); return(buffer != null?TypeConvertUtility.ByteToMd5(buffer) : null); }