// WL-816b — 무기 12종 메시·텍스처 실측 (에디트 모드 · 렌더 없음)
// unity command run_script --file AgentScripts/WL816b_Probe.cs --entry WL816b_Probe.Run
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
public static class WL816b_Probe
{
static readonly StringBuilder sb = new StringBuilder();
static void L(string s) { sb.AppendLine(s); }
public const string WDIR = "Assets/Res_Addr/Weapon/";
/// 비readable 텍스처를 임포터를 건드리지 않고 sRGB 바이트로 읽는다(원본 meta 수정 0).
public static Texture2D ReadAny(Texture src)
{
var rt = RenderTexture.GetTemporary(src.width, src.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
var prevF = (src as Texture2D) != null ? (src as Texture2D).filterMode : FilterMode.Point;
if (src is Texture2D) ((Texture2D)src).filterMode = FilterMode.Point;
Graphics.Blit(src, rt);
if (src is Texture2D) ((Texture2D)src).filterMode = prevF;
var prev = RenderTexture.active; RenderTexture.active = rt;
var t = new Texture2D(src.width, src.height, TextureFormat.RGBA32, false);
t.ReadPixels(new Rect(0, 0, src.width, src.height), 0, 0); t.Apply();
RenderTexture.active = prev; RenderTexture.ReleaseTemporary(rt);
return t;
}
public static void Run()
{
sb.Length = 0;
L("=== WL-816b 무기 프로브 ===");
var files = Directory.GetFiles(WDIR, "*.prefab").OrderBy(f => f).ToArray();
foreach (var f in files)
{
var p = f.Replace('\\', '/');
var go = AssetDatabase.LoadAssetAtPath(p);
if (go == null) { L(Path.GetFileNameWithoutExtension(p) + " : 로드 실패"); continue; }
var mfs = go.GetComponentsInChildren(true);
var smrs = go.GetComponentsInChildren(true);
var rends = go.GetComponentsInChildren(true);
int tris = 0, verts = 0, subs = 0;
var bb = new Bounds(Vector3.zero, Vector3.zero); bool first = true;
foreach (var mf in mfs)
{
var m = mf.sharedMesh; if (m == null) continue;
verts += m.vertexCount; subs += m.subMeshCount;
for (int s = 0; s < m.subMeshCount; s++) tris += (int)(m.GetIndexCount(s) / 3);
var b = m.bounds; if (first) { bb = b; first = false; } else bb.Encapsulate(b);
}
var texs = new List();
foreach (var r in rends)
foreach (var mt in r.sharedMaterials)
{
if (mt == null) { texs.Add("(null mat)"); continue; }
Texture t = null;
if (mt.HasProperty("_BaseMap")) t = mt.GetTexture("_BaseMap");
if (t == null && mt.HasProperty("_MainTex")) t = mt.GetTexture("_MainTex");
string tp = t == null ? "(no tex)" : AssetDatabase.GetAssetPath(t);
var ti = string.IsNullOrEmpty(tp) ? null : AssetImporter.GetAtPath(tp) as TextureImporter;
texs.Add(mt.name + "[" + mt.shader.name + "] tex=" + (t == null ? "-" : t.name + " " + t.width + "x" + t.height
+ " fmt=" + ((t as Texture2D) != null ? ((Texture2D)t).format.ToString() : "?")
+ " filt=" + t.filterMode + " mip=" + t.mipmapCount
+ (ti != null ? " imp(max=" + ti.maxTextureSize + " comp=" + ti.textureCompression + " read=" + ti.isReadable + ")" : ""))
+ " path=" + tp);
}
L(string.Format("{0,-26} rend={1} mf={2} smr={3} verts={4} tris={5} sub={6} size={7} ",
Path.GetFileNameWithoutExtension(p), rends.Length, mfs.Length, smrs.Length, verts, tris, subs,
first ? "-" : bb.size.ToString("F4")));
foreach (var t in texs.Distinct()) L(" " + t);
foreach (var r in rends) L(" rend '" + r.name + "' type=" + r.GetType().Name + " mats=" + r.sharedMaterials.Length);
}
// 텍스처 읽기 검증 — 비readable 원본을 RT 블릿으로 읽는다
L("");
L("=== 텍스처 읽기(블릿) 검증 ===");
foreach (var tp in new[] {
"Assets/ResWork/PurePoly/Fantasy RPG Weapons/Textures/PP_Color_Palette.png",
"Assets/ResWork/Elven Weapons/Textures/Elven_Sword_01.psd",
"Assets/ResWork/Suriyun/Cute_Goblin/Textures/Weapon/T_Dagger.png" })
{
var t = AssetDatabase.LoadAssetAtPath(tp);
if (t == null) { L(tp + " : 로드 실패"); continue; }
var rd = ReadAny(t);
var px = rd.GetPixels32();
var set = new HashSet();
for (int i = 0; i < px.Length; i++) set.Add((px[i].r << 16) | (px[i].g << 8) | px[i].b);
L(string.Format("{0} {1}x{2} fmt={3} 고유색={4} 샘플=({5},{6},{7})", Path.GetFileName(tp), rd.width, rd.height, t.format, set.Count, px[px.Length / 2].r, px[px.Length / 2].g, px[px.Length / 2].b));
UnityEngine.Object.DestroyImmediate(rd);
}
Directory.CreateDirectory("AgentScripts");
File.WriteAllText("AgentScripts/WL816b_PROBE.txt", sb.ToString(), new UTF8Encoding(true));
Debug.Log("[WL816b] probe done → AgentScripts/WL816b_PROBE.txt");
}
}