public static FileEntry GenFileEntry(string entryName, string filePath) { using (var stream = File.OpenRead(filePath)) { var checksum = new Utils.Crc16(); checksum.Update(stream); return(new FileEntry() { name = entryName, checksum = checksum.hex, size = (int)stream.Position, }); } }
// 生成清单 public static void BuildManifest(BundleBuilderData data, string outputPath, AssetBundleManifest assetBundleManifest, ZipArchiveManifest zipArchiveManifest) { var manifest = new Manifest(); if (assetBundleManifest != null) { var assetBundles = assetBundleManifest.GetAllAssetBundles(); foreach (var assetBundle in assetBundles) { BundleBuilderData.BundleInfo bundleInfo; BundleBuilderData.BundleSplit bundleSplit; if (TryGetBundleSplit(data, assetBundle, out bundleInfo, out bundleSplit)) { // Debug.Log(bundleInfo.name); var assetBundlePath = Path.Combine(outputPath, assetBundle); using (var stream = File.OpenRead(assetBundlePath)) { var fileInfo = new FileInfo(assetBundlePath); var checksum = new Utils.Crc16(); checksum.Update(stream); var bundle = new Manifest.BundleInfo(); bundle.type = Manifest.BundleType.AssetBundle; bundle.name = bundleSplit.name; bundle.checksum = checksum.hex; bundle.size = (int)fileInfo.Length; bundle.startup = bundleInfo.load == BundleLoad.Startup; bundle.priority = bundleInfo.priority; foreach (var asset in bundleSplit.assets) { var assetPath = AssetDatabase.GetAssetPath(asset); bundle.assets.Add(assetPath); } bundle.dependencies = assetBundleManifest.GetAllDependencies(assetBundle); manifest.bundles.Add(bundle); } } } } if (zipArchiveManifest != null) { foreach (var zipArchive in zipArchiveManifest.archives) { var bundleInfo = GetBundleInfo(data, zipArchive.name); var zipArchivePath = Path.Combine(outputPath, zipArchive.name); using (var stream = File.OpenRead(zipArchivePath)) { var fileInfo = new FileInfo(zipArchivePath); var checksum = new Utils.Crc16(); checksum.Update(stream); var bundle = new Manifest.BundleInfo(); bundle.type = Manifest.BundleType.ZipArchive; bundle.name = zipArchive.name; bundle.checksum = checksum.hex; bundle.size = (int)fileInfo.Length; bundle.startup = bundleInfo.load == BundleLoad.Startup; bundle.priority = bundleInfo.priority; foreach (var assetPath in zipArchive.assets) { // var assetPath = AssetDatabase.GetAssetPath(asset.target); bundle.assets.Add(assetPath); } // bundle.dependencies = null; manifest.bundles.Add(bundle); } } } if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } var json = JsonUtility.ToJson(manifest); var jsonChecksum = Utils.Crc16.ToString(Utils.Crc16.ComputeChecksum(System.Text.Encoding.UTF8.GetBytes(json))); var manifestPath = Path.Combine(outputPath, "manifest.json"); var manifestChecksumPath = Path.Combine(outputPath, "checksum.txt"); File.WriteAllText(manifestPath, json); File.WriteAllText(manifestChecksumPath, jsonChecksum); }
// 生成清单 public static void BuildManifest(BundleBuilderData data, string outputPath, AssetBundleManifest assetBundleManifest, ZipArchiveManifest zipArchiveManifest, out EmbeddedManifest embeddedManifest) { var manifest = new Manifest(); embeddedManifest = new EmbeddedManifest(); if (assetBundleManifest != null) { var assetBundles = assetBundleManifest.GetAllAssetBundles(); foreach (var assetBundle in assetBundles) { BundleBuilderData.BundleInfo bundleInfo; BundleBuilderData.BundleSplit bundleSplit; if (TryGetBundleSplit(data, assetBundle, out bundleInfo, out bundleSplit)) { // Debug.Log(bundleInfo.name); var assetBundlePath = Path.Combine(outputPath, assetBundle); using (var stream = File.OpenRead(assetBundlePath)) { var fileInfo = new FileInfo(assetBundlePath); var checksum = new Utils.Crc16(); checksum.Update(stream); var bundle = new Manifest.BundleInfo(); bundle.type = Manifest.BundleType.AssetBundle; bundle.name = bundleSplit.name; bundle.checksum = checksum.hex; bundle.size = (int)fileInfo.Length; bundle.load = bundleInfo.load; bundle.priority = bundleInfo.priority; foreach (var asset in bundleSplit.assets) { var assetPath = AssetDatabase.GetAssetPath(asset); bundle.assets.Add(assetPath); } bundle.dependencies = assetBundleManifest.GetAllDependencies(assetBundle); manifest.bundles.Add(bundle); if (bundleInfo.streamingAssets) { embeddedManifest.bundles.Add(new EmbeddedManifest.BundleInfo() { name = bundle.name, checksum = bundle.checksum, size = bundle.size, }); } } } } } if (zipArchiveManifest != null) { foreach (var zipArchive in zipArchiveManifest.archives) { var bundleInfo = GetBundleInfo(data, zipArchive.name); var zipArchivePath = Path.Combine(outputPath, zipArchive.name); using (var stream = File.OpenRead(zipArchivePath)) { var fileInfo = new FileInfo(zipArchivePath); var checksum = new Utils.Crc16(); checksum.Update(stream); var bundle = new Manifest.BundleInfo(); bundle.type = Manifest.BundleType.ZipArchive; bundle.name = zipArchive.name; bundle.checksum = checksum.hex; bundle.size = (int)fileInfo.Length; bundle.load = bundleInfo.load; bundle.priority = bundleInfo.priority; foreach (var assetPath in zipArchive.assets) { // var assetPath = AssetDatabase.GetAssetPath(asset.target); bundle.assets.Add(assetPath); } // bundle.dependencies = null; manifest.bundles.Add(bundle); if (bundleInfo.streamingAssets) { embeddedManifest.bundles.Add(new EmbeddedManifest.BundleInfo() { name = bundle.name, checksum = bundle.checksum, size = bundle.size, }); } } } } if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } OutputManifest(manifest, outputPath); OutputEmbeddedManifest(embeddedManifest, outputPath); }