update asset bundle builder

pull/186/head^2
hevinci 2023-09-25 17:59:31 +08:00
parent 11386a7ec2
commit bcb6443300
4 changed files with 62 additions and 60 deletions

View File

@ -28,6 +28,11 @@ namespace YooAsset.Editor
/// 缓存服务器端口 /// 缓存服务器端口
/// </summary> /// </summary>
public int CacheServerPort; public int CacheServerPort;
/// <summary>
/// 修复图集资源冗余问题
/// </summary>
public bool FixSpriteAtlasRedundancy = false;
} }
/// <summary> /// <summary>

View File

@ -13,31 +13,27 @@ namespace UnityEditor.Build.Pipeline.Tasks
/// </summary> /// </summary>
public class RemoveSpriteAtlasRedundancy : IBuildTask public class RemoveSpriteAtlasRedundancy : IBuildTask
{ {
/// <inheritdoc />
public int Version => 1; public int Version => 1;
[InjectContext] [InjectContext]
IBundleWriteData writeDataParam; IBundleWriteData writeDataParam;
/// <inheritdoc />
public ReturnCode Run() public ReturnCode Run()
{ {
#if UNITY_2020_3_OR_NEWER #if UNITY_2020_3_OR_NEWER
BundleWriteData writeData = (BundleWriteData)writeDataParam; BundleWriteData writeData = (BundleWriteData)writeDataParam;
// 所有图集散图的 guid 集合 // 图集引用的精灵图片集合
HashSet<GUID> spriteGuids = new HashSet<GUID>(); HashSet<GUID> spriteGuids = new HashSet<GUID>();
// 遍历资源包里的资源记录其中图集的散图 guid
foreach (var pair in writeData.FileToObjects) foreach (var pair in writeData.FileToObjects)
{ {
foreach (ObjectIdentifier objectIdentifier in pair.Value) foreach (ObjectIdentifier objectIdentifier in pair.Value)
{ {
string path = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid); var assetPath = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
Object asset = AssetDatabase.LoadAssetAtPath<Object>(path); var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
if (asset is SpriteAtlas) if (assetType == typeof(SpriteAtlas))
{ {
List<string> spritePaths = AssetDatabase.GetDependencies(path, false).ToList(); var spritePaths = AssetDatabase.GetDependencies(assetPath, false);
foreach (string spritePath in spritePaths) foreach (string spritePath in spritePaths)
{ {
GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath); GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
@ -47,7 +43,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
} }
} }
// 将 writeData.FileToObjects 包含的图集散图的 texture 删掉避免冗余 // 移除图集引用的精力图片对象
foreach (var pair in writeData.FileToObjects) foreach (var pair in writeData.FileToObjects)
{ {
List<ObjectIdentifier> objectIdentifiers = pair.Value; List<ObjectIdentifier> objectIdentifiers = pair.Value;
@ -58,7 +54,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
{ {
if (objectIdentifier.localIdentifierInFile == 2800000) if (objectIdentifier.localIdentifierInFile == 2800000)
{ {
// 删除图集散图的冗余 texture // 删除图集散图的冗余纹理
objectIdentifiers.RemoveAt(i); objectIdentifiers.RemoveAt(i);
} }
} }

View File

@ -9,7 +9,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
{ {
public static class SBPBuildTasks public static class SBPBuildTasks
{ {
public static IList<IBuildTask> Create(string builtInShaderBundleName) public static IList<IBuildTask> Create(bool fixSpriteAtlasRedundancy, string builtInShaderBundleName)
{ {
var buildTasks = new List<IBuildTask>(); var buildTasks = new List<IBuildTask>();
@ -33,7 +33,8 @@ namespace UnityEditor.Build.Pipeline.Tasks
// Packing // Packing
buildTasks.Add(new GenerateBundlePacking()); buildTasks.Add(new GenerateBundlePacking());
buildTasks.Add(new RemoveSpriteAtlasRedundancy()); // Fix for SpriteAtlas Redundancy if (fixSpriteAtlasRedundancy)
buildTasks.Add(new RemoveSpriteAtlasRedundancy());
buildTasks.Add(new UpdateBundleObjectLayout()); buildTasks.Add(new UpdateBundleObjectLayout());
buildTasks.Add(new GenerateBundleCommands()); buildTasks.Add(new GenerateBundleCommands());
buildTasks.Add(new GenerateSubAssetPathMaps()); buildTasks.Add(new GenerateSubAssetPathMaps());

View File

@ -33,7 +33,7 @@ namespace YooAsset.Editor
// 开始构建 // 开始构建
IBundleBuildResults buildResults; IBundleBuildResults buildResults;
var buildParameters = buildParametersContext.GetSBPBuildParameters(); var buildParameters = buildParametersContext.GetSBPBuildParameters();
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName); var taskList = SBPBuildTasks.Create(buildParametersContext.Parameters.SBPParameters.FixSpriteAtlasRedundancy, buildMapContext.Command.ShadersBundleName);
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
if (exitCode < 0) if (exitCode < 0)
{ {