41 lines
743 B
C#
41 lines
743 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SafeArea : MonoBehaviour
|
|
{
|
|
Vector2 minAnchor;
|
|
Vector2 maxAnchor;
|
|
|
|
|
|
private void Start()
|
|
{
|
|
var Myrect = this.GetComponent<RectTransform>();
|
|
|
|
minAnchor = Screen.safeArea.min;
|
|
maxAnchor = Screen.safeArea.max;
|
|
|
|
minAnchor.x /= Screen.width;
|
|
minAnchor.y /= Screen.height;
|
|
|
|
maxAnchor.x /= Screen.width;
|
|
maxAnchor.y /= Screen.height;
|
|
|
|
|
|
Myrect.anchorMin = minAnchor;
|
|
Myrect.anchorMax = maxAnchor;
|
|
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (minAnchor != Screen.safeArea.min || maxAnchor != Screen.safeArea.max)
|
|
{
|
|
Start();
|
|
}
|
|
}
|
|
|
|
|
|
}
|