private static void GenerateCSVFile(List <AssetInfoItem> assetInfoItemList) { StringBuilder csvFileStr = new StringBuilder(); csvFileStr.Append("id,bundleName,versionCode,crc,hashCode\r"); for (int i = 0; i < assetInfoItemList.Count; ++i) { AssetInfoItem info = assetInfoItemList[i]; csvFileStr.Append((i + 1).ToString()); csvFileStr.Append(","); csvFileStr.Append(info.bunndleName); csvFileStr.Append(","); csvFileStr.Append(info.versionCode.ToString()); csvFileStr.Append(","); csvFileStr.Append(info.crc); csvFileStr.Append(","); csvFileStr.Append(info.hashCode); if (i < assetInfoItemList.Count - 1) { csvFileStr.Append('\r'); } } FileStream assetFile = File.Open(GetOutPutPath() + "/" + csvFileName, FileMode.Create); Encoding utf8WithoutBom = new UTF8Encoding(false); StreamWriter sw = new StreamWriter(assetFile, utf8WithoutBom); sw.Write(csvFileStr); sw.Close(); assetFile.Close(); if (File.Exists(Application.dataPath.Replace("Assets", "") + "AssetBundles/" + csvFileName)) { File.Delete(Application.dataPath.Replace("Assets", "") + "AssetBundles/" + csvFileName); } File.Copy(GetOutPutPath() + "/" + csvFileName, Application.dataPath.Replace("Assets", "") + "AssetBundles/" + csvFileName); }
/// <summary> /// Generates the file info table. /// </summary> private static void GenerateFileInfoTable() { EditorResourcesInfoData.Instance.Init(); List <AssetInfoItem> assetInfoItemList = new List <AssetInfoItem>(); AssetDatabase.RemoveUnusedAssetBundleNames(); //普通bundle 的信息 bool isChange = false; String[] names = AssetDatabase.GetAllAssetBundleNames(); for (int i = 0; i < names.Length; ++i) { AssetInfoItem assetInfoItem = new AssetInfoItem(); string bundlename = names[i]; assetInfoItem.bunndleName = bundlename; ManifestInfo info = GetManifestInfo(bundlename); assetInfoItem.crc = info.crc; assetInfoItem.hashCode = info.hashCode; string oldHashCode = EditorResourcesInfoData.Instance.GetHashCode(bundlename); if (oldHashCode != info.hashCode) //upgrade versioncode { assetInfoItem.versionCode = EditorResourcesInfoData.Instance.GetNextVersionCode(bundlename); isChange = true; } else //not change ,keep versioncode { assetInfoItem.versionCode = EditorResourcesInfoData.Instance.GetVersionCode(bundlename); } assetInfoItemList.Add(assetInfoItem); } //总包的信息 AssetInfoItem totalInfoItem = new AssetInfoItem(); totalInfoItem.bunndleName = GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget); ManifestInfo totalInfo = GetManifestInfo(totalInfoItem.bunndleName); totalInfoItem.crc = totalInfo.crc; totalInfoItem.hashCode = ""; if (isChange) { totalInfoItem.versionCode = EditorResourcesInfoData.Instance.GetNextVersionCode(totalInfoItem.bunndleName); } else { totalInfoItem.versionCode = EditorResourcesInfoData.Instance.GetVersionCode(totalInfoItem.bunndleName); } assetInfoItemList.Insert(0, totalInfoItem); GenerateCSVFile(assetInfoItemList); GenerateVerInfo(isChange); }