public BuildParametersContext(BuildParameters parameters) { Parameters = parameters; PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget); if (parameters.BuildMode == EBuildMode.DryRunBuild) { PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}"; } else if (parameters.BuildMode == EBuildMode.SimulateBuild) { PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}"; } }
void IBuildTask.Run(BuildContext context) { // 注意:我们只有在强制重建的时候才会拷贝 var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>(); if (buildParameters.Parameters.CopyBuildinTagFiles) { // 清空流目录 AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); // 拷贝内置文件 CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); } }
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion) { // 加载补丁清单 PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion); // 拷贝文件列表 foreach (var patchBundle in patchManifest.BundleList) { if (patchBundle.IsBuildin == false) { continue; } string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝清单文件 { string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝清单哈希文件 { string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝静态版本文件 { string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 刷新目录 AssetDatabase.Refresh(); BuildRunner.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}"); }
/// <summary> /// 执行构建 /// </summary> private void ExecuteBuild() { string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); BuildParameters buildParameters = new BuildParameters(); buildParameters.OutputRoot = defaultOutputRoot; buildParameters.BuildTarget = _buildTarget; buildParameters.BuildMode = (EBuildMode)_buildModeField.value; buildParameters.BuildVersion = _buildVersionField.value; buildParameters.BuildinTags = _buildinTagsField.value; buildParameters.VerifyBuildingResult = true; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; buildParameters.AppendFileExtension = _appendExtensionToggle.value; buildParameters.CopyBuildinTagFiles = _copyBuildinTagFilesToggle.value; buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.CompressOption = (ECompressOption)_compressionField.value; AssetBundleBuilder builder = new AssetBundleBuilder(); builder.Run(buildParameters); }
/// <summary> /// 模拟构建 /// </summary> public static void SimulateBuild() { string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); BuildParameters buildParameters = new BuildParameters(); buildParameters.OutputRoot = defaultOutputRoot; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildMode = EBuildMode.SimulateBuild; buildParameters.BuildVersion = 999; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; AssetBundleBuilder builder = new AssetBundleBuilder(); bool buildResult = builder.Run(buildParameters); if (buildResult) { string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget); _manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}"; } else { _manifestFilePath = null; } }
/// <summary> /// 拷贝补丁文件到补丁包目录 /// </summary> private void CopyPatchFiles(AssetBundleBuilder.BuildParametersContext buildParameters) { int resourceVersion = buildParameters.Parameters.BuildVersion; string packageDirectory = buildParameters.GetPackageDirectory(); BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); // 拷贝Report文件 { string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion); string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}"; string destPath = $"{packageDirectory}/{reportFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝补丁清单文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝补丁清单哈希文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝静态版本文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝UnityManifest序列化文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝UnityManifest文本文件 { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}.manifest"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝所有补丁文件 int progressValue = 0; PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); int patchFileTotalCount = patchManifest.BundleList.Count; foreach (var patchBundle in patchManifest.BundleList) { string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; string destPath = $"{packageDirectory}/{patchBundle.Hash}"; EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); } EditorTools.ClearProgressBar(); }
public void CreateGUI() { try { VisualElement root = this.rootVisualElement; // 加载布局文件 var visualAsset = EditorHelper.LoadWindowUXML <AssetBundleBuilderWindow>(); if (visualAsset == null) { return; } visualAsset.CloneTree(root); _buildTarget = EditorUserBuildSettings.activeBuildTarget; _encryptionServicesClassTypes = GetEncryptionServicesClassTypes(); _encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList(); // 输出目录 string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget); _buildOutputField = root.Q <TextField>("BuildOutput"); _buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory); _buildOutputField.SetEnabled(false); // 构建版本 _buildVersionField = root.Q <IntegerField>("BuildVersion"); _buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion); _buildVersionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; }); // 构建模式 _buildModeField = root.Q <EnumField>("BuildMode"); _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.style.width = 300; _buildModeField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value; RefreshWindow(); }); // 内置资源标签 _buildinTagsField = root.Q <TextField>("BuildinTags"); _buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags); _buildinTagsField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value; }); // 加密方法 var encryptionContainer = root.Q("EncryptionContainer"); if (_encryptionServicesClassNames.Count > 0) { int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName); _encryptionField = new PopupField <string>(_encryptionServicesClassNames, defaultIndex); _encryptionField.label = "Encryption"; _encryptionField.style.width = 300; _encryptionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value; }); encryptionContainer.Add(_encryptionField); } else { _encryptionField = new PopupField <string>(); _encryptionField.label = "Encryption"; _encryptionField.style.width = 300; encryptionContainer.Add(_encryptionField); } // 压缩方式 _compressionField = root.Q <EnumField>("Compression"); _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.style.width = 300; _compressionField.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; }); // 附加后缀格式 _appendExtensionToggle = root.Q <Toggle>("AppendExtension"); _appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); _appendExtensionToggle.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; }); // 拷贝首包文件 _copyBuildinTagFilesToggle = root.Q <Toggle>("CopyBuildinFiles"); _copyBuildinTagFilesToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles); _copyBuildinTagFilesToggle.RegisterValueChangedCallback(evt => { AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles = _copyBuildinTagFilesToggle.value; }); // 构建按钮 var buildButton = root.Q <Button>("Build"); buildButton.clicked += BuildButton_clicked;; RefreshWindow(); } catch (Exception e) { Debug.LogError(e.ToString()); } }
void IBuildTask.Run(BuildContext context) { var buildParameters = context.GetContextObject <AssetBundleBuilder.BuildParametersContext>(); buildParameters.BeginWatch(); // 检测构建平台是否合法 if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget) { throw new Exception("请选择目标平台"); } // 检测构建版本是否合法 if (buildParameters.Parameters.BuildVersion <= 0) { throw new Exception("请先设置版本号"); } // 检测输出目录是否为空 if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) { throw new Exception("输出目录不能为空"); } // 增量更新时候的必要检测 var buildMode = buildParameters.Parameters.BuildMode; if (buildMode == EBuildMode.IncrementalBuild) { // 检测历史版本是否存在 if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false) { throw new Exception("没有发现任何历史版本,请尝试强制重建"); } // 检测构建版本是否合法 int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot); if (buildParameters.Parameters.BuildVersion <= maxPackageVersion) { throw new Exception("构建版本不能小于历史版本"); } // 检测补丁包是否已经存在 string packageDirectory = buildParameters.GetPackageDirectory(); if (Directory.Exists(packageDirectory)) { throw new Exception($"补丁包已经存在:{packageDirectory}"); } // 检测内置资源分类标签是否一致 var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory); if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags) { throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}"); } } // 如果是强制重建 if (buildMode == EBuildMode.ForceRebuild) { // 删除平台总目录 string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; if (EditorTools.DeleteDirectory(platformDirectory)) { BuildRunner.Log($"删除平台总目录:{platformDirectory}"); } } // 如果输出目录不存在 if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory)) { BuildRunner.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}"); } }
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext) { PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); BuildReport buildReport = new BuildReport(); // 概述信息 { buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.BuildTime = DateTime.Now.ToString(); buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds(); buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles; buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ? "null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; // 构建参数 buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; // 构建结果 buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest); buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest); buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest); buildReport.Summary.BuildinBundleTotalSize = GetBuildinBundleSize(patchManifest); buildReport.Summary.EncryptedBundleTotalCount = GetEncryptedBundleCount(patchManifest); buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(patchManifest); buildReport.Summary.RawBundleTotalCount = GetRawBundleCount(patchManifest); buildReport.Summary.RawBundleTotalSize = GetRawBundleSize(patchManifest); } // 资源对象列表 buildReport.AssetInfos = new List <ReportAssetInfo>(patchManifest.AssetList.Count); foreach (var patchAsset in patchManifest.AssetList) { var mainBundle = patchManifest.BundleList[patchAsset.BundleID]; ReportAssetInfo reportAssetInfo = new ReportAssetInfo(); reportAssetInfo.Address = patchAsset.Address; reportAssetInfo.AssetPath = patchAsset.AssetPath; reportAssetInfo.AssetTags = patchAsset.AssetTags; reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath); reportAssetInfo.MainBundleName = mainBundle.BundleName; reportAssetInfo.MainBundleSize = mainBundle.SizeBytes; reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset); reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath); buildReport.AssetInfos.Add(reportAssetInfo); } // 资源包列表 buildReport.BundleInfos = new List <ReportBundleInfo>(patchManifest.BundleList.Count); foreach (var patchBundle in patchManifest.BundleList) { ReportBundleInfo reportBundleInfo = new ReportBundleInfo(); reportBundleInfo.BundleName = patchBundle.BundleName; reportBundleInfo.Hash = patchBundle.Hash; reportBundleInfo.CRC = patchBundle.CRC; reportBundleInfo.SizeBytes = patchBundle.SizeBytes; reportBundleInfo.Tags = patchBundle.Tags; reportBundleInfo.Flags = patchBundle.Flags; buildReport.BundleInfos.Add(reportBundleInfo); } // 删除旧文件 string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}"; if (File.Exists(filePath)) { File.Delete(filePath); } // 序列化文件 BuildReport.Serialize(filePath, buildReport); BuildRunner.Log($"资源构建报告文件创建完成:{filePath}"); }