74 lines
2.9 KiB
C#
74 lines
2.9 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/";
|
|
|
|
void OnPreprocessTexture()
|
|
{
|
|
string path = assetPath.Replace('\\', '/');
|
|
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()
|
|
{
|
|
string dir = Root.TrimEnd('/');
|
|
if (!AssetDatabase.IsValidFolder(dir))
|
|
{
|
|
Debug.Log("[TKS] " + dir + " 없음");
|
|
return;
|
|
}
|
|
AssetDatabase.ImportAsset(dir, ImportAssetOptions.ImportRecursive | ImportAssetOptions.ForceUpdate);
|
|
AssetDatabase.Refresh();
|
|
Debug.Log("[TKS] 유닛 아트 재임포트 완료 · " + dir);
|
|
}
|
|
}
|
|
}
|