Unity中判断平台的三种方法

方法一:使用宏命令

方法二:使用RuntimePlatform枚举去判断平台

方法三:使用Application中API

一,宏命令

#if UNITY_EDITOR
        //编辑器
#elif UNITY_WINDOW
        //电脑平台
#elif UNITY_ANDROID
        //安卓平台
#elif UNITY_IOS
        //苹果平台
#endif

二,使用Application中API

RuntimePlatform platform = Application.platform;

枚举值:

        OSXEditor = 0,
        //
        // 摘要:
        //     In the player on macOS.
        OSXPlayer = 1,
        //
        // 摘要:
        //     In the player on Windows.
        WindowsPlayer = 2,
        //
        // 摘要:
        //     In the web player on macOS.
        OSXWebPlayer = 3,
        //
        // 摘要:
        //     In the Dashboard widget on macOS.
        OSXDashboardPlayer = 4,
        //
        // 摘要:
        //     In the web player on Windows.
        WindowsWebPlayer = 5,
        //
        // 摘要:
        //     In the Unity editor on Windows.
        WindowsEditor = 7,
        //
        // 摘要:
        //     In the player on the iPhone.
        IPhonePlayer = 8,
        PS3 = 9,
        XBOX360 = 10,
        //
        // 摘要:
        //     In the player on Android devices.
        Android = 11,
        NaCl = 12,
        //
        // 摘要:
        //     In the player on Linux.
        LinuxPlayer = 13,
        FlashPlayer = 15,
        //
        // 摘要:
        //     In the Unity editor on Linux.
        LinuxEditor = 16,
        //
        // 摘要:
        //     In the player on WebGL
        WebGLPlayer = 17,
        MetroPlayerX86 = 18,
        //
        // 摘要:
        //     In the player on Windows Store Apps when CPU architecture is X86.
        WSAPlayerX86 = 18,
        MetroPlayerX64 = 19,
        //
        // 摘要:
        //     In the player on Windows Store Apps when CPU architecture is X64.
        WSAPlayerX64 = 19,
        MetroPlayerARM = 20,
        //
        // 摘要:
        //     In the player on Windows Store Apps when CPU architecture is ARM.
        WSAPlayerARM = 20,
        WP8Player = 21,
        BB10Player = 22,
        BlackBerryPlayer = 22,
        TizenPlayer = 23,
        //
        // 摘要:
        //     In the player on the PS Vita.
        PSP2 = 24,
        //
        // 摘要:
        //     In the player on the Playstation 4.
        PS4 = 25,
        PSM = 26,
        //
        // 摘要:
        //     In the player on Xbox One.
        XboxOne = 27,
        SamsungTVPlayer = 28,
        //
        // 摘要:
        //     In the player on Wii U.
        WiiU = 30,
        //
        // 摘要:
        //     In the player on the Apple's tvOS.
        tvOS = 31,
        //
        // 摘要:
        //     In the player on Nintendo Switch.
        Switch = 32

三,使用Application中API

bool platform= Application.isEditor;//是否是编辑器状态
platform = Application.isMobilePlatform;//是否是移动平台

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值