diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
index cef251a..7707dc5 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs
@@ -28,6 +28,11 @@ namespace YooAsset.Editor
/// 缓存服务器端口
///
public int CacheServerPort;
+
+ ///
+ /// 修复图集资源冗余问题
+ ///
+ public bool FixSpriteAtlasRedundancy = false;
}
///
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/ExtdBuildTasks.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/ExtdBuildTasks.cs
index c50cce5..aafb847 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/ExtdBuildTasks.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/ExtdBuildTasks.cs
@@ -8,65 +8,61 @@ using System.Linq;
namespace UnityEditor.Build.Pipeline.Tasks
{
- ///
- /// Ref https://zhuanlan.zhihu.com/p/586918159
- ///
- public class RemoveSpriteAtlasRedundancy : IBuildTask
- {
- ///
- public int Version => 1;
+ ///
+ /// Ref https://zhuanlan.zhihu.com/p/586918159
+ ///
+ public class RemoveSpriteAtlasRedundancy : IBuildTask
+ {
+ public int Version => 1;
- [InjectContext]
- IBundleWriteData writeDataParam;
+ [InjectContext]
+ IBundleWriteData writeDataParam;
- ///
- public ReturnCode Run()
- {
+ public ReturnCode Run()
+ {
#if UNITY_2020_3_OR_NEWER
- BundleWriteData writeData = (BundleWriteData)writeDataParam;
+ BundleWriteData writeData = (BundleWriteData)writeDataParam;
- // 所有图集散图的 guid 集合
- HashSet spriteGuids = new HashSet();
+ // 图集引用的精灵图片集合
+ HashSet spriteGuids = new HashSet();
+ foreach (var pair in writeData.FileToObjects)
+ {
+ foreach (ObjectIdentifier objectIdentifier in pair.Value)
+ {
+ var assetPath = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
+ var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
+ if (assetType == typeof(SpriteAtlas))
+ {
+ var spritePaths = AssetDatabase.GetDependencies(assetPath, false);
+ foreach (string spritePath in spritePaths)
+ {
+ GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
+ spriteGuids.Add(spriteGuild);
+ }
+ }
+ }
+ }
- // 遍历资源包里的资源记录其中图集的散图 guid
- foreach (var pair in writeData.FileToObjects)
- {
- foreach (ObjectIdentifier objectIdentifier in pair.Value)
- {
- string path = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
- Object asset = AssetDatabase.LoadAssetAtPath