1.屏幕宽高比判断
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace QFramework
{
public class JudgeScreenWidthAndHeight : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("QFramework/9.屏幕宽高比判断")]
#endif
private static void MenuClicked()
{
var isLandscape = Screen.width > Screen.height;
float aspect;
if (isLandscape)
{
aspect = (float)Screen.width / Screen.height;
}
else
{
aspect = (float)Screen.height / Screen.width;
}
Debug.Log(aspect);
Debug.Log("宽:" + Screen.width + "高:" + Screen.height);
Debug.Log(isLandscape ? "横屏" : "竖屏");
}
}
}
2.判断屏幕是否是IPad分辨率
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
namespace QFramework
{
public class JudgeScreenWidthAndHeight : MonoBehaviour
{
#if UNITY_EDITOR
[MenuItem("QFramework/9.屏幕宽高比判断")]
#endif
private static void MenuClicked()
{
Debug.Log(IsPad() ? "是IPad分辨率" : "不是IPad分辨率");
}
public static float ScreenAspect()//屏幕分辨率
{
return Screen.width > Screen.height ? (float)Screen.width / Screen.height : (float)Screen.height / Screen.width;
}
public static bool IsPad()
{
float aspect = ScreenAspect();
return aspect > (4.0f / 3 - 0.05) && aspect < (4.0f / 3 + 0.05);
}
}
}