update asset bundle builder

remove RemoveSpriteAtlasRedundancy task.
pull/229/head
hevinci 2023-11-01 11:02:46 +08:00
parent 506612527d
commit a4ffa580b7
3 changed files with 0 additions and 79 deletions

View File

@ -1,67 +0,0 @@
using System.Collections.Generic;
using UnityEditor.Build.Content;
using UnityEngine.U2D;
using UnityEditor.Build.Pipeline.Injector;
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEngine;
namespace UnityEditor.Build.Pipeline.Tasks
{
/// <summary>
/// Ref https://zhuanlan.zhihu.com/p/586918159
/// </summary>
public class RemoveSpriteAtlasRedundancy : IBuildTask
{
public int Version => 1;
[InjectContext]
IBundleWriteData writeDataParam;
public ReturnCode Run()
{
#if UNITY_2020_3_OR_NEWER
BundleWriteData writeData = (BundleWriteData)writeDataParam;
// 图集引用的精灵图片集合
HashSet<GUID> spriteGuids = new HashSet<GUID>();
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);
}
}
}
}
// 移除图集引用的精力图片对象
foreach (var pair in writeData.FileToObjects)
{
List<ObjectIdentifier> objectIdentifiers = pair.Value;
for (int i = objectIdentifiers.Count - 1; i >= 0; i--)
{
ObjectIdentifier objectIdentifier = objectIdentifiers[i];
if (spriteGuids.Contains(objectIdentifier.guid))
{
if (objectIdentifier.localIdentifierInFile == 2800000)
{
// 删除图集散图的冗余纹理
objectIdentifiers.RemoveAt(i);
}
}
}
}
#endif
return ReturnCode.Success;
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: f01d5c82be95c8f4b93aeefc0454ae5c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -33,7 +33,6 @@ namespace UnityEditor.Build.Pipeline.Tasks
// Packing
buildTasks.Add(new GenerateBundlePacking());
buildTasks.Add(new RemoveSpriteAtlasRedundancy()); // Fix for SpriteAtlas Redundancy
buildTasks.Add(new UpdateBundleObjectLayout());
buildTasks.Add(new GenerateBundleCommands());
buildTasks.Add(new GenerateSubAssetPathMaps());