From cfe8a77dd53b5e9f3db794d2aac33495c30914e4 Mon Sep 17 00:00:00 2001 From: hevinci Date: Tue, 10 Oct 2023 16:19:53 +0800 Subject: [PATCH] fix #179 --- .../BaseTasks/TaskCreateManifest.cs | 32 ++++++++++++------- .../BaseTasks/TaskGetBuildMap.cs | 2 +- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs index 92e08fe..5d56879 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs @@ -16,6 +16,7 @@ namespace YooAsset.Editor public abstract class TaskCreateManifest { private readonly Dictionary _cachedBundleID = new Dictionary(10000); + private readonly Dictionary> _cacheBundleTags = new Dictionary>(10000); /// /// 创建补丁清单文件到输出目录 @@ -165,36 +166,43 @@ namespace YooAsset.Editor /// private void ProcessBundleTags(PackageManifest manifest) { - Dictionary> cacheBundleTags = new Dictionary>(10000); - + // 将主资源的标签信息传染给其依赖的资源包集合 foreach (var packageAsset in manifest.AssetList) { - // 主资源包 + var assetTags = packageAsset.AssetTags; int bundleID = packageAsset.BundleID; - CacheBundleTags(cacheBundleTags, bundleID, packageAsset.AssetTags); + CacheBundleTags(bundleID, assetTags); - // 依赖资源包 var packageBundle = manifest.BundleList[bundleID]; foreach (var dependBundleID in packageBundle.DependIDs) { - CacheBundleTags(cacheBundleTags, dependBundleID, packageAsset.AssetTags); + CacheBundleTags(dependBundleID, assetTags); } } for (int index = 0; index < manifest.BundleList.Count; index++) { - manifest.BundleList[index].Tags = cacheBundleTags[index].ToArray(); + var packageBundle = manifest.BundleList[index]; + if (_cacheBundleTags.ContainsKey(index)) + { + packageBundle.Tags = _cacheBundleTags[index].ToArray(); + } + else + { + // 注意:SBP构建管线会自动剔除一些冗余资源的引用关系,导致游离资源包没有被任何主资源包引用。 + UnityEngine.Debug.LogWarning($"发现游离的资源包 {index} ! {packageBundle.BundleName}"); + } } } - private void CacheBundleTags(Dictionary> cacheBundleTags, int bundleID, string[] assetTags) + private void CacheBundleTags(int bundleID, string[] assetTags) { - if (cacheBundleTags.ContainsKey(bundleID) == false) - cacheBundleTags.Add(bundleID, new HashSet()); + if (_cacheBundleTags.ContainsKey(bundleID) == false) + _cacheBundleTags.Add(bundleID, new HashSet()); foreach (var assetTag in assetTags) { - if (cacheBundleTags[bundleID].Contains(assetTag) == false) - cacheBundleTags[bundleID].Add(assetTag); + if (_cacheBundleTags[bundleID].Contains(assetTag) == false) + _cacheBundleTags[bundleID].Add(assetTag); } } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskGetBuildMap.cs index f64d29b..30a70c9 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskGetBuildMap.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskGetBuildMap.cs @@ -162,7 +162,7 @@ namespace YooAsset.Editor // 4. 移除所有零引用的依赖资源 foreach (var removeValue in removeList) { - BuildLogger.Log($"发现未被依赖的资源并自动移除 : {removeValue.AssetPath}"); + BuildLogger.Warning($"发现未被依赖的资源并自动移除 : {removeValue.AssetPath}"); allCollectAssetInfos.Remove(removeValue); } }