using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BF { public class SafeAreaManager { // public const string NOTCH_SCREEN_SIMULATE = "NOTCH_SCREEN_SIMULATE"; private static SafeAreaManager instance; public static SafeAreaManager Instance { get { if (instance == null) { instance = new SafeAreaManager(); } return instance; } } /// /// 是否开启模拟模式 /// /// // public static bool CheckIfSimulate () { // return PlayerPrefs.GetInt ("NOTCH_SCREEN_SIMULATE", 0) == 1; // } /// /// 得到安全区域 /// /// public static Rect GetSafeArea () { // 当前屏幕尺寸 float screenWidth = Screen.width; float screenHeight = Screen.height; #if UNITY_EDITOR return Screen.safeArea; #elif UNITY_IPHONE return Screen.safeArea; #elif UNITY_ANDROID // 安卓直接用SDK方法 不使用SafeArea return new Rect (0, 0, screenWidth, screenHeight); #else return new Rect (0, 0, screenWidth, screenHeight); #endif } /// /// 得到竖屏时的刘海高度 /// /// public static float GetNotchScreenHeight() { Rect rect = GetSafeArea (); #if UNITY_EDITOR return Screen.height - rect.height - rect.y; #elif UNITY_ANDROID float height = Screen.height - rect.height - rect.y; if (height > 0) { return height; } else { return BFMain.Instance.SDKMgr.GetNotchScreenHeight(); } #else return Screen.height - rect.height - rect.y; #endif } } }