Project_WL/Assets/Script/Util/SafeArea.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2024-12-15 01:39:39 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SafeArea : MonoBehaviour
{
public bool BaseIsLeft = true;
public float OffSet = 0f;
ScreenOrientation screenOrientation = ScreenOrientation.Portrait;
IEnumerator Start()
{
var rect = GetComponent<RectTransform>();
var originalPos = rect.anchoredPosition;
float Gap = Screen.height - Screen.safeArea.height;
while (true)
{
switch (Screen.orientation)
{
case ScreenOrientation.LandscapeLeft: // 노치가 왼쪽
if (screenOrientation != Screen.orientation)
{
screenOrientation = Screen.orientation;
if (BaseIsLeft)
rect.anchoredPosition = new Vector2(originalPos.x + OffSet + Gap, originalPos.y);
}
break;
case ScreenOrientation.LandscapeRight:
if (screenOrientation != Screen.orientation)
{
screenOrientation = Screen.orientation;
rect.anchoredPosition = originalPos;
}
break;
}
yield return null;
}
}
}