50 lines
2.0 KiB
C#
50 lines
2.0 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace TKS.OutGame
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 폭 맞춤 배경 그림이 세로로 긴 화면에서 아래가 비지 않게(PD 2026-11-26 「로비 화면 하단이 비어 보임」) — 부모(본문) 크기가 바뀔 때마다
|
|||
|
|
/// 배율 = max(기본 배율, 그림 top 줄 ~ 맨 아래 줄이 본문 높이를 덮는 배율) · 늘어난 몫은 좌우로 같이 잘림(가운데 기준) · 그림 위 장면(영웅 자리 · 연출)은 같이 커짐.
|
|||
|
|
/// 대상 RectTransform = 앵커 x 를 (−pad ~ 1+pad) 로 쓰는 폭 맞춤 그림(AspectRatioFitter WidthControlsHeight · 피벗 y = top 줄).
|
|||
|
|
/// </summary>
|
|||
|
|
public class UiArtCover : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
public float baseZoom = 1f;
|
|||
|
|
public float artW = 1080f;
|
|||
|
|
public float artH = 1920f;
|
|||
|
|
/// <summary>본문 맨 위에 오는 그림 줄(px).</summary>
|
|||
|
|
public float top;
|
|||
|
|
Vector2 last = new Vector2(-1f, -1f);
|
|||
|
|
|
|||
|
|
/// <summary>지금 배율(시험 · 캡처 로그).</summary>
|
|||
|
|
public float Zoom { get; private set; }
|
|||
|
|
|
|||
|
|
void OnEnable()
|
|||
|
|
{
|
|||
|
|
last = new Vector2(-1f, -1f);
|
|||
|
|
Apply();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void LateUpdate()
|
|||
|
|
{
|
|||
|
|
Apply();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Apply()
|
|||
|
|
{
|
|||
|
|
var rt = (RectTransform)transform;
|
|||
|
|
var parent = rt.parent as RectTransform;
|
|||
|
|
if (parent == null) return;
|
|||
|
|
var size = parent.rect.size;
|
|||
|
|
if (size == last || size.x <= 1f || size.y <= 1f) return;
|
|||
|
|
last = size;
|
|||
|
|
float below = Mathf.Max(1f, artH - top); // top 줄 아래 그림 높이(px)
|
|||
|
|
float need = size.y * artW / (below * size.x); // 이 배율이면 그림 아래끝 = 본문 아래끝
|
|||
|
|
Zoom = Mathf.Max(baseZoom, need);
|
|||
|
|
float pad = (Zoom - 1f) * 0.5f;
|
|||
|
|
rt.anchorMin = new Vector2(-pad, rt.anchorMin.y);
|
|||
|
|
rt.anchorMax = new Vector2(1f + pad, rt.anchorMax.y);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|