SafeAreaTop.cs 460 B

12345678910111213141516171819
  1. using UnityEngine;
  2. namespace Plugins.CxShine.SafeArea
  3. {
  4. public class SafeAreaTop : MonoBehaviour
  5. {
  6. public void Start()
  7. {
  8. //计算屏幕顶部异形大小
  9. var safeAreaOffset = (int)(Screen.height - Screen.safeArea.yMax);
  10. //UI偏移
  11. var rectTransform = transform.GetComponent<RectTransform>();
  12. rectTransform.offsetMax = new Vector2(0, -safeAreaOffset / 2);
  13. }
  14. }
  15. }