46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace TKS.OutGame
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 본문 높이 맞춤(PD #1100) — 부모가 기준 높이보다 낮으면(3:4 등) 같은 비율로 줄이고 가로는 부모를 꽉 채운다 · 높거나 같으면 부모와 같은 크기(기존 늘림과 같음).
|
||
|
|
/// </summary>
|
||
|
|
public class UiFitHeight : MonoBehaviour
|
||
|
|
{
|
||
|
|
public float designHeight = 1546f;
|
||
|
|
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);
|
||
|
|
rt.sizeDelta = s < 1f ? new Vector2(size.x / s, designHeight) : size;
|
||
|
|
rt.anchoredPosition = Vector2.zero;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|