public static async Task SetCriAssetFileInfo(string exportPath, AssetInfoManifest assetInfoManifest) { var assetInfos = Reflection.GetPrivateField <AssetInfoManifest, AssetInfo[]>(assetInfoManifest, "assetInfos"); var tasks = new List <Task>(); for (var i = 0; i < assetInfos.Length; i++) { var assetInfo = assetInfos[i]; if (assetInfo.IsAssetBundle) { continue; } var extension = Path.GetExtension(assetInfo.FileName); if (CriAssetDefinition.AssetAllExtensions.Any(x => x == extension)) { var filePath = PathUtility.Combine(new string[] { exportPath, assetInfo.FileName }); var task = Task.Run(() => { if (!File.Exists(filePath)) { return; } var fileInfo = new FileInfo(filePath); var size = fileInfo.Exists ? fileInfo.Length : -1; var crc = FileUtility.GetCRC(filePath); var hash = FileUtility.GetHash(filePath); assetInfo.SetFileInfo(size, crc, hash); }); tasks.Add(task); } } await Task.WhenAll(tasks); Reflection.SetPrivateField(assetInfoManifest, "assetInfos", assetInfos); UnityEditorUtility.SaveAsset(assetInfoManifest); assetInfoManifest.BuildCache(true); EditorUtility.ClearProgressBar(); }
public static async Task SetAssetBundleFileInfo(string exportPath, AssetInfoManifest assetInfoManifest, BuildResult buildResult) { var assetInfos = Reflection.GetPrivateField <AssetInfoManifest, AssetInfo[]>(assetInfoManifest, "assetInfos"); var assetBundleGroups = assetInfos .Where(x => x.IsAssetBundle) .GroupBy(x => x.AssetBundle.AssetBundleName); var tasks = new Dictionary <string, Task>(); foreach (var assetBundleGroup in assetBundleGroups) { var assetBundleName = assetBundleGroup.Key; if (tasks.ContainsKey(assetBundleName)) { continue; } var assetInfo = assetBundleGroup.First(); var detail = buildResult.GetDetails(assetBundleName); if (!detail.HasValue) { throw new InvalidDataException("AssetBundle build info not found. : " + assetBundleName); } var filePath = PathUtility.Combine(exportPath, assetBundleName); // CRC. assetInfo.AssetBundle.SetCRC(detail.Value.Crc); // Hash. var assetBundleHash = detail.Value.Hash.ToString(); // ファイルハッシュ・ファイルサイズ設定. var packageFilePath = Path.ChangeExtension(filePath, AssetBundleManager.PackageExtension); var task = Task.Run(() => { if (!File.Exists(packageFilePath)) { throw new InvalidDataException("Package file not found. : " + packageFilePath); } var fileInfo = new FileInfo(packageFilePath); var size = fileInfo.Exists ? fileInfo.Length : -1; var crc = FileUtility.GetCRC(packageFilePath); // 同じアセットバンドル名の全アセット情報を更新. foreach (var item in assetBundleGroup) { item.SetFileInfo(size, crc, assetBundleHash); } }); tasks.Add(assetBundleName, task); } await Task.WhenAll(tasks.Values); Reflection.SetPrivateField(assetInfoManifest, "assetInfos", assetInfos); UnityEditorUtility.SaveAsset(assetInfoManifest); assetInfoManifest.BuildCache(true); EditorUtility.ClearProgressBar(); }