mirror of https://github.com/tuyoogame/YooAsset
Merge pull request #151 from michael811125/main
加入 ExtdBuildTasks 进行 SBP 扩展,修复 Sprite 打包冗馀问题 (猫佬方案) + typo errorpull/153/head
commit
880b6d429d
|
@ -0,0 +1,70 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEditor.Build.Content;
|
||||
using UnityEngine.U2D;
|
||||
using UnityEditor.Build.Pipeline.Injector;
|
||||
using UnityEditor.Build.Pipeline.Interfaces;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
namespace UnityEditor.Build.Pipeline.Tasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Ref https://zhuanlan.zhihu.com/p/586918159
|
||||
/// </summary>
|
||||
public class RemoveSpriteAtlasRedundancy : IBuildTask
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public int Version => 1;
|
||||
|
||||
[InjectContext]
|
||||
IBundleWriteData writeDataParam;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ReturnCode Run()
|
||||
{
|
||||
BundleWriteData writeData = (BundleWriteData)writeDataParam;
|
||||
|
||||
// 所有图集散图的 guid 集合
|
||||
HashSet<GUID> spriteGuids = new HashSet<GUID>();
|
||||
|
||||
// 遍历资源包里的资源记录其中图集的散图 guid
|
||||
foreach (var pair in writeData.FileToObjects)
|
||||
{
|
||||
foreach (ObjectIdentifier objectIdentifier in pair.Value)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(objectIdentifier.guid);
|
||||
Object asset = AssetDatabase.LoadAssetAtPath<Object>(path);
|
||||
if (asset is SpriteAtlas)
|
||||
{
|
||||
List<string> spritePaths = AssetDatabase.GetDependencies(path, false).ToList();
|
||||
foreach (string spritePath in spritePaths)
|
||||
{
|
||||
GUID spriteGuild = AssetDatabase.GUIDFromAssetPath(spritePath);
|
||||
spriteGuids.Add(spriteGuild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 将 writeData.FileToObjects 包含的图集散图的 texture 删掉避免冗余
|
||||
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)
|
||||
{
|
||||
// 删除图集散图的冗余 texture
|
||||
objectIdentifiers.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ReturnCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f01d5c82be95c8f4b93aeefc0454ae5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -33,19 +33,20 @@ 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());
|
||||
buildTasks.Add(new GenerateBundleMaps());
|
||||
buildTasks.Add(new PostPackingCallback());
|
||||
|
||||
|
||||
// Writing
|
||||
buildTasks.Add(new WriteSerializedFiles());
|
||||
buildTasks.Add(new ArchiveAndCompressBundles());
|
||||
buildTasks.Add(new AppendBundleHash());
|
||||
buildTasks.Add(new GenerateLinkXml());
|
||||
buildTasks.Add(new PostWritingCallback());
|
||||
|
||||
|
||||
return buildTasks;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ namespace YooAsset.Editor
|
|||
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build package name is null or mepty !");
|
||||
throw new Exception("Build package name is null or empty !");
|
||||
|
||||
var package = GetPackage(packageName);
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
|
@ -131,7 +131,7 @@ namespace YooAsset.Editor
|
|||
if (package.PackageName == packageName)
|
||||
return package;
|
||||
}
|
||||
throw new Exception($"Not found pacakge : {packageName}");
|
||||
throw new Exception($"Not found package : {packageName}");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue