Project_WL/AgentScripts/WL_MonsterRuntimeProbe.cs

201 lines
10 KiB
C#

// PD 지시 #757 — Play 중 스포너·몬스터·Stage UI 검증 프로브 (읽기 전용)
// 실행: unity command run_script --file AgentScripts/WL_MonsterRuntimeProbe.cs --entry WL_MonsterRuntimeProbe.Run
// CLAUDE.md §1 준수: using 금지 · 네임스페이스 풀어 쓰기
public static class WL_MonsterRuntimeProbe
{
const string kLogPath = "AgentScripts/staging/WL_Monsters/RUNTIME_LOG.txt";
static System.Text.StringBuilder s;
public static string Run()
{
s = new System.Text.StringBuilder();
L("===== 런타임 검증 t=" + UnityEngine.Time.realtimeSinceStartup.ToString("F1") + "s =====");
L("playing=" + UnityEngine.Application.isPlaying + " timeScale=" + UnityEngine.Time.timeScale);
// 씬
var sb = new System.Text.StringBuilder();
for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCount; i++)
{
var sc = UnityEngine.SceneManagement.SceneManager.GetSceneAt(i);
if (sb.Length > 0) sb.Append(", ");
sb.Append(sc.name + "(" + (sc.isLoaded ? "loaded" : "loading") + ")");
}
L("씬: " + sb);
// 게임 모드 · 맵
if (InGameInfo.Ins != null)
{
L("GameMode = " + InGameInfo.Ins.Get_GameMode() + " (Stage 여야 함)");
L("MyChoiceMapData.n_MapID = " + MyValue.MyChoiceMapData.n_MapID);
}
else L("[경고] InGameInfo 인스턴스 없음");
// 로딩 UI
if (LoadingUI.isIns && LoadingUI.Ins.go != null)
L("LoadingUI 활성 = " + LoadingUI.Ins.go.activeInHierarchy + " (false 여야 로딩 종료)");
// Stage HUD
if (NewGameUI.isIns)
{
var ng = NewGameUI.Ins;
var g = new System.Text.StringBuilder();
for (int i = 0; i < ng.gos.Length; i++) g.Append("gos[" + i + "]=" + (ng.gos[i] == null ? "null" : ng.gos[i].activeInHierarchy.ToString()) + " ");
for (int i = 0; i < ng.gos_ingame.Length; i++) g.Append("gos_ingame[" + i + "]=" + (ng.gos_ingame[i] == null ? "null" : ng.gos_ingame[i].activeInHierarchy.ToString()) + " ");
for (int i = 0; i < ng.gos_etc.Length; i++) g.Append("gos_etc[" + i + "]=" + (ng.gos_etc[i] == null ? "null" : ng.gos_etc[i].activeInHierarchy.ToString()) + " ");
L("NewGameUI: " + g);
}
// 스포너
var mgrs = UnityEngine.Object.FindObjectsByType<MobControlMgr>(UnityEngine.FindObjectsSortMode.None);
L("MobControlMgr 씬 내 = " + mgrs.Length + "개 (기대 19)");
int done = 0;
var notDone = new System.Text.StringBuilder();
for (int i = 0; i < mgrs.Length; i++)
{
if (mgrs[i].Get_LoadComplete()) done++;
else { if (notDone.Length > 0) notDone.Append(","); notDone.Append(mgrs[i].SpawnerID); }
}
L("로드 완료 스포너 = " + done + "/" + mgrs.Length + (notDone.Length > 0 ? " 미완료ID: " + notDone : ""));
// Lv 라벨
int lvOk = 0, lvUnknown = 0;
var lvs = new System.Text.StringBuilder();
for (int i = 0; i < mgrs.Length; i++)
{
var t = mgrs[i].text_lv;
if (t == null) continue;
if (t.text.Contains("?")) lvUnknown++; else lvOk++;
if (lvs.Length > 0) lvs.Append(" ");
lvs.Append(mgrs[i].SpawnerID + ":" + t.text);
}
L("Lv 라벨 정상 " + lvOk + " · 미해결(???) " + lvUnknown);
L("라벨값: " + lvs);
// 몬스터
var mobs = UnityEngine.Object.FindObjectsByType<MobActor>(UnityEngine.FindObjectsSortMode.None);
int alive = 0;
for (int i = 0; i < mobs.Length; i++) if (mobs[i].isActiveAndEnabled) alive++;
L("MobActor 생성 총수 = " + mobs.Length + " · 활성 = " + alive + " (테이블 n_MaxMonsterCount 합계 175 기대)");
// 플레이어
if (MyValue.bMyPC && MyValue.MyPC != null)
{
var pc = MyValue.MyPC;
L("플레이어 위치 = " + pc.transform.position.ToString("F2") + " scale=" + pc.transform.localScale.ToString("F2"));
var anim = pc.GetComponentInChildren<UnityEngine.Animator>(true);
if (anim != null)
{
L("Animator controller = " + (anim.runtimeAnimatorController == null ? "null" : anim.runtimeAnimatorController.name));
L(" lying 보유=" + anim.HasState(0, UnityEngine.Animator.StringToHash("lying"))
+ " getup 보유=" + anim.HasState(0, UnityEngine.Animator.StringToHash("getup")));
var st = anim.GetCurrentAnimatorStateInfo(0);
L(" 현재 상태 hash=" + st.shortNameHash + " normTime=" + st.normalizedTime.ToString("F2"));
}
// 가장 가까운 몬스터
float best = float.MaxValue; MobActor near = null;
for (int i = 0; i < mobs.Length; i++)
{
if (!mobs[i].isActiveAndEnabled) continue;
float d = UnityEngine.Vector3.Distance(pc.transform.position, mobs[i].transform.position);
if (d < best) { best = d; near = mobs[i]; }
}
L("가장 가까운 활성 몬스터 = " + (near == null ? "없음" : near.name + " " + best.ToString("F1") + "m @" + near.transform.position.ToString("F1")));
}
else L("[경고] MyPC 없음");
Flush();
return "OK — " + kLogPath;
}
// 전투 확인용: 가장 가까운 몬스터의 HP 를 찍는다
public static string Mob()
{
s = new System.Text.StringBuilder();
var mobs = UnityEngine.Object.FindObjectsByType<MobActor>(UnityEngine.FindObjectsSortMode.None);
int alive = 0; for (int i = 0; i < mobs.Length; i++) if (mobs[i].isActiveAndEnabled) alive++;
L("t=" + UnityEngine.Time.realtimeSinceStartup.ToString("F1") + " 총 " + mobs.Length + " 활성 " + alive);
if (MyValue.bMyPC && MyValue.MyPC != null)
{
var pc = MyValue.MyPC;
L("PC pos=" + pc.transform.position.ToString("F2") + " HP=" + Num(pc, "Get_HP"));
float best = float.MaxValue; MobActor near = null;
for (int i = 0; i < mobs.Length; i++)
{
if (!mobs[i].isActiveAndEnabled) continue;
float d = UnityEngine.Vector3.Distance(pc.transform.position, mobs[i].transform.position);
if (d < best) { best = d; near = mobs[i]; }
}
if (near != null)
L("근접몹 " + near.name + " d=" + best.ToString("F1") + " HP=" + Num(near, "Get_HP") + " active=" + near.isActiveAndEnabled);
}
var txt = s.ToString();
System.IO.File.AppendAllText(kLogPath, txt);
return txt;
}
// 지정 스포너를 내려다보는 임시 카메라로 렌더 (몬스터 군집 캡처용 · 저장은 Assets 밖)
public static string Shot(string arg)
{
var parts = arg.Split(':');
int id = int.Parse(parts[0]);
string tag = parts.Length > 1 ? parts[1] : ("spawner" + id);
float height = parts.Length > 2 ? float.Parse(parts[2]) : 18f;
float back = parts.Length > 3 ? float.Parse(parts[3]) : 18f;
var mgrs = UnityEngine.Object.FindObjectsByType<MobControlMgr>(UnityEngine.FindObjectsSortMode.None);
MobControlMgr target = null;
for (int i = 0; i < mgrs.Length; i++) if (mgrs[i].SpawnerID == id) { target = mgrs[i]; break; }
if (target == null) return "SpawnerID " + id + " 없음";
int alive = 0;
var mobs = UnityEngine.Object.FindObjectsByType<MobActor>(UnityEngine.FindObjectsSortMode.None);
for (int i = 0; i < mobs.Length; i++)
if (mobs[i].isActiveAndEnabled && UnityEngine.Vector3.Distance(mobs[i].transform.position, target.transform.position) <= target.MobGenRange + 5f) alive++;
var src = UnityEngine.Camera.main;
int w = 1280, h = 720;
var rt = new UnityEngine.RenderTexture(w, h, 24, UnityEngine.RenderTextureFormat.ARGB32);
var go = new UnityEngine.GameObject("__wlShotCam");
var c = go.AddComponent<UnityEngine.Camera>();
if (src != null) c.CopyFrom(src);
c.targetTexture = rt; c.enabled = false; c.orthographic = false; c.fieldOfView = 60f;
var dir = new UnityEngine.Vector3(-0.707f, 0f, 0.707f); // CamRot_Portal 315도 방향
go.transform.position = target.transform.position - dir * back + UnityEngine.Vector3.up * height;
go.transform.LookAt(target.transform.position);
c.Render();
var prev = UnityEngine.RenderTexture.active;
UnityEngine.RenderTexture.active = rt;
var tex = new UnityEngine.Texture2D(w, h, UnityEngine.TextureFormat.RGB24, false);
tex.ReadPixels(new UnityEngine.Rect(0, 0, w, h), 0, 0); tex.Apply();
UnityEngine.RenderTexture.active = prev;
var d = "Screenshots_WL/monsters";
System.IO.Directory.CreateDirectory(d);
var path = d + "/" + tag + ".png";
System.IO.File.WriteAllBytes(path, UnityEngine.ImageConversion.EncodeToPNG(tex));
UnityEngine.Object.DestroyImmediate(go); UnityEngine.Object.DestroyImmediate(tex);
rt.Release(); UnityEngine.Object.DestroyImmediate(rt);
return "saved " + path + " SpawnerID=" + id + " @" + target.transform.position.ToString("F1")
+ " 반경내 활성몹=" + alive + " 라벨=" + (target.text_lv == null ? "-" : target.text_lv.text);
}
static string Num(object o, string method)
{
if (o == null) return "-";
var m = o.GetType().GetMethod(method, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (m == null || m.GetParameters().Length != 0) return "(no " + method + ")";
try { return System.Convert.ToString(m.Invoke(o, null)); } catch (System.Exception e) { return "err:" + e.Message; }
}
static void L(string t) { s.AppendLine(t); }
static void Flush()
{
var dir = System.IO.Path.GetDirectoryName(kLogPath);
if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);
System.IO.File.WriteAllText(kLogPath, s.ToString());
}
}