using UnityEditor;
|
using UnityEditor.U2D;
|
using UnityEngine;
|
|
/// <summary>
|
/// 新资源导入时自动设置平台压缩格式:
|
/// - 纹理(Texture2D):Android→ETC2(有Alpha→RGBA8 / 无Alpha→RGB4) iPhone→ASTC_6x6 WebGL→ASTC_6x6
|
/// - 图集(SpriteAtlas):Android→ETC2_RGBA8 iPhone→ASTC_6x6 WebGL→ASTC_6x6
|
/// - PC(Standalone):不设置覆盖,保持默认
|
///
|
/// 仅处理 Assets/ResourcesOut 下的资源。
|
/// </summary>
|
public class TexturePlatformAssetPostprocessor : AssetPostprocessor
|
{
|
private static readonly string TARGET_FOLDER = TexturePlatformFormatHelper.TARGET_FOLDER;
|
|
void OnPreprocessTexture()
|
{
|
if (!assetPath.StartsWith(TARGET_FOLDER))
|
return;
|
|
var importer = assetImporter as TextureImporter;
|
if (importer == null)
|
return;
|
|
if (TexturePlatformFormatHelper.ApplyTexturePlatformSettings(importer))
|
{
|
Debug.Log($"[TexImport] 贴图: {assetPath}");
|
}
|
}
|
|
static void OnPostprocessAllAssets(
|
string[] importedAssets,
|
string[] deletedAssets,
|
string[] movedAssets,
|
string[] movedFromAssetPaths)
|
{
|
foreach (var assetPath in importedAssets)
|
{
|
if (!assetPath.StartsWith(TARGET_FOLDER))
|
continue;
|
if (!assetPath.EndsWith(".spriteatlasv2") && !assetPath.EndsWith(".spriteatlas"))
|
continue;
|
|
try
|
{
|
var importer = SpriteAtlasImporter.GetAtPath(assetPath) as SpriteAtlasImporter;
|
if (importer == null)
|
continue;
|
|
if (TexturePlatformFormatHelper.ApplyAtlasPlatformSettings(importer))
|
{
|
importer.SaveAndReimport();
|
Debug.Log($"[TexImport] 图集: {assetPath}");
|
}
|
}
|
catch (System.Exception ex)
|
{
|
Debug.LogError($"[TexImport] 图集失败 {assetPath}: {ex.Message}");
|
}
|
}
|
}
|
}
|