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>
This commit is contained in:
+12
-6
@@ -10,9 +10,11 @@
|
||||
|
||||
// ---- KNOBS -----------------------------------------------------------------
|
||||
float MATCH = 1.0f; // 0 = scale by width, 1 = scale by height
|
||||
float SCALE_MULT = 1.0f; // extra multiplier on top (0.9 = 10% smaller HUD)
|
||||
float REF_W = 0f; // 0 = leave reference resolution alone
|
||||
float REF_H = 0f; // e.g. set 3840/1080 to design against ultrawide
|
||||
// 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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -27,10 +29,14 @@ foreach (var cs in UnityEngine.Object.FindObjectsOfType<UnityEngine.UI.CanvasSca
|
||||
|
||||
if (!LIST_ONLY)
|
||||
{
|
||||
if (REF_W > 0 && REF_H > 0)
|
||||
cs.referenceResolution = new UnityEngine.Vector2(REF_W, REF_H);
|
||||
cs.matchWidthOrHeight = MATCH;
|
||||
cs.scaleFactor = SCALE_MULT;
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user