From e1801a5fbae7d40de68a8a92fb4a7a3905af59cb Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 27 Sep 2022 21:04:08 +0800 Subject: [PATCH] Update editor logic --- .../AssetBundleBuilder/AssetBundleBuilder.cs | 3 +- .../AssetBundleBuilderHelper.cs | 75 +++---------------- .../AssetBundleBuilderSetting.cs | 5 -- .../AssetBundleBuilderWindow.cs | 16 +--- .../AssetBundleBuilderWindow.uxml | 1 - .../AssetBundleSimulateBuilder.cs | 6 +- .../AssetBundleBuilder/BuildParameters.cs | 5 -- .../BuildParametersContext.cs | 48 +++++++++--- .../BuildReport/ReportSummary.cs | 4 +- .../BuildSystem/BuildResult.cs | 5 ++ .../BuildTasks/TaskBuilding.cs | 13 ++-- .../BuildTasks/TaskBuilding_SBP.cs | 6 +- .../BuildTasks/TaskCopyBuildinFiles.cs | 37 +++++---- .../BuildTasks/TaskCreatePatchManifest.cs | 48 ++++++------ .../BuildTasks/TaskCreatePatchPackage.cs | 58 +++++++------- .../BuildTasks/TaskCreateReport.cs | 38 +++++----- .../BuildTasks/TaskEncryption.cs | 7 +- .../BuildTasks/TaskPrepare.cs | 56 ++++---------- .../BuildTasks/TaskVerifyBuildResult.cs | 7 +- .../AssetBundleCollectorConfig.cs | 2 +- .../AssetBundleCollectorWindow.cs | 2 +- .../VisualViewers/ReporterSummaryViewer.cs | 2 +- Assets/YooAsset/Editor/EditorTools.cs | 3 + 23 files changed, 193 insertions(+), 254 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index 9abe437..2079263 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -86,7 +86,8 @@ namespace YooAsset.Editor var buildResult = BuildRunner.Run(pipeline, _buildContext); if (buildResult.Success) { - buildResult.OutputPackageDirectory = buildParametersContext.GetPackageDirectory(); + buildResult.OutputPackageCRC = buildParametersContext.OutputPackageCRC; + buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory(); Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !"); } else diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs index 2a69920..c4bebed 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs @@ -25,14 +25,6 @@ namespace YooAsset.Editor return $"{Application.dataPath}/StreamingAssets/YooAssets/"; } - /// - /// 获取构建管线的输出目录 - /// - public static string MakePipelineOutputDirectory(string outputRoot, BuildTarget buildTarget) - { - return $"{outputRoot}/{buildTarget}/{YooAssetSettings.OutputFolderName}"; - } - /// /// 清空流文件夹 /// @@ -67,61 +59,25 @@ namespace YooAsset.Editor } } - /// - /// 获取所有补丁包版本列表 - /// 注意:列表会按照版本号从小到大排序 + /// 获取构建管线的输出目录 /// - private static List GetPackageVersionList(BuildTarget buildTarget, string outputRoot) + public static string MakePipelineOutputDirectory(string outputRoot, string buildPackage, BuildTarget buildTarget, EBuildMode buildMode) { - List versionList = new List(); - - string parentPath = $"{outputRoot}/{buildTarget}"; - if (Directory.Exists(parentPath) == false) - return versionList; - - // 获取所有补丁包文件夹 - string[] allFolders = Directory.GetDirectories(parentPath); - for (int i = 0; i < allFolders.Length; i++) - { - string folderName = Path.GetFileNameWithoutExtension(allFolders[i]); - if (int.TryParse(folderName, out int version)) - versionList.Add(version); - } - - // 从小到大排序 - versionList.Sort(); - return versionList; + string result = $"{outputRoot}/{buildPackage}/{buildTarget}/{YooAssetSettings.OutputFolderName}"; + if (buildMode == EBuildMode.DryRunBuild) + result += $"_{EBuildMode.DryRunBuild}"; + else if (buildMode == EBuildMode.SimulateBuild) + result += $"_{EBuildMode.SimulateBuild}"; + return result; } - /// - /// 获取当前最大的补丁包版本号 - /// - /// 如果没有任何补丁版本,那么返回-1 - public static int GetMaxPackageVersion(BuildTarget buildTarget, string outputRoot) - { - List versionList = GetPackageVersionList(buildTarget, outputRoot); - if (versionList.Count == 0) - return -1; - return versionList[versionList.Count - 1]; - } - - /// - /// 是否存在任何补丁包版本 - /// - public static bool HasAnyPackageVersion(BuildTarget buildTarget, string outputRoot) - { - List versionList = GetPackageVersionList(buildTarget, outputRoot); - return versionList.Count > 0; - } - - /// /// 加载补丁清单文件 /// - internal static PatchManifest LoadPatchManifestFile(string fileDirectory, int resourceVersion) + internal static PatchManifest LoadPatchManifestFile(string fileDirectory, string packageName, string packageCRC) { - string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; + string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC)}"; if (File.Exists(filePath) == false) { throw new System.Exception($"Not found patch manifest file : {filePath}"); @@ -130,16 +86,5 @@ namespace YooAsset.Editor string jsonData = FileUtility.ReadFile(filePath); return PatchManifest.Deserialize(jsonData); } - - /// - /// 获取旧的补丁清单 - /// - internal static PatchManifest GetOldPatchManifest(string pipelineOutputDirectory) - { - string staticVersionFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; - string staticVersionContent = FileUtility.ReadFile(staticVersionFilePath); - int staticVersion = int.Parse(staticVersionContent); - return LoadPatchManifestFile(pipelineOutputDirectory, staticVersion); - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index 8b0c8fd..28d0cf7 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -5,11 +5,6 @@ namespace YooAsset.Editor { public class AssetBundleBuilderSetting : ScriptableObject { - /// - /// 构建版本号 - /// - public int BuildVersion = 0; - /// /// 构建管线 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 48bd8ac..a0c6c26 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -25,7 +25,6 @@ namespace YooAsset.Editor private Button _saveButton; private TextField _buildOutputField; - private IntegerField _buildVersionField; private EnumField _buildPipelineField; private EnumField _buildModeField; private TextField _buildinTagsField; @@ -63,20 +62,10 @@ namespace YooAsset.Editor // 输出目录 string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); - string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget); _buildOutputField = root.Q("BuildOutput"); - _buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory); + _buildOutputField.SetValueWithoutNotify(defaultOutputRoot); _buildOutputField.SetEnabled(false); - // 构建版本 - _buildVersionField = root.Q("BuildVersion"); - _buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion); - _buildVersionField.RegisterValueChangedCallback(evt => - { - AssetBundleBuilderSettingData.IsDirty = true; - AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; - }); - // 构建管线 _buildPipelineField = root.Q("BuildPipeline"); _buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline); @@ -249,7 +238,6 @@ namespace YooAsset.Editor buildParameters.BuildTarget = _buildTarget; buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline; buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode; - buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion; buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.VerifyBuildingResult = true; @@ -269,7 +257,7 @@ namespace YooAsset.Editor var buildResult = builder.Run(buildParameters); if (buildResult.Success) { - EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}"); + EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory); } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml index 67006da..79f579f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml @@ -4,7 +4,6 @@ - diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs index b9a556f..39c078f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs @@ -16,7 +16,6 @@ namespace YooAsset.Editor buildParameters.OutputRoot = defaultOutputRoot; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildMode = EBuildMode.SimulateBuild; - buildParameters.BuildVersion = 999; buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; @@ -24,8 +23,9 @@ namespace YooAsset.Editor var buildResult = builder.Run(buildParameters); if (buildResult.Success) { - string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget); - _manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}"; + string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildPackage, buildParameters.BuildTarget, buildParameters.BuildMode); + string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildResult.OutputPackageCRC); + _manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}"; } else { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs index 1cad106..741a835 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs @@ -61,11 +61,6 @@ namespace YooAsset.Editor /// public string BuildPackage; - /// - /// 构建的版本(资源版本号) - /// - public int BuildVersion; - /// /// 内置资源标签集合(首包资源标签) /// 注意:分号为分隔符 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs index e06d7fc..96a1ca1 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParametersContext.cs @@ -9,34 +9,61 @@ namespace YooAsset.Editor { private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch(); + private string _pipelineOutputDirectory = string.Empty; + private string _packageOutputDirectory = string.Empty; + private string _outputPackageCRC = string.Empty; + /// /// 构建参数 /// public BuildParameters Parameters { private set; get; } /// - /// 构建管线的输出目录 + /// 构建输出的包裹清单哈希值 /// - public string PipelineOutputDirectory { private set; get; } + public string OutputPackageCRC + { + get + { + if (string.IsNullOrEmpty(_outputPackageCRC)) + throw new Exception("Output package file CRC32 is empty !"); + return _outputPackageCRC; + } + set + { + _outputPackageCRC = value; + } + } 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}"; + /// + /// 获取构建管线的输出目录 + /// + /// + public string GetPipelineOutputDirectory() + { + if (string.IsNullOrEmpty(_pipelineOutputDirectory)) + { + _pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(Parameters.OutputRoot, Parameters.BuildPackage, Parameters.BuildTarget, Parameters.BuildMode); + } + return _pipelineOutputDirectory; } /// /// 获取本次构建的补丁目录 /// - public string GetPackageDirectory() + public string GetPackageOutputDirectory() { - return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}"; + if (string.IsNullOrEmpty(_packageOutputDirectory)) + { + _packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildPackage}/{Parameters.BuildTarget}/{OutputPackageCRC}"; + } + return _packageOutputDirectory; } /// @@ -86,7 +113,8 @@ namespace YooAsset.Editor throw new Exception("Should never get here !"); var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget); - var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory); + var pipelineOutputDirectory = GetPipelineOutputDirectory(); + var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, pipelineOutputDirectory); if (Parameters.CompressOption == ECompressOption.Uncompressed) buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs index 67fbf99..86d2345 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs @@ -44,9 +44,9 @@ namespace YooAsset.Editor public EBuildMode BuildMode; /// - /// 构建版本 + /// 构建包裹 /// - public int BuildVersion; + public string BuildPackage; /// /// 内置资源标签 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildResult.cs index c47623d..2f52e51 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildResult.cs @@ -25,5 +25,10 @@ namespace YooAsset.Editor /// 输出的补丁包目录 /// public string OutputPackageDirectory; + + /// + /// 输出的包裹清单哈希值 + /// + public string OutputPackageCRC; } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs index ae47991..e1d4ece 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs @@ -25,14 +25,15 @@ namespace YooAsset.Editor if (buildMode == EBuildMode.SimulateBuild) return; - BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions(); - AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget); + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); + BuildAssetBundleOptions buildOptions = buildParametersContext.GetPipelineBuildOptions(); + AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget); if (buildResults == null) throw new Exception("构建过程中发生错误!"); if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) { - string unityOutputManifestFilePath = $"{buildParametersContext.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; + string unityOutputManifestFilePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{YooAssetSettings.OutputFolderName}"; if(System.IO.File.Exists(unityOutputManifestFilePath) == false) throw new Exception("构建过程中发生严重错误!请查阅上下文日志!"); } @@ -54,11 +55,12 @@ namespace YooAsset.Editor /// private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) { + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.BundleInfos) { if (bundleInfo.IsRawFile) { - string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; foreach (var buildAsset in bundleInfo.BuildinAssets) { if (buildAsset.IsRawAsset) @@ -73,11 +75,12 @@ namespace YooAsset.Editor /// private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult) { + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.BundleInfos) { if (bundleInfo.IsRawFile) { - string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; bundleInfo.ContentHash = HashUtility.FileMD5(filePath); } else diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs index d2fa771..c7651b2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs @@ -58,11 +58,12 @@ namespace YooAsset.Editor /// private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) { + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.BundleInfos) { if (bundleInfo.IsRawFile) { - string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; foreach (var buildAsset in bundleInfo.BuildinAssets) { if (buildAsset.IsRawAsset) @@ -77,11 +78,12 @@ namespace YooAsset.Editor /// private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult) { + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.BundleInfos) { if (bundleInfo.IsRawFile) { - string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; bundleInfo.ContentHash = HashUtility.FileMD5(filePath); } else diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs index d031e71..2d766f9 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCopyBuildinFiles.cs @@ -11,22 +11,26 @@ namespace YooAsset.Editor { void IBuildTask.Run(BuildContext context) { - // 注意:我们只有在强制重建的时候才会拷贝 - var buildParameters = context.GetContextObject(); - if (buildParameters.Parameters.CopyBuildinTagFiles) + var buildParametersContext = context.GetContextObject(); + if (buildParametersContext.Parameters.CopyBuildinTagFiles) { // 清空流目录 AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); // 拷贝内置文件 - CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); + CopyBuildinFilesToStreaming(buildParametersContext); } } - private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion) + private void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext) { + string streamingAssetsOutputDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath(); + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); + string packageName = buildParametersContext.Parameters.BuildPackage; + string packageCRC = buildParametersContext.OutputPackageCRC; + // 加载补丁清单 - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, packageName, packageCRC); // 拷贝文件列表 foreach (var patchBundle in patchManifest.BundleList) @@ -35,34 +39,29 @@ namespace YooAsset.Editor continue; string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.FileName}"; + string destPath = $"{streamingAssetsOutputDirectory}/{patchBundle.FileName}"; 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)}"; + string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC); + string sourcePath = $"{pipelineOutputDirectory}/{manifestFileName}"; + string destPath = $"{streamingAssetsOutputDirectory}/{manifestFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝静态版本文件 { - string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}"; + string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(packageName); + string sourcePath = $"{pipelineOutputDirectory}/{versionFileName}"; + string destPath = $"{streamingAssetsOutputDirectory}/{versionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 刷新目录 AssetDatabase.Refresh(); - BuildRunner.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}"); + BuildRunner.Log($"内置文件拷贝完成:{streamingAssetsOutputDirectory}"); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 1b15a73..8f17399 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -21,23 +21,24 @@ namespace YooAsset.Editor /// private void CreatePatchManifestFile(BuildContext context) { - var buildParameters = context.GetContextObject(); - int resourceVersion = buildParameters.Parameters.BuildVersion; + var buildParametersContext = context.GetContextObject(); + var buildParameters = buildParametersContext.Parameters; + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); // 创建新补丁清单 PatchManifest patchManifest = new PatchManifest(); patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion; - patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; - patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; - patchManifest.OutputNameStyle = (int)buildParameters.Parameters.OutputNameStyle; - patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags; + patchManifest.EnableAddressable = buildParameters.EnableAddressable; + patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle; + patchManifest.PackageName = buildParameters.BuildPackage; + patchManifest.BuildinTags = buildParameters.BuildinTags; patchManifest.BundleList = GetAllPatchBundle(context); patchManifest.AssetList = GetAllPatchAsset(context, patchManifest); // 更新Unity内置资源包的引用关系 - if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) + if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) { - if(buildParameters.Parameters.BuildMode == EBuildMode.IncrementalBuild) + if(buildParameters.BuildMode == EBuildMode.IncrementalBuild) { var buildResultContext = context.GetContextObject(); UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results); @@ -45,21 +46,24 @@ namespace YooAsset.Editor } // 创建补丁清单文件 - string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; - BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}"); - PatchManifest.Serialize(manifestFilePath, patchManifest); + string manifestFileTempName = YooAssetSettingsData.GetPatchManifestTempFileName(buildParameters.BuildPackage); + string manifestFileTempPath = $"{pipelineOutputDirectory}/{manifestFileTempName}"; + BuildRunner.Log($"创建补丁清单文件:{manifestFileTempPath}"); + PatchManifest.Serialize(manifestFileTempPath, patchManifest); - // 创建补丁清单哈希文件 - string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; - string manifestHash = HashUtility.FileMD5(manifestFilePath); - BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}"); - FileUtility.CreateFile(manifestHashFilePath, manifestHash); + // 计算补丁清单文件的CRC32 + buildParametersContext.OutputPackageCRC = HashUtility.FileCRC32(manifestFileTempPath); + + // 补丁清单文件重命名 + string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); + string manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}"; + EditorTools.FileMoveTo(manifestFileTempPath, manifestFilePath); // 创建静态版本文件 - string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; - string staticVersion = resourceVersion.ToString(); + string staticVersionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage); + string staticVersionFilePath = $"{pipelineOutputDirectory}/{staticVersionFileName}"; BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}"); - FileUtility.CreateFile(staticVersionFilePath, staticVersion); + FileUtility.CreateFile(staticVersionFilePath, buildParametersContext.OutputPackageCRC); } /// @@ -111,7 +115,7 @@ namespace YooAsset.Editor if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return "00000000000000000000000000000000"; //32位 - string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}"; return HashUtility.FileMD5(filePath); } private string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) @@ -120,7 +124,7 @@ namespace YooAsset.Editor if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return "00000000"; //8位 - string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}"; return HashUtility.FileCRC32(filePath); } private long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) @@ -129,7 +133,7 @@ namespace YooAsset.Editor if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return 0; - string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}"; return FileUtility.GetFileSize(filePath); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs index a99ae92..6d13fea 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchPackage.cs @@ -19,55 +19,51 @@ namespace YooAsset.Editor /// /// 拷贝补丁文件到补丁包目录 /// - private void CopyPatchFiles(BuildParametersContext buildParameters) + private void CopyPatchFiles(BuildParametersContext buildParametersContext) { - int resourceVersion = buildParameters.Parameters.BuildVersion; - string packageDirectory = buildParameters.GetPackageDirectory(); - BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); + var buildParameters = buildParametersContext.Parameters; + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); + string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory(); + BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageOutputDirectory}"); // 拷贝Report文件 { - string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion); - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}"; - string destPath = $"{packageDirectory}/{reportFileName}"; + string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); + string sourcePath = $"{pipelineOutputDirectory}/{reportFileName}"; + string destPath = $"{packageOutputDirectory}/{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)}"; + string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); + string sourcePath = $"{pipelineOutputDirectory}/{manifestFileName}"; + string destPath = $"{packageOutputDirectory}/{manifestFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝静态版本文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; - string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}"; + string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage); + string sourcePath = $"{pipelineOutputDirectory}/{versionFileName}"; + string destPath = $"{packageOutputDirectory}/{versionFileName}"; EditorTools.CopyFile(sourcePath, destPath, true); } - if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) + if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) { // 拷贝构建日志 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json"; - string destPath = $"{packageDirectory}/buildlogtep.json"; + string sourcePath = $"{pipelineOutputDirectory}/buildlogtep.json"; + string destPath = $"{packageOutputDirectory}/buildlogtep.json"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝代码防裁剪配置 - if (buildParameters.Parameters.SBPParameters.WriteLinkXML) + if (buildParameters.SBPParameters.WriteLinkXML) { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml"; - string destPath = $"{packageDirectory}/link.xml"; + string sourcePath = $"{pipelineOutputDirectory}/link.xml"; + string destPath = $"{packageOutputDirectory}/link.xml"; EditorTools.CopyFile(sourcePath, destPath, true); } } @@ -75,27 +71,27 @@ namespace YooAsset.Editor { // 拷贝UnityManifest序列化文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; - string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}"; + string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; + string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}"; EditorTools.CopyFile(sourcePath, destPath, true); } // 拷贝UnityManifest文本文件 { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; - string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; + string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; + string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; EditorTools.CopyFile(sourcePath, destPath, true); } } // 拷贝所有补丁文件 int progressValue = 0; - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); int patchFileTotalCount = patchManifest.BundleList.Count; foreach (var patchBundle in patchManifest.BundleList) { - string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; - string destPath = $"{packageDirectory}/{patchBundle.FileName}"; + string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; + string destPath = $"{packageOutputDirectory}/{patchBundle.FileName}"; EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index c74e638..9904974 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -24,9 +24,12 @@ namespace YooAsset.Editor BuildRunner.Info($"Build time consuming {buildSeconds} seconds."); } - private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext) + private void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) { - PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); + var buildParameters = buildParametersContext.Parameters; + + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); + PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); BuildReport buildReport = new BuildReport(); // 概述信息 @@ -38,22 +41,22 @@ namespace YooAsset.Editor #endif buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.BuildDate = DateTime.Now.ToString(); - buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds(); - buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; - buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline; - 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.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles; - buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ? - "null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; + buildReport.Summary.BuildSeconds = (int)buildParametersContext.GetBuildingSeconds(); + buildReport.Summary.BuildTarget = buildParameters.BuildTarget; + buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline; + buildReport.Summary.BuildMode = buildParameters.BuildMode; + buildReport.Summary.BuildPackage = buildParameters.BuildPackage; + buildReport.Summary.BuildinTags = buildParameters.BuildinTags; + buildReport.Summary.EnableAddressable = buildParameters.EnableAddressable; + buildReport.Summary.CopyBuildinTagFiles = buildParameters.CopyBuildinTagFiles; + buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ? + "null" : buildParameters.EncryptionServices.GetType().FullName; // 构建参数 - buildReport.Summary.OutputNameStyle = buildParameters.Parameters.OutputNameStyle; - buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; - buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; - buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; + buildReport.Summary.OutputNameStyle = buildParameters.OutputNameStyle; + buildReport.Summary.CompressOption = buildParameters.CompressOption; + buildReport.Summary.DisableWriteTypeTree = buildParameters.DisableWriteTypeTree; + buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.IgnoreTypeTreeChanges; // 构建结果 buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; @@ -101,7 +104,8 @@ namespace YooAsset.Editor } // 删除旧文件 - string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}"; + string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC); + string filePath = $"{pipelineOutputDirectory}/{fileName}"; if (File.Exists(filePath)) File.Delete(filePath); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs index eb006d9..4f9554a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs @@ -45,9 +45,9 @@ namespace YooAsset.Editor /// /// 加密文件 /// - private List EncryptFiles(BuildParametersContext buildParameters, BuildMapContext buildMapContext) + private List EncryptFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext) { - var encryptionServices = buildParameters.Parameters.EncryptionServices; + var encryptionServices = buildParametersContext.Parameters.EncryptionServices; // 加密资源列表 List encryptList = new List(); @@ -57,6 +57,7 @@ namespace YooAsset.Editor return encryptList; int progressValue = 0; + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var bundleInfo in buildMapContext.BundleInfos) { if (encryptionServices.Check(bundleInfo.BundleName)) @@ -70,7 +71,7 @@ namespace YooAsset.Editor encryptList.Add(bundleInfo.BundleName); // 注意:通过判断文件合法性,规避重复加密一个文件 - string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleInfo.BundleName}"; + string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; byte[] fileData = File.ReadAllBytes(filePath); if (EditorTools.CheckBundleFileValid(fileData)) { diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs index 034cf5b..44a62e2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs @@ -11,24 +11,18 @@ namespace YooAsset.Editor { void IBuildTask.Run(BuildContext context) { - var buildParameters = context.GetContextObject(); - buildParameters.BeginWatch(); + var buildParametersContext = context.GetContextObject(); + buildParametersContext.BeginWatch(); - var buildMode = buildParameters.Parameters.BuildMode; + var buildParameters = buildParametersContext.Parameters; - // 检测构建平台是否合法 - if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget) + // 检测构建参数合法性 + if (buildParameters.BuildTarget == BuildTarget.NoTarget) throw new Exception("请选择目标平台"); + if (string.IsNullOrEmpty(buildParameters.BuildPackage)) + throw new Exception("包裹名称不能为空"); - // 检测构建版本是否合法 - if (buildParameters.Parameters.BuildVersion <= 0) - throw new Exception("请先设置版本号"); - - // 检测输出目录是否为空 - if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory)) - throw new Exception("输出目录不能为空"); - - if (buildMode != EBuildMode.SimulateBuild) + if (buildParameters.BuildMode != EBuildMode.SimulateBuild) { // 检测当前是否正在构建资源包 if (BuildPipeline.isBuildingPlayer) @@ -41,35 +35,10 @@ namespace YooAsset.Editor // 保存改动的资源 AssetDatabase.SaveAssets(); } - - // 增量更新时候的必要检测 - if (buildMode == EBuildMode.IncrementalBuild) - { - // 检测历史版本是否存在 - if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot)) - { - // 检测构建版本是否合法 - 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) + if (buildParameters.BuildMode == EBuildMode.ForceRebuild) { // 删除平台总目录 - string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; + string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildPackage}/{buildParameters.BuildTarget}"; if (EditorTools.DeleteDirectory(platformDirectory)) { BuildRunner.Log($"删除平台总目录:{platformDirectory}"); @@ -77,9 +46,10 @@ namespace YooAsset.Editor } // 如果输出目录不存在 - if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory)) + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); + if (EditorTools.CreateDirectory(pipelineOutputDirectory)) { - BuildRunner.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}"); + BuildRunner.Log($"创建输出目录:{pipelineOutputDirectory}"); } } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs index 8816f0c..1623942 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs @@ -32,7 +32,7 @@ namespace YooAsset.Editor /// private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest) { - var buildParameters = context.GetContextObject(); + var buildParametersContext = context.GetContextObject(); var buildMapContext = context.GetContextObject(); string[] buildedBundles = unityManifest.GetAllAssetBundles(); @@ -63,13 +63,14 @@ namespace YooAsset.Editor // 4. 验证Asset bool isPass = true; - var buildMode = buildParameters.Parameters.BuildMode; + var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) { int progressValue = 0; + string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); foreach (var buildedBundle in buildedBundles) { - string filePath = $"{buildParameters.PipelineOutputDirectory}/{buildedBundle}"; + string filePath = $"{pipelineOutputDirectory}/{buildedBundle}"; string[] buildedAssetPaths = GetAssetBundleAllAssets(filePath); string[] mapAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle); if (mapAssetPaths.Length != buildedAssetPaths.Length) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs index 60fb1b7..edfd408 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs @@ -240,7 +240,7 @@ namespace YooAsset.Editor // 添加包裹元素 var packageElement = xmlDoc.CreateElement(XmlPackage); - packageElement.SetAttribute(XmlPackageName, "Default Package"); + packageElement.SetAttribute(XmlPackageName, "DefaultPackage"); packageElement.SetAttribute(XmlPackageDesc, string.Empty); root.AppendChild(packageElement); diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index c512e70..9447ae4 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -374,7 +374,7 @@ namespace YooAsset.Editor private void AddPackageBtn_clicked() { Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddPackage"); - AssetBundleCollectorSettingData.CreatePackage("Default Package"); + AssetBundleCollectorSettingData.CreatePackage("DefaultPackage"); FillPackageViewData(); } private void RemovePackageBtn_clicked() diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs index 417578b..1bb244f 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/ReporterSummaryViewer.cs @@ -66,7 +66,7 @@ namespace YooAsset.Editor _items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}")); _items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}")); _items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}")); - _items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}")); + _items.Add(new ItemWrapper("构建包裹", $"{buildReport.Summary.BuildPackage}")); _items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}")); _items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}")); diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index f91c041..3664478 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -353,6 +353,9 @@ namespace YooAsset.Editor /// public static void FileMoveTo(string filePath, string destPath) { + if (File.Exists(destPath)) + File.Delete(destPath); + FileInfo fileInfo = new FileInfo(filePath); fileInfo.MoveTo(destPath); }