Pasting the file verbatim was a no-op because the knobs shipped at 1.0, so every run reported KNOBS ...=1 and changed nothing. Default to HUD_SCALE=0.85 and WORLD_SCALE=0.8 so copying the file straight from the editor actually exercises the fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
64 lines
3.1 KiB
C#
64 lines
3.1 KiB
C#
// LIVE UI TUNER — paste into UnityExplorer's C# Console. Edit knobs, Run, look, repeat.
|
|
// Nothing persists; a scene change or relaunch reverts everything.
|
|
//
|
|
// This game has TWO canvas families, tuned by DIFFERENT properties:
|
|
// 1. ScreenSpaceOverlay + ScaleWithScreenSize ("Canvas", "Canvas in front")
|
|
// -> the HUD. Controlled by matchWidthOrHeight + referenceResolution.
|
|
// 2. WorldSpace + ConstantPixelSize ("NamePlate", etc.)
|
|
// -> in-world labels. Unity IGNORES referenceResolution here;
|
|
// ONLY scaleFactor does anything.
|
|
//
|
|
// The tuner prints the knob values it actually used, so you can confirm your edit took.
|
|
|
|
// ---- KNOBS -----------------------------------------------------------------
|
|
float MATCH = 1.0f; // ScaleWithScreenSize only. 0=scale by width, 1=by height
|
|
float HUD_SCALE = 0.85f; // ScaleWithScreenSize only. <1 = smaller HUD + more room
|
|
float WORLD_SCALE = 0.8f; // ConstantPixelSize only. <1 = smaller in-world labels
|
|
bool LIST_ONLY = false; // true = report only, change nothing
|
|
// ----------------------------------------------------------------------------
|
|
|
|
var log = new System.Text.StringBuilder();
|
|
log.AppendLine($"KNOBS match={MATCH} hudScale={HUD_SCALE} worldScale={WORLD_SCALE} listOnly={LIST_ONLY}");
|
|
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>())
|
|
{
|
|
var cv = cs.GetComponent<UnityEngine.Canvas>();
|
|
string render = cv ? cv.renderMode.ToString() : "?";
|
|
log.AppendLine($"BEFORE {cs.name} [{cs.uiScaleMode}/{render}] ref={cs.referenceResolution} " +
|
|
$"match={cs.matchWidthOrHeight} scaleFactor={cs.scaleFactor}");
|
|
|
|
if (!LIST_ONLY)
|
|
{
|
|
if (cs.uiScaleMode == UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize)
|
|
{
|
|
cs.matchWidthOrHeight = MATCH;
|
|
// effective scale = screenH / refH => refH = 1080 / HUD_SCALE
|
|
if (HUD_SCALE > 0f && System.Math.Abs(HUD_SCALE - 1f) > 0.0001f)
|
|
{
|
|
var r = cs.referenceResolution;
|
|
cs.referenceResolution = new UnityEngine.Vector2(r.x, 1080f / HUD_SCALE);
|
|
log.AppendLine($" APPLIED ref {r} -> {cs.referenceResolution}");
|
|
}
|
|
}
|
|
else if (cs.uiScaleMode == UnityEngine.UI.CanvasScaler.ScaleMode.ConstantPixelSize)
|
|
{
|
|
// referenceResolution is ignored in this mode; scaleFactor is the only lever
|
|
if (WORLD_SCALE > 0f && System.Math.Abs(WORLD_SCALE - 1f) > 0.0001f)
|
|
{
|
|
float old = cs.scaleFactor;
|
|
cs.scaleFactor = WORLD_SCALE;
|
|
log.AppendLine($" APPLIED scaleFactor {old} -> {cs.scaleFactor}");
|
|
}
|
|
}
|
|
}
|
|
|
|
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}");
|
|
}
|
|
|
|
UnityExplorer.ExplorerCore.Log(log.ToString());
|