From f01e00c1b4cb553b95307682ba66e175a3d80530 Mon Sep 17 00:00:00 2001 From: NTG_DESKTOP Date: Mon, 28 Jul 2025 07:18:39 +0900 Subject: [PATCH] =?UTF-8?q?AssetPostProcessors=20ui=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssetPostProcessors.cs | 13 ++--- .../AssetPostprocessorSprite.cs | 56 ++++++++++++++++--- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs index 7b627294d..dd547e1fb 100644 --- a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs +++ b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostProcessors.cs @@ -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); } diff --git a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs index 338246f3f..19c4c5a73 100644 --- a/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs +++ b/Assets/_DDD/_Scripts/AssetPostprocessors/AssetPostprocessorSprite.cs @@ -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();