Unity宏定义重构修改

大城市里の小女人 提交于 2019-12-14 06:13:42

using UnityEngine;
public class Platformtool
{
    public static bool IsAndroid
    {
        get
        {
            bool retValue = false;
#if UNITY_ANDROID
                retValue = true;    
#endif
            return retValue;
        }
    }

    public static bool IsEditor
    {
        get
        {
            bool retValue = false;
#if UNITY_EDITOR
            retValue = true;
#endif
            return retValue;
        }
    }

    public static bool IsIOSiPhone    
    {
        get
        {
            bool retValue = false;
#if UNITY_IOS
            if ((float)Screen.width / (float)Screen.height >= 1.5f)
            {
                retValue = true;
            }
            else
            {
                retValue = false;
            }  
#endif
            return retValue;
        }
    }
    public static bool IsiOSIpad
    {
        get
        {
            bool retValue = false;
#if UNITY_IOS
            if ((float)Screen.width / (float)Screen.height >= 1.5f)
            {
                retValue = false;
            }
            else
            {
                retValue = true;
            } 
#endif
            return retValue;
        }
    }
    public static bool IsWEB
    {
        get
        {
            bool retValue = false;
#if UNITY_WEBGL
            retValue = true;    
#endif
            return retValue;
        }
    }
    public static bool IsPad()
    {
        string type = SystemInfo.deviceModel.ToLower().Trim();
        Debug.Log(type);
        if (type.Substring(0, 3) == "iph")
        {//iPhone机型
            return false;
        }
        else if (type.Substring(0, 3) == "ipa")
        {//iPad机型
            return true;
        }
        else
        {//其他
            return false;
        }

    }
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!