美文网首页
Unity平台判断

Unity平台判断

作者: 王郁 | 来源:发表于2023-11-11 01:22 被阅读0次

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 ,转载请注明出处。

相关文章

网友评论

      本文标题:Unity平台判断

      本文链接:https://www.haomeiwen.com/subject/ogekwdtx.html