Files
UltraWidePatches/tools/unity_uitune.cs
T
ckochandClaude Opus 4.8 bd9fdc50f6 Fix UI tuner: scaleFactor is ignored in ScaleWithScreenSize
CanvasScaler.scaleFactor only applies to ConstantPixelSize mode, so the old
SCALE_MULT knob would have done nothing. Replaced with HUD_SCALE, implemented
via referenceResolution.y (effective scale = screenH/refH), which genuinely
shrinks the HUD while giving the layout MORE logical room - the right lever
for overlapping text.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 15:52:19 -04:00

57 lines
2.8 KiB
C#

// LIVE UI TUNER — paste into UnityExplorer's C# Console. Edit the knobs, Run, look,
// repeat. Nothing persists; relaunching reverts everything.
//
// IMPORTANT: run this IN-GAME (not the main menu). Different scenes have different
// canvases, and the overlapping text is in the gameplay HUD.
//
// scaleFactor = (screenW/refW)^(1-match) * (screenH/refH)^match
// match=1 scales by HEIGHT (logical height stays 1080 = the design height).
// Lowering match shrinks logical height below 1080 and CRAMPS things vertically.
// ---- KNOBS -----------------------------------------------------------------
float MATCH = 1.0f; // 0 = scale by width, 1 = scale by height
// HUD_SCALE shrinks/grows the HUD *without* cramping the layout.
// <1 = smaller HUD + MORE logical room (use this to cure overlapping text)
// Implemented by raising referenceResolution.y, because CanvasScaler.scaleFactor
// is IGNORED in ScaleWithScreenSize mode (it only applies to ConstantPixelSize).
float HUD_SCALE = 1.0f; // try 0.95, 0.9, 0.85
bool LIST_ONLY = false; // true = report current state, change nothing
// ----------------------------------------------------------------------------
var log = new System.Text.StringBuilder();
log.AppendLine($"SCREEN {UnityEngine.Screen.width}x{UnityEngine.Screen.height} " +
$"aspect={(float)UnityEngine.Screen.width / UnityEngine.Screen.height:F4}");
foreach (var cs in UnityEngine.Object.FindObjectsOfType<UnityEngine.UI.CanvasScaler>())
{
log.AppendLine($"BEFORE {cs.name}: mode={cs.uiScaleMode} ref={cs.referenceResolution} " +
$"match={cs.matchWidthOrHeight} scaleFactor={cs.scaleFactor}");
if (!LIST_ONLY)
{
cs.matchWidthOrHeight = MATCH;
if (HUD_SCALE > 0f && System.Math.Abs(HUD_SCALE - 1f) > 0.0001f)
{
// effective scale = screenH / refH, so refH = designH / HUD_SCALE
var r = cs.referenceResolution;
cs.referenceResolution = new UnityEngine.Vector2(r.x, 1080f / HUD_SCALE);
log.AppendLine($" refResolution {r} -> {cs.referenceResolution}");
}
}
// report the resulting logical canvas the UI is laid out in
var cv = cs.GetComponent<UnityEngine.Canvas>();
float sf = cv ? cv.scaleFactor : 0f;
if (sf > 0)
log.AppendLine($"AFTER {cs.name}: effectiveScale={sf:F4} " +
$"logicalCanvas={UnityEngine.Screen.width / sf:F0}x{UnityEngine.Screen.height / sf:F0}");
}
// Every canvas in the scene — the overlapping text may live on one we haven't touched
foreach (var cv in UnityEngine.Object.FindObjectsOfType<UnityEngine.Canvas>())
log.AppendLine($"CANVAS {cv.name} mode={cv.renderMode} scale={cv.scaleFactor:F4} " +
$"hasScaler={(cv.GetComponent<UnityEngine.UI.CanvasScaler>() != null)} " +
$"sortOrder={cv.sortingOrder}");
UnityExplorer.ExplorerCore.Log(log.ToString());