| 123456789101112131415161718192021 |
- using UnityEngine;
- namespace DiamondArrow
- {
- public sealed class SafeCanvas : MonoBehaviour
- {
- public RectTransform content;
- void LateUpdate() { Apply(); }
- public void Apply()
- {
- if (!content) return;
- var area = Screen.safeArea;
- if (area.width <= 0 || area.height <= 0) return;
- float canvasScale = Mathf.Max(.001f, GetComponent<Canvas>().scaleFactor);
- float fit = Mathf.Min(area.width / 750f, area.height / 1334f);
- content.sizeDelta = area.size / fit;
- content.localScale = Vector3.one * (fit / canvasScale);
- content.anchoredPosition = (area.center - new Vector2(Screen.width, Screen.height) * .5f) / canvasScale;
- }
- }
- }
|