Files

50 lines
1.9 KiB
C#

#if UNITY_EDITOR
using System;
using System.IO;
using HotUpdate.UI;
using UnityEditor;
using UnityEngine;
using UnityEngine.U2D;
using YooAsset.Editor;
namespace AIGame.EditorTools
{
[DisplayName("UI 图片与所属图集同包")]
public sealed class PackUiAtlas : IBundlePackRule
{
public BundlePackRuleResult GetPackRuleResult(BundlePackRuleData data)
{
string path = data.AssetPath.Replace('\\', '/');
if (UiAtlasPaths.IsTexturePath(path)) path = UiAtlasPaths.GetAtlasPathForTexture(path);
else if (!path.StartsWith(UiAtlasPaths.AtlasRoot + "/", StringComparison.Ordinal)
|| !path.EndsWith(".spriteatlas", StringComparison.Ordinal))
throw new ArgumentException("Not a UI atlas input: " + path);
return new BundlePackRuleResult(Path.ChangeExtension(path, null), DefaultBundlePackRule.AssetBundleFileExtension);
}
}
[DisplayName("自动生成的 UI 图集")]
public sealed class CollectUiAtlas : IAssetFilterRule
{
public string FindAssetType => "SpriteAtlas";
public bool IsCollectAsset(AssetFilterRuleData data)
{
var atlas = AssetDatabase.LoadAssetAtPath<SpriteAtlas>(data.AssetPath);
return atlas != null && Array.IndexOf(AssetDatabase.GetLabels(atlas), UiSpriteAtlasGenerator.GeneratedLabel) >= 0;
}
}
[DisplayName("UI 图集原图")]
public sealed class CollectUiAtlasTexture : IAssetFilterRule
{
public string FindAssetType => "Texture2D";
public bool IsCollectAsset(AssetFilterRuleData data)
{
return UiAtlasPaths.IsTexturePath(data.AssetPath)
&& AssetDatabase.LoadAssetAtPath<SpriteAtlas>(UiAtlasPaths.GetAtlasPathForTexture(data.AssetPath)) != null
&& (AssetImporter.GetAtPath(data.AssetPath) as TextureImporter)?.textureType == TextureImporterType.Sprite;
}
}
}
#endif