From f771a98f25e011990f54a264711919cae2945b2d Mon Sep 17 00:00:00 2001 From: hevinci Date: Wed, 21 Dec 2022 17:11:09 +0800 Subject: [PATCH] update editor code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复开启UniqueBundleName选项后,SBP构建报错的问题。 --- .../AssetBundleBuilder/BuildAssetInfo.cs | 24 ++++++++++--------- .../BuildTasks/TaskBuilding_SBP.cs | 2 +- .../BuildTasks/TaskCreatePatchManifest.cs | 6 ++--- .../AssetBundleCollector/CollectAssetInfo.cs | 8 ------- .../AssetBundleCollector/CollectResult.cs | 8 ------- 5 files changed, 17 insertions(+), 31 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index 71f63da..dd21a6e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -175,8 +175,7 @@ namespace YooAsset.Editor if (IsShaderAsset) { - string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName(); - _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); + _shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName(uniqueBundleName, packageName); } else { @@ -188,14 +187,12 @@ namespace YooAsset.Editor bundleName = EditorTools.GetRegularPath(bundleName).Replace('/', '_').Replace('.', '_').ToLower(); else bundleName = EditorTools.GetRegularPath(bundleName).ToLower(); - _shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; - } - } - if (uniqueBundleName) - { - if (string.IsNullOrEmpty(_shareBundleName) == false) - _shareBundleName = $"{packageName.ToLower()}_{_shareBundleName}"; + if (uniqueBundleName) + _shareBundleName = $"{packageName.ToLower()}_share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; + else + _shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; + } } } else @@ -203,12 +200,17 @@ namespace YooAsset.Editor if (IsRawAsset) { string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.RawFileVariant}"; - _mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower(); + _mainBundleName = mainBundleName.ToLower(); } else { string mainBundleName = $"{_mainBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}"; - _mainBundleName = EditorTools.GetRegularPath(mainBundleName).ToLower(); ; + _mainBundleName = mainBundleName.ToLower(); ; + } + + if (uniqueBundleName) + { + _mainBundleName = $"{packageName.ToLower()}_{_mainBundleName}"; } } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs index 59786a4..d17ee14 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs @@ -33,7 +33,7 @@ namespace YooAsset.Editor // 开始构建 IBundleBuildResults buildResults; var buildParameters = buildParametersContext.GetSBPBuildParameters(); - var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(); + var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParametersContext.Parameters.PackageName); var taskList = SBPBuildTasks.Create(shadersBunldeName); ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); if (exitCode < 0) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 4a5851c..1e0ae3a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -42,12 +42,13 @@ namespace YooAsset.Editor patchManifest.AssetList = GetAllPatchAsset(context, patchManifest); // 更新Unity内置资源包的引用关系 + string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(buildMapContext.UniqueBundleName, buildParameters.PackageName); if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) { if (buildParameters.BuildMode == EBuildMode.IncrementalBuild) { var buildResultContext = context.GetContextObject(); - UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results); + UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results, shadersBunldeName); } } @@ -165,10 +166,9 @@ namespace YooAsset.Editor /// /// 更新Unity内置资源包的引用关系 /// - private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults) + private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults, string shadersBunldeName) { // 获取所有依赖着色器资源包的资源包列表 - string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName(); List shaderBundleReferenceList = new List(); foreach (var valuePair in buildResults.BundleInfos) { diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs index 0db2574..fc9c41b 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/CollectAssetInfo.cs @@ -50,13 +50,5 @@ namespace YooAsset.Editor AssetTags = assetTags; IsRawAsset = isRawAsset; } - - /// - /// 资源包名称追加包裹名 - /// - public void BundleNameAppendPackageName(string packageName) - { - BundleName = $"{packageName.ToLower()}_{BundleName}"; - } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs b/Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs index 040de73..5eca265 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/CollectResult.cs @@ -36,14 +36,6 @@ namespace YooAsset.Editor public void SetCollectAssets(List collectAssets) { CollectAssets = collectAssets; - - if (UniqueBundleName) - { - foreach (var collectAsset in CollectAssets) - { - collectAsset.BundleNameAppendPackageName(PackageName); - } - } } } } \ No newline at end of file