/// <summary> /// 创建补丁清单文件到输出目录 /// </summary> private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext) { int resourceVersion = buildParameters.Parameters.BuildVersion; // 创建新补丁清单 PatchManifest patchManifest = new PatchManifest(); patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags; patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext); patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest); // 创建补丁清单文件 string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}"); PatchManifest.Serialize(manifestFilePath, patchManifest); // 创建补丁清单哈希文件 string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; string manifestHash = HashUtility.FileMD5(manifestFilePath); BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}"); FileUtility.CreateFile(manifestHashFilePath, manifestHash); // 创建静态版本文件 string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string staticVersion = resourceVersion.ToString(); BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}"); FileUtility.CreateFile(staticVersionFilePath, staticVersion); }
/// <summary> /// 获取资源包列表 /// </summary> private List <PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext) { List <PatchBundle> result = new List <PatchBundle>(1000); List <string> buildinTags = buildParameters.Parameters.GetBuildinTags(); var buildMode = buildParameters.Parameters.BuildMode; bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild; foreach (var bundleInfo in buildMapContext.BundleInfos) { var bundleName = bundleInfo.BundleName; string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}"; string hash = GetFileHash(filePath, standardBuild); string crc32 = GetFileCRC(filePath, standardBuild); long size = GetFileSize(filePath, standardBuild); string[] tags = buildMapContext.GetBundleTags(bundleName); bool isEncrypted = encryptionContext.IsEncryptFile(bundleName); bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isRawFile = bundleInfo.IsRawFile; // 附加文件扩展名 if (buildParameters.Parameters.AppendFileExtension) { hash += bundleInfo.GetAppendExtension(); } PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags); patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile); result.Add(patchBundle); } return(result); }