97 lines
4.1 KiB
C#
97 lines
4.1 KiB
C#
using System.IO;
|
||
using UnityEditor;
|
||
using UnityEngine;
|
||
|
||
namespace TKS.EditorTools
|
||
{
|
||
/// <summary>
|
||
/// Assets/Resources/Units/<art>/<clip>/f###.png 임포트 설정: 단일 스프라이트 · 피벗 = meta.json pivot(발) · PPU = meta.ppu · 밉맵 없음 · 무압축.
|
||
/// meta.json 은 skeletal-anim-pipeline `rig_frames_export.py` 가 쓴다.
|
||
/// </summary>
|
||
public class UnitArtImporter : AssetPostprocessor
|
||
{
|
||
public const string Root = "Assets/Resources/Units/";
|
||
/// <summary>전장 배경(원화 세션 납품 · 5:8 불투명 · PPU 100 = 전장 20×32 월드).</summary>
|
||
public const string BoardRoot = "Assets/Resources/Board/";
|
||
|
||
void OnPreprocessTexture()
|
||
{
|
||
string path = assetPath.Replace('\\', '/');
|
||
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;
|
||
}
|
||
if (!path.StartsWith(Root)) return;
|
||
var ti = (TextureImporter)assetImporter;
|
||
ti.textureType = TextureImporterType.Sprite;
|
||
ti.spriteImportMode = SpriteImportMode.Single;
|
||
ti.mipmapEnabled = false;
|
||
ti.filterMode = FilterMode.Bilinear;
|
||
ti.alphaIsTransparency = true;
|
||
ti.textureCompression = TextureImporterCompression.Uncompressed;
|
||
ti.maxTextureSize = 2048;
|
||
|
||
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);
|
||
}
|
||
|
||
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()
|
||
{
|
||
foreach (var root in new[] { Root, BoardRoot })
|
||
{
|
||
string dir = root.TrimEnd('/');
|
||
if (!AssetDatabase.IsValidFolder(dir))
|
||
{
|
||
Debug.Log("[TKS] " + dir + " 없음");
|
||
continue;
|
||
}
|
||
AssetDatabase.ImportAsset(dir, ImportAssetOptions.ImportRecursive | ImportAssetOptions.ForceUpdate);
|
||
Debug.Log("[TKS] 아트 재임포트 완료 · " + dir);
|
||
}
|
||
AssetDatabase.Refresh();
|
||
}
|
||
}
|
||
}
|