2026-11-04 04:05:46 +00:00
using System.IO ;
using UnityEditor ;
using UnityEngine ;
namespace TKS.EditorTools
{
/// <summary>
2026-11-11 14:51:31 +00:00
/// Assets/Resources/Units/<art>/<clip>/f###.png 임포트 설정: 단일 스프라이트 · 피벗 = meta.json pivot(발) · PPU = meta.ppu · 밉맵 + Trilinear(2026-11-11) · 무압축.
2026-11-04 04:05:46 +00:00
/// meta.json 은 skeletal-anim-pipeline `rig_frames_export.py` 가 쓴다.
/// </summary>
public class UnitArtImporter : AssetPostprocessor
{
public const string Root = "Assets/Resources/Units/" ;
2026-11-04 06:56:02 +00:00
/// <summary>전장 배경(원화 세션 납품 · 5:8 불투명 · PPU 100 = 전장 20× 32 월드).</summary>
public const string BoardRoot = "Assets/Resources/Board/" ;
2026-11-04 18:38:47 +00:00
/// <summary>챕터 월드맵(Maps = 2160× 3840 불투명) · 거점 UI 부품(UI = 투명 · pivot·9-slice·PPU = UI/import.json).</summary>
public const string ChapterMapRoot = "Assets/Resources/ChapterMap/" ;
2026-11-18 08:05:31 +00:00
/// <summary>
/// UI 풍경 그림(연무장 허브 · PD 2026-11-18 · 테마 등록 없이 Resources 경로로 읽음) — 배경 = 불투명 · 최대 4096(1620× 2400 원본 크기 유지 · 2048 이면 줄어듦) ·
/// 압축 = 기존 배경(bg_dom_* · keyart)과 같은 Compressed · Android 덮어쓰기 없음 · 밉맵 없음 · 앞 층(layers/) = 투명 · 최대 1024.
/// </summary>
public const string UiSceneRoot = "Assets/Resources/UI/Yeonmu/" ;
2026-11-18 05:48:47 +00:00
/// <summary>투기장 화면(PD 2026-11-18 「투기장 UI 완료」) — 연무장 허브와 같은 규칙(바로 아래 = 배경 · 하위 폴더 parts/ = 투명 부품 · 부품 9 분할 = 그 폴더 import.json).</summary>
public const string UiLeagueRoot = "Assets/Resources/UI/League/" ;
/// <summary>연의 전기 화면(PD 2026-11-18 「연의 전기 통과」) — 같은 규칙(바로 아래 = 탭 배경 · parts/ = 두루마리 · 상세 두루마리 9 분할 = import.json).</summary>
public const string UiScenarioRoot = "Assets/Resources/UI/Scenario/" ;
2026-11-18 12:47:48 +00:00
/// <summary>천하제일 탑 화면(PD 2026-11-18 「B안으로 진행해」) — 같은 규칙(바로 아래 = 하늘 2장 · parts/ = 탑 조각 3(max 2048 = import.json) · 문 빛 · 화살표).</summary>
public const string UiTowerRoot = "Assets/Resources/UI/Tower/" ;
2026-11-18 14:06:36 +00:00
/// <summary>훈련장(보급전) 메뉴(PD 2026-11-18 「위 내용으로 게임에 반영」) — 같은 규칙(banners/ = 배너 4장 · 둥근 모서리 투명 · max 2048 = import.json · parts/ = 「/」 글자 판).</summary>
public const string UiSupplyRoot = "Assets/Resources/UI/Supply/" ;
2026-11-19 13:37:08 +00:00
/// <summary>이벤트 화면(PD 2026-11-19 「게임에 구현해」) — 같은 규칙(바로 아래 = 룰렛 배경 · banners/ = 배너 · 팝업 머리 · big/ = 바둑판 · parts/ = 아틀라스 부품 · 9 분할 · 최대 크기 = 그 폴더 import.json).</summary>
public const string UiEventRoot = "Assets/Resources/UI/Event/" ;
2026-11-12 05:00:15 +00:00
/// <summary>Android 유닛 프레임 긴 변 상한(Fable 검토 2026-11-12 · 원화 PNG 는 그대로 · 빌드 때만 축소).</summary>
public const int AndroidUnitMaxSize = 512 ;
/// <summary>Android 유닛 프레임 압축(ASTC 5× 5 시작값 · 출시 전 4× 4·6× 6 과 육안 비교로 확정).</summary>
public const TextureImporterFormat AndroidUnitFormat = TextureImporterFormat . ASTC_5x5 ;
2026-11-04 18:38:47 +00:00
[System.Serializable]
class ChapterUiImport
{
public string file ;
public float [ ] pivot ;
public float [ ] border ;
public float ppu ;
2026-11-18 05:48:47 +00:00
/// <summary>임포트 최대 크기(0 = 기본 · UI 풍경 부품 기본 1024 보다 큰 그림 = 연의 전기 상세 두루마리 1000× 1302).</summary>
public int max ;
2026-11-04 18:38:47 +00:00
}
[System.Serializable]
class ChapterUiImportList
{
public ChapterUiImport [ ] items ;
}
2026-11-04 04:05:46 +00:00
void OnPreprocessTexture ( )
{
string path = assetPath . Replace ( '\\' , '/' ) ;
2026-11-04 18:38:47 +00:00
if ( path . StartsWith ( ChapterMapRoot ) )
{
PreprocessChapterMap ( path ) ;
return ;
}
2026-11-04 06:56:02 +00:00
if ( path . StartsWith ( BoardRoot ) )
{
var bi = ( TextureImporter ) assetImporter ;
bi . textureType = TextureImporterType . Sprite ;
bi . spriteImportMode = SpriteImportMode . Single ;
bi . mipmapEnabled = false ;
bi . filterMode = FilterMode . Bilinear ;
bi . alphaIsTransparency = false ;
bi . textureCompression = TextureImporterCompression . Compressed ;
bi . maxTextureSize = 4096 ;
bi . spritePixelsPerUnit = 100f ;
var bs = new TextureImporterSettings ( ) ;
bi . ReadTextureSettings ( bs ) ;
bs . spriteMeshType = SpriteMeshType . FullRect ;
bs . spriteAlignment = ( int ) SpriteAlignment . Center ;
bi . SetTextureSettings ( bs ) ;
return ;
}
2026-11-18 08:05:31 +00:00
if ( path . StartsWith ( UiSceneRoot ) )
{
PreprocessUiScene ( path , UiSceneRoot ) ;
return ;
}
2026-11-18 05:48:47 +00:00
if ( path . StartsWith ( UiLeagueRoot ) )
{
PreprocessUiScene ( path , UiLeagueRoot ) ;
return ;
}
if ( path . StartsWith ( UiScenarioRoot ) )
{
PreprocessUiScene ( path , UiScenarioRoot ) ;
return ;
}
2026-11-18 12:47:48 +00:00
if ( path . StartsWith ( UiTowerRoot ) )
{
PreprocessUiScene ( path , UiTowerRoot ) ;
return ;
}
2026-11-18 14:06:36 +00:00
if ( path . StartsWith ( UiSupplyRoot ) )
{
PreprocessUiScene ( path , UiSupplyRoot ) ;
return ;
}
2026-11-19 13:37:08 +00:00
if ( path . StartsWith ( UiEventRoot ) )
{
PreprocessUiScene ( path , UiEventRoot ) ;
return ;
}
2026-11-04 04:05:46 +00:00
if ( ! path . StartsWith ( Root ) ) return ;
var ti = ( TextureImporter ) assetImporter ;
ti . textureType = TextureImporterType . Sprite ;
ti . spriteImportMode = SpriteImportMode . Single ;
2026-11-11 14:51:31 +00:00
// 밉맵 + Trilinear(Fable 검토 2026-11-11 A안 · PD 「해상도가 조금 깨진 느낌」) — 로비·전투는 원본을 1/3~1/4 로 줄여 그림 →
// 밉맵 없는 Bilinear 는 4× 4 중 2× 2 만 섞어 외곽선이 들쭉날쭉(실측 고주파 +18 % · 반투명 가장자리 − 20 %) · 대기 프레임이 움직이면 그 깨짐이 반짝임으로 보임. 메모리 +33 %.
ti . mipmapEnabled = true ;
ti . filterMode = FilterMode . Trilinear ;
2026-11-04 04:05:46 +00:00
ti . alphaIsTransparency = true ;
ti . textureCompression = TextureImporterCompression . Uncompressed ;
ti . maxTextureSize = 2048 ;
2026-11-12 05:00:15 +00:00
// Android(구글 플레이 출시 · PD 2026-11-12 「리소스 구성 Fable 검토 후 진행」) = 빌드 때만 긴 변 512(표시 0.12~0.56 배) + ASTC 5× 5 · 밉맵 유지
// 장당 ≈ 4.35 → 0.20 MB(계산값) · PC·편집기 화면 불변 · 블록 크기(4× 4·5× 5·6× 6)는 출시 전 Android 전환 육안 비교로 확정(Fable 검토 문서 「출시 전 1」)
var ap = ti . GetPlatformTextureSettings ( "Android" ) ;
ap . overridden = true ;
ap . maxTextureSize = AndroidUnitMaxSize ;
ap . format = AndroidUnitFormat ;
ti . SetPlatformTextureSettings ( ap ) ;
2026-11-04 04:05:46 +00:00
var meta = LoadMeta ( path ) ;
var s = new TextureImporterSettings ( ) ;
ti . ReadTextureSettings ( s ) ;
s . spriteMeshType = SpriteMeshType . FullRect ;
if ( meta ! = null & & meta . pivot ! = null & & meta . pivot . Length = = 2 )
{
s . spriteAlignment = ( int ) SpriteAlignment . Custom ;
s . spritePivot = new Vector2 ( meta . pivot [ 0 ] , meta . pivot [ 1 ] ) ;
}
if ( meta ! = null & & meta . ppu > 0.01f ) s . spritePixelsPerUnit = meta . ppu ;
ti . SetTextureSettings ( s ) ;
}
2026-11-18 05:48:47 +00:00
void PreprocessUiScene ( string path , string root )
{
bool layer = path . Substring ( root . Length ) . Contains ( "/" ) ; // 하위 폴더(layers/ · parts/) = 투명 앞 층·부품 · 바로 아래 = 배경
var ti = ( TextureImporter ) assetImporter ;
ti . textureType = TextureImporterType . Sprite ;
ti . spriteImportMode = SpriteImportMode . Single ;
ti . mipmapEnabled = false ;
ti . filterMode = FilterMode . Bilinear ;
ti . alphaIsTransparency = layer ;
ti . textureCompression = TextureImporterCompression . Compressed ;
ti . maxTextureSize = layer ? 1024 : 4096 ;
ti . spritePixelsPerUnit = 100f ;
var s = new TextureImporterSettings ( ) ;
ti . ReadTextureSettings ( s ) ;
s . spriteMeshType = SpriteMeshType . FullRect ;
s . spriteAlignment = ( int ) SpriteAlignment . Center ;
// 부품 9 분할·피벗 = 그 폴더 import.json(월드맵 UI 부품과 같은 형식 · 없으면 기본 · 투기장 목패 · 띠지)
var item = layer ? FindChapterUi ( path ) : null ;
if ( item ! = null )
{
if ( item . max > 0 ) ti . maxTextureSize = item . max ;
if ( item . pivot ! = null & & item . pivot . Length = = 2 )
{
s . spriteAlignment = ( int ) SpriteAlignment . Custom ;
s . spritePivot = new Vector2 ( item . pivot [ 0 ] , 1f - item . pivot [ 1 ] ) ;
}
if ( item . border ! = null & & item . border . Length = = 4 )
s . spriteBorder = new Vector4 ( item . border [ 0 ] , item . border [ 1 ] , item . border [ 2 ] , item . border [ 3 ] ) ;
if ( item . ppu > 0.01f ) s . spritePixelsPerUnit = item . ppu ;
}
ti . SetTextureSettings ( s ) ;
}
2026-11-04 18:38:47 +00:00
void PreprocessChapterMap ( string path )
{
var ti = ( TextureImporter ) assetImporter ;
ti . textureType = TextureImporterType . Sprite ;
ti . spriteImportMode = SpriteImportMode . Single ;
ti . mipmapEnabled = false ;
ti . filterMode = FilterMode . Bilinear ;
var s = new TextureImporterSettings ( ) ;
if ( path . StartsWith ( ChapterMapRoot + "Maps/" ) )
{
ti . alphaIsTransparency = false ;
ti . textureCompression = TextureImporterCompression . Compressed ;
ti . maxTextureSize = 4096 ;
ti . spritePixelsPerUnit = 100f ;
ti . ReadTextureSettings ( s ) ;
s . spriteMeshType = SpriteMeshType . FullRect ;
s . spriteAlignment = ( int ) SpriteAlignment . Center ;
ti . SetTextureSettings ( s ) ;
return ;
}
ti . alphaIsTransparency = true ;
ti . textureCompression = TextureImporterCompression . Uncompressed ;
ti . maxTextureSize = 1024 ;
ti . ReadTextureSettings ( s ) ;
s . spriteMeshType = SpriteMeshType . FullRect ;
var item = FindChapterUi ( path ) ;
if ( item ! = null )
{
if ( item . pivot ! = null & & item . pivot . Length = = 2 )
{
s . spriteAlignment = ( int ) SpriteAlignment . Custom ;
s . spritePivot = new Vector2 ( item . pivot [ 0 ] , 1f - item . pivot [ 1 ] ) ; // import.json = 이미지 좌표(위 → 아래)
}
if ( item . border ! = null & & item . border . Length = = 4 )
s . spriteBorder = new Vector4 ( item . border [ 0 ] , item . border [ 1 ] , item . border [ 2 ] , item . border [ 3 ] ) ;
if ( item . ppu > 0.01f ) s . spritePixelsPerUnit = item . ppu ;
}
ti . SetTextureSettings ( s ) ;
}
static ChapterUiImport FindChapterUi ( string texPath )
{
string dir = Path . GetDirectoryName ( texPath ) ;
if ( string . IsNullOrEmpty ( dir ) ) return null ;
string json = Path . Combine ( dir , "import.json" ) ;
if ( ! File . Exists ( json ) ) return null ;
try
{
var list = JsonUtility . FromJson < ChapterUiImportList > ( File . ReadAllText ( json ) ) ;
string name = Path . GetFileName ( texPath ) ;
if ( list ! = null & & list . items ! = null )
foreach ( var it in list . items )
if ( it . file = = name ) return it ;
}
catch
{
// 표가 깨졌으면 기본 설정
}
return null ;
}
2026-11-04 04:05:46 +00:00
static UnitArtMeta LoadMeta ( string texPath )
{
string clipDir = Path . GetDirectoryName ( texPath ) ;
string artDir = clipDir ! = null ? Path . GetDirectoryName ( clipDir ) : null ;
if ( string . IsNullOrEmpty ( artDir ) ) return null ;
string metaPath = Path . Combine ( artDir , "meta.json" ) ;
if ( ! File . Exists ( metaPath ) ) return null ;
try
{
return JsonUtility . FromJson < UnitArtMeta > ( File . ReadAllText ( metaPath ) ) ;
}
catch
{
return null ;
}
}
/// <summary>프레임을 새로 넣거나 meta.json 피벗을 바꾼 뒤 임포트 설정을 다시 적용한다(메뉴 · CLI `-executeMethod TKS.EditorTools.UnitArtImporter.ReimportAll`).</summary>
[MenuItem("TKS/Reimport Unit Art (유닛 아트 재임포트)")]
public static void ReimportAll ( )
{
2026-11-18 14:06:36 +00:00
foreach ( var root in new [ ] { Root , BoardRoot , ChapterMapRoot , UiSceneRoot , UiLeagueRoot , UiScenarioRoot , UiTowerRoot , UiSupplyRoot } )
2026-11-04 04:05:46 +00:00
{
2026-11-04 06:56:02 +00:00
string dir = root . TrimEnd ( '/' ) ;
if ( ! AssetDatabase . IsValidFolder ( dir ) )
{
Debug . Log ( "[TKS] " + dir + " 없음" ) ;
continue ;
}
AssetDatabase . ImportAsset ( dir , ImportAssetOptions . ImportRecursive | ImportAssetOptions . ForceUpdate ) ;
Debug . Log ( "[TKS] 아트 재임포트 완료 · " + dir ) ;
2026-11-04 04:05:46 +00:00
}
AssetDatabase . Refresh ( ) ;
}
}
}