Project_WL/AgentScripts/WL816h_Console.cs

59 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// WL-816h — 콘솔 error/warning 수와 error 메시지만 뽑아 파일로 (토큰 절약)
using System.Reflection;
using UnityEngine;
public static class WL816h_Console
{
public static void Dump()
{
var t = System.Type.GetType("UnityEditor.LogEntries,UnityEditor");
var sb = new System.Text.StringBuilder();
object[] args = { 0, 0, 0 };
t.GetMethod("GetCountsByType", BindingFlags.Public | BindingFlags.Static).Invoke(null, args);
sb.AppendLine("error=" + args[0] + " warning=" + args[1] + " log=" + args[2]);
int n = (int)t.GetMethod("StartGettingEntries", BindingFlags.Public | BindingFlags.Static).Invoke(null, null);
var entryType = System.Type.GetType("UnityEditor.LogEntry,UnityEditor");
var entry = System.Activator.CreateInstance(entryType);
var getEntry = t.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static);
var msgF = entryType.GetField("message", BindingFlags.Public | BindingFlags.Instance);
var modeF = entryType.GetField("mode", BindingFlags.Public | BindingFlags.Instance);
var seen = new System.Collections.Generic.Dictionary<string, int>();
for (int i = 0; i < n; i++)
{
object[] a2 = { i, entry };
getEntry.Invoke(null, a2);
int mode = (int)modeF.GetValue(a2[1]);
// Error(1) | Assert(2) | Fatal(0x10) | ScriptingError(0x100) | ScriptingException(0x400) | ScriptCompileError(0x800)
bool isErr = (mode & (1 | 2 | 0x10 | 0x100 | 0x400 | 0x800 | 0x2000)) != 0;
if (!isErr) continue;
string m = (string)msgF.GetValue(a2[1]);
if (m == null) continue;
// 메시지 1줄 + 스택 앞 3줄 (누가 냈는지 보려고)
var lines = m.Split('\n');
var key = new System.Text.StringBuilder(lines[0].Length > 140 ? lines[0].Substring(0, 140) : lines[0]);
for (int k = 1; k < lines.Length && k <= 3; k++)
{
var s = lines[k].Trim();
if (s.Length == 0) continue;
if (s.Length > 120) s = s.Substring(0, 120);
key.Append("\n ").Append(s);
}
string kk = key.ToString();
seen[kk] = seen.ContainsKey(kk) ? seen[kk] + 1 : 1;
}
t.GetMethod("EndGettingEntries", BindingFlags.Public | BindingFlags.Static).Invoke(null, null);
sb.AppendLine("--- error 메시지(중복 묶음) ---");
foreach (var kv in seen) sb.AppendLine(" ×" + kv.Value + " " + kv.Key);
if (seen.Count == 0) sb.AppendLine(" (없음)");
System.IO.File.WriteAllText("AgentScripts/WL816h_CONSOLE.txt", sb.ToString());
Debug.Log("[816h console]\n" + sb);
}
public static void Clear()
{
var t = System.Type.GetType("UnityEditor.LogEntries,UnityEditor");
t.GetMethod("Clear", BindingFlags.Public | BindingFlags.Static).Invoke(null, null);
}
}