您当前的位置: 首页 >  unity

unity工具人

暂无认证

  • 2浏览

    0关注

    205博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity平台区分

unity工具人 发布时间:2021-04-18 00:11:20 ,浏览量:2

这里就介绍几种常见的,也是便于使用的几种平台判断的方法。

1.先说第一种,也是我用的顺手的一个。利用RuntimePlatform判断,API上的解释是[The platform application is running. Returned by Application.platform.]

举个栗子:

if (Application.platform == RuntimePlatform.WindowsEditor)  { }

一般常用的是三个平台,安卓[Android],苹果[IphonePlayer],Unity编辑器[WindowsEditor]。

2.在编辑器中的平台依赖编译[Platform Dependent Compilation],可以使用if…else…对不同平台的代码进行区分。

 void Start()
    {
#if UNITY_EDITOR
        Debug.Log("这是编辑器模式。。。");
#endif
#if !UNITY_EDITOR
        Debug.Log("这不是编辑器模式。。。");
#endif
#if UNITY_ANDROID
        Debug.Log("这是安卓平台。。。");
#endif
#if UNITY_IPHONE
        Debug.Log("这是iPhone平台。。。"); // 不好听,用IOS代替
#endif
#if UNITY_IOS
        Debug.Log("这是IOS平台。。。");
#endif
#if UNITY_STANDALONE_WIN
        Debug.Log("这是Windows平台。。。");
#endif
#if UNITY_STANDALONE_OSX
    Debug.Log("这是OSX平台。。。");
#endif
    }

3.在编译后生效。

 if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            Debug.Log("这是Windows编辑器模式。。。");
        }
        if (Application.platform == RuntimePlatform.IPhonePlayer) // 使用Unity切换Platform无法模拟
        {
            Debug.Log("这是iPhone平台。。。");
        }
        if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
        {
            Debug.Log("这是安卓平台。。。");
        }

最后,贴出官网的API,具体的平台在官网上都有介绍,官网地址:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

关注
打赏
1656671177
查看更多评论
立即登录/注册

微信扫码登录

0.0467s