AssetPostProcessors ui 처리

This commit is contained in:
NTG_DESKTOP 2025-07-28 07:18:39 +09:00
parent b836d2db17
commit f01e00c1b4
2 changed files with 54 additions and 15 deletions

View File

@ -12,13 +12,12 @@ private void OnPreprocessTexture()
var importer = assetImporter as TextureImporter;
var upperPath = importer.assetPath.ToUpper();
// if (upperPath.Contains("ASSETS/RAW/Units/"))
// {
// AssetPostprocessorModel.OnPreprocessTexture(importer);
// }
if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
if (upperPath.Contains(PathConstants.RawUiPathUpper))
{
AssetPostprocessorSprite.OnPreprocessTextureForUi(importer);
}
else if (upperPath.Contains(PathConstants.RawSpritesPathUpper))
{
AssetPostprocessorSprite.OnPreprocessTexture(importer);
}

View File

@ -40,6 +40,34 @@ public static void OnPreprocessTexture(TextureImporter importer)
string path = importer.assetPath;
EditorApplication.delayCall += () => { TryApplyPivotAfterImport(path); };
}
public static void OnPreprocessTextureForUi(TextureImporter importer)
{
importer.textureType = TextureImporterType.Sprite;
importer.spriteImportMode = SpriteImportMode.Single;
// 기본 PPU (UI는 100 또는 1 고정 추천)
importer.spritePixelsPerUnit = 100f;
importer.sRGBTexture = true;
importer.isReadable = false;
importer.mipmapEnabled = false;
importer.streamingMipmaps = false;
importer.wrapMode = TextureWrapMode.Clamp;
importer.filterMode = FilterMode.Bilinear;
importer.textureCompression = TextureImporterCompression.Uncompressed;
var textureSettings = new TextureImporterSettings();
importer.ReadTextureSettings(textureSettings);
textureSettings.spriteMeshType = SpriteMeshType.FullRect;
textureSettings.spriteExtrude = 2;
// ✅ UI는 항상 중앙 피벗 (또는 LeftTop 등 고정)
textureSettings.spriteAlignment = (int)SpriteAlignment.Center;
importer.SetTextureSettings(textureSettings);
}
private static void TryApplyPivotAfterImport(string path)
{
@ -99,10 +127,14 @@ private static void TryApplyPivotAfterImport(string path)
public static void OnRemove(string path, string movePath)
{
var upperPath = path.ToUpper();
if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false ||
upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return;
if (TargetPaths.Contains(path) == false)
bool isValid = (upperPath.Contains(PathConstants.RawSpritesPathUpper) ||
upperPath.Contains(PathConstants.RawUiPathUpper))
&& upperPath.Contains(ExtenstionConstants.PngExtensionUpper);
if (!isValid) return;
if (!TargetPaths.Contains(path))
{
TargetPaths.Add(path);
}
@ -111,10 +143,14 @@ public static void OnRemove(string path, string movePath)
public static void OnAdd(string path)
{
var upperPath = path.ToUpper();
if (upperPath.Contains(PathConstants.RawSpritesPathUpper) == false ||
upperPath.Contains(ExtenstionConstants.PngExtensionUpper) == false) return;
if (TargetPaths.Contains(path) == false)
bool isValid = (upperPath.Contains(PathConstants.RawSpritesPathUpper) ||
upperPath.Contains(PathConstants.RawUiPathUpper))
&& upperPath.Contains(ExtenstionConstants.PngExtensionUpper);
if (!isValid) return;
if (!TargetPaths.Contains(path))
{
TargetPaths.Add(path);
}
@ -143,7 +179,9 @@ public static void CreateAtlas(string path, string destPath)
var maxSize = sprite.rect.size.x > sprite.rect.size.y ? sprite.rect.size.x : sprite.rect.size.y;
if (maxSize > 1024)
{
CreateSingleAtlas(filePath, path.Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + $"_{fileName}{ExtenstionConstants.SpriteAtlasExtenstionLower}");
CreateSingleAtlas(filePath,
path.Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) +
$"_{fileName}{ExtenstionConstants.SpriteAtlasExtenstionLower}");
continue;
}
@ -272,7 +310,9 @@ public static void BuildTarget()
{
foreach (var path in TargetPaths)
{
CreateAtlas(Utils.FolderPath(path), Utils.FolderPath(path).Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) + ExtenstionConstants.SpriteAtlasExtenstionLower);
CreateAtlas(Utils.FolderPath(path),
Utils.FolderPath(path).Replace(PathConstants.RawFolderPath, PathConstants.AddressablesFolderPath) +
ExtenstionConstants.SpriteAtlasExtenstionLower);
}
TargetPaths.Clear();