Unity平台判断

2023-11-11  本文已影响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

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

平台定义

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

运行时

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

平台枚举

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

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

上一篇 下一篇

猜你喜欢

热点阅读