From a5138b98465bcb612402eef94f957e61d85ef5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Fri, 29 Aug 2025 19:06:55 +0800 Subject: [PATCH] =?UTF-8?q?feat=20:=20=E5=9C=A8SBP=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E7=AE=A1=E7=BA=BF=E9=87=8C=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=BB=BA?= =?UTF-8?q?=E7=AB=8B=E4=B8=BB=E8=B5=84=E6=BA=90=E5=AF=B9=E8=B1=A1=E5=AF=B9?= =?UTF-8?q?=E5=9B=BE=E9=9B=86=E7=9A=84=E4=BE=9D=E8=B5=96=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssetBundleBuilder/BuildMapContext.cs | 11 +++++++++++ .../BaseTasks/TaskCreateManifest.cs | 18 ++++++++++++++++-- Assets/YooAsset/Editor/Common/AssetInfo.cs | 11 +++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs index e027e8d7..b2b1455c 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs @@ -13,6 +13,11 @@ namespace YooAsset.Editor /// private readonly Dictionary _bundleInfoDic = new Dictionary(10000); + /// + /// 图集资源集合 + /// + public readonly List SpriteAtlasAssetList = new List(10000); + /// /// 未被依赖的资源列表 /// @@ -60,6 +65,12 @@ namespace YooAsset.Editor newBundleInfo.PackAsset(assetInfo); _bundleInfoDic.Add(bundleName, newBundleInfo); } + + // 统计所有的精灵图集 + if (assetInfo.AssetInfo.IsSpriteAtlas()) + { + SpriteAtlasAssetList.Add(assetInfo); + } } /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs index 305d8ee3..263f126b 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskCreateManifest.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Collections; using System.Collections.Generic; +using UnityEditor; namespace YooAsset.Editor { @@ -301,15 +302,28 @@ namespace YooAsset.Editor #region YOOASSET_LEGACY_DEPENDENCY private void ProcessBuiltinBundleDependency(BuildContext context, PackageManifest manifest) { + // 注意:初始化资源清单建立引用关系 + ManifestTools.InitManifest(manifest); + // 注意:如果是可编程构建管线,需要补充内置资源包 // 注意:该步骤依赖前面的操作! var buildResultContext = context.TryGetContextObject(); if (buildResultContext != null) { - // 注意:初始化资源清单建立引用关系 - ManifestTools.InitManifest(manifest); ProcessBuiltinBundleReference(context, manifest, buildResultContext.BuiltinShadersBundleName); ProcessBuiltinBundleReference(context, manifest, buildResultContext.MonoScriptsBundleName); + + // 注意:检测是否开启图集模式 + // 说明:需要记录主资源对象对图集的依赖关系! + if (EditorSettings.spritePackerMode != SpritePackerMode.Disabled) + { + var buildMapContext = context.GetContextObject(); + foreach (var spriteAtlasAsset in buildMapContext.SpriteAtlasAssetList) + { + string spriteAtlasBundleName = spriteAtlasAsset.BundleName; + ProcessBuiltinBundleReference(context, manifest, spriteAtlasBundleName); + } + } } } private void ProcessBuiltinBundleReference(BuildContext context, PackageManifest manifest, string builtinBundleName) diff --git a/Assets/YooAsset/Editor/Common/AssetInfo.cs b/Assets/YooAsset/Editor/Common/AssetInfo.cs index bef65871..615fef97 100644 --- a/Assets/YooAsset/Editor/Common/AssetInfo.cs +++ b/Assets/YooAsset/Editor/Common/AssetInfo.cs @@ -62,6 +62,17 @@ namespace YooAsset.Editor return false; } + /// + /// 是否为图集资源 + /// + public bool IsSpriteAtlas() + { + if (AssetType == typeof(UnityEngine.U2D.SpriteAtlas)) + return true; + else + return false; + } + public int CompareTo(AssetInfo other) { return this.AssetPath.CompareTo(other.AssetPath);