| 12345678910111213141516171819202122232425 |
- using UnityEngine;
- namespace DevilLink2.Presentation
- {
- [RequireComponent(typeof(RectTransform))]
- public sealed class SafeAreaAdapter : MonoBehaviour
- {
- private Rect previous; private Vector2Int previousSize;
- private void OnEnable() { Apply(); }
- private void Update()
- {
- if (previous != Screen.safeArea || previousSize.x != Screen.width || previousSize.y != Screen.height) Apply();
- }
- public void Apply()
- {
- if (Screen.width <= 0 || Screen.height <= 0) return;
- var safe = Screen.safeArea; var rect = (RectTransform)transform;
- rect.anchorMin = new Vector2(safe.xMin / Screen.width, safe.yMin / Screen.height);
- rect.anchorMax = new Vector2(safe.xMax / Screen.width, safe.yMax / Screen.height);
- rect.offsetMin = rect.offsetMax = Vector2.zero;
- previous = safe; previousSize = new Vector2Int(Screen.width, Screen.height);
- }
- }
- }
|