Unity平台判断

Unity 平台的判断包含编译时判断和运行时判断,总结如下:

编译时

    #if UNITY_EDITOR
      Debug.Log("Unity Editor");
    #endif

    #if UNITY_IOS
      Debug.Log("Iphone");
    #endif

    #if UNITY_STANDALONE_OSX
    Debug.Log("Stand Alone OSX");
    #endif

    #if UNITY_STANDALONE_WIN
      Debug.Log("Stand Alone Windows");
    #endif

可以使用||&&进行组合

平台定义

  • UNITY_EDITOR
  • UNITY_EDITOR_WIN
  • UNITY_EDITOR_OSX
  • UNITY_STANDALONE_OSX
  • UNITY_STANDALONE_WIN
  • UNITY_STANDALONE_LINUX
  • UNITY_STANDALONE
  • UNITY_WII
  • UNITY_IOS
  • UNITY_IPHONE
  • UNITY_ANDROID
  • UNITY_PS4
  • UNITY_SAMSUNGTV
  • UNITY_XBOXONE
  • UNITY_TIZEN
  • UNITY_TVOS
  • UNITY_WP_8_1
  • UNITY_WSA
  • UNITY_WSA_8_1
  • UNITY_WSA_10_0
  • UNITY_WINRT
  • UNITY_WINRT_8_1
  • UNITY_WINRT_10_0
  • UNITY_WEBGL
  • UNITY_ADS
  • UNITY_ANALYTICS
  • UNITY_ASSERTIONS

官方文档:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

运行时

if(Application.platform == RuntimePlatform.WindowsWebPlayer)
{
   Debug.Log("Windows Web Player");
}

平台枚举

  • OSXEditor
  • OSXPlayer
  • WindowsPlayer
  • OSXDashboardPlayer
  • WindowsEditor
  • IPhonePlayer
  • Android
  • LinuxPlayer
  • LinuxEditor
  • WebGLPlayer
  • WSAPlayerX86
  • WSAPlayerX64
  • WSAPlayerARM
  • TizenPlayer
  • PSP2
  • PS4
  • XboxOne
  • SamsungTVPlayer
  • WiiU
  • tvOS
  • Switch

官方文档:https://docs.unity3d.com/ScriptReference/RuntimePlatform.html

本文于2017-6-27发表在 https://wycode.cn/blog/unity-platform ,转载请注明出处。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值