Add UnityExplorer camera/UI diagnostic script

Reflection-based so it compiles across Cinemachine versions. Dumps cameras,
Cinemachine lens FOV, and CanvasScaler settings to identify what drives FOV
and what breaks the HUD at ultrawide.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-21 15:06:02 -04:00
co-authored by Claude Opus 4.8
parent b6ab1bf5ab
commit e21c6c3c44
+51
View File
@@ -0,0 +1,51 @@
// UnityExplorer C# console diagnostic — paste into the C# Console tab, hit Run.
// Dumps cameras, Cinemachine lenses, and UI scalers so we can see what drives FOV
// and what breaks the HUD at ultrawide. Reflection-based so it compiles regardless
// of Cinemachine version/namespace (Unity 6 uses Unity.Cinemachine, older uses Cinemachine).
var sb = new System.Text.StringBuilder();
sb.AppendLine($"SCREEN {UnityEngine.Screen.width}x{UnityEngine.Screen.height} " +
$"aspect={(float)UnityEngine.Screen.width / UnityEngine.Screen.height:F4} " +
$"full={UnityEngine.Screen.fullScreenMode}");
foreach (var c in UnityEngine.Object.FindObjectsOfType<UnityEngine.Camera>())
sb.AppendLine($"CAM {c.name} depth={c.depth} fov={c.fieldOfView:F2} aspect={c.aspect:F4} " +
$"phys={c.usePhysicalProperties} gate={c.gateFit} sensor={c.sensorSize} rect={c.rect} " +
$"ortho={c.orthographic} enabled={c.enabled}");
// --- Cinemachine (any version) via reflection ---
foreach (var mb in UnityEngine.Object.FindObjectsOfType<UnityEngine.MonoBehaviour>())
{
var t = mb.GetType();
if (t.FullName == null || t.FullName.IndexOf("Cinemachine", System.StringComparison.OrdinalIgnoreCase) < 0)
continue;
object lens = null;
var bf = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance;
foreach (var name in new[] { "Lens", "m_Lens" })
{
var p = t.GetProperty(name, bf); if (p != null) { lens = p.GetValue(mb); break; }
var f = t.GetField(name, bf); if (f != null) { lens = f.GetValue(mb); break; }
}
if (lens != null)
{
var lt = lens.GetType();
object fov = null, mode = null;
foreach (var n in new[] { "FieldOfView", "m_FieldOfView" })
{ var f = lt.GetField(n, bf); if (f != null) { fov = f.GetValue(lens); break; } }
foreach (var n in new[] { "ModeOverride", "m_ModeOverride" })
{ var f = lt.GetField(n, bf); if (f != null) { mode = f.GetValue(lens); break; } }
sb.AppendLine($"CM {t.Name} '{mb.name}' lensFOV={fov} modeOverride={mode} enabled={mb.enabled}");
}
else sb.AppendLine($"CM {t.Name} '{mb.name}' (no lens field) enabled={mb.enabled}");
}
// --- uGUI canvas scalers (HUD scaling at ultrawide) ---
foreach (var cs in UnityEngine.Object.FindObjectsOfType<UnityEngine.UI.CanvasScaler>())
sb.AppendLine($"UI {cs.name} mode={cs.uiScaleMode} ref={cs.referenceResolution} " +
$"match={cs.matchWidthOrHeight} screenMatch={cs.screenMatchMode}");
foreach (var cv in UnityEngine.Object.FindObjectsOfType<UnityEngine.Canvas>())
sb.AppendLine($"CANV {cv.name} mode={cv.renderMode} cam={(cv.worldCamera ? cv.worldCamera.name : "none")}");
UnityExplorer.ExplorerCore.Log(sb.ToString());