using UnityEngine; namespace TKS.OutGame { /// /// 본문 높이 맞춤(PD #1100) — 부모가 기준 높이보다 낮으면(3:4 등) 같은 비율로 줄이고 가로는 부모를 꽉 채운다 · 높거나 같으면 부모와 같은 크기(기존 늘림과 같음). /// public class UiFitHeight : MonoBehaviour { public float designHeight = 1546f; /// 폭 상한(0 = 부모 폭 그대로) — 목업 좌표(왼쪽 기준)로 배치한 화면이 태블릿에서 왼쪽에 붙지 않게 가운데 1080(PD 2026-11-26 해상도 대응). public float maxWidth; Vector2 last = new Vector2(-1f, -1f); void OnEnable() { last = new Vector2(-1f, -1f); Apply(); } void Update() { Apply(); } public float Scale { get { return transform.localScale.x; } } void Apply() { var rt = (RectTransform)transform; var parent = rt.parent as RectTransform; if (parent == null || designHeight <= 0f) return; var size = parent.rect.size; if (size == last || size.y <= 0f) return; last = size; float s = Mathf.Min(1f, size.y / designHeight); rt.anchorMin = rt.anchorMax = new Vector2(0.5f, 1f); rt.pivot = new Vector2(0.5f, 1f); rt.localScale = new Vector3(s, s, 1f); float w = s < 1f ? size.x / s : size.x; if (maxWidth > 0f) w = Mathf.Min(w, maxWidth); // 넓은 화면(태블릿) = 기준 폭으로 가운데(왼쪽 붙음 방지 · 2026-11-26) rt.sizeDelta = s < 1f ? new Vector2(w, designHeight) : new Vector2(w, size.y); rt.anchoredPosition = Vector2.zero; } } }