31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace TKS
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 늘어나는 칸(부모를 채우는 RectTransform)의 폭이 바뀌는 순간 자기 배율을 다시 맞춘다 — 배율 = min(1, (폭 − 오른쪽 비움 − 간격) ÷ 설계 폭).
|
|||
|
|
/// 전투 하단 정보판 왼쪽 묶음이 좁은 화면(캔버스 폭 978)에서 오른쪽 스킬 열과 안 겹치게(PD 2026-11-21 「여백이 남지 않도록 능력치 · 패시브를 키워」).
|
|||
|
|
/// 매 프레임 계산하면 캡처처럼 화면 크기를 바꾼 그 프레임에 늦으므로 크기 바뀜 알림에서 계산한다.
|
|||
|
|
/// </summary>
|
|||
|
|
public class UiFitScale : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public float reserveRight; // 오른쪽에 비워 둘 폭(스킬 열)
|
|||
|
|
public float gap; // 간격
|
|||
|
|
public float designWidth; // 왼쪽 묶음 오른끝(설계 1080 기준)
|
|||
|
|
|
|||
|
|
RectTransform rt;
|
|||
|
|
|
|||
|
|
void OnEnable() { Apply(); }
|
|||
|
|
|
|||
|
|
void OnRectTransformDimensionsChange() { Apply(); }
|
|||
|
|
|
|||
|
|
public void Apply()
|
|||
|
|
{
|
|||
|
|
if (rt == null) rt = transform as RectTransform;
|
|||
|
|
if (rt == null || designWidth <= 0f) return;
|
|||
|
|
float s = Mathf.Clamp01((rt.rect.width - reserveRight - gap) / designWidth);
|
|||
|
|
if (Mathf.Abs(rt.localScale.x - s) > 0.0005f) rt.localScale = new Vector3(s, s, 1f);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|