因为手机屏幕长宽比,以及是否是刘海屏,需要检测设配型号,这里帖上代码,占个坑。
using UnityEngine;
public class DeviceInfo
{
/// <summary>
/// 获取设备型号
/// </summary>
/// <returns></returns>
public static string CurrentDeviceModel()
{
return SystemInfo.deviceModel; // hardware strings
}
/// <summary>
/// 通过设备型号判断该设备是不是异形屏幕(带刘海),如果是则返回true
/// </summary>
/// <returns></returns>
public static bool Flag_ExternScreen()
{
if (CurrentDeviceModel().CompareTo("iPhone10,3") == 0 ||
CurrentDeviceModel().CompareTo("iPhone10,6") == 0 ||
CurrentDeviceModel().CompareTo("vivo vivo Y85A") == 0
)
{
return true;
}
return false;
}
/// <summary>
/// 获取设备的屏幕比例(高宽比)
/// </summary>
/// <returns></returns>
public static int CurrentScreenRatio()
{
float ss = (Screen.height * 1.0f) / Screen.width;
//Debug.Log((int)(ss * 100));
return (int)(ss * 100);
}
}