Unity3D -- 平台宏定义

来源:互联网 发布:java免费发送短信插件 编辑:程序博客网 时间:2024/06/06 08:51

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

本文章转译自官方文档

Property:Function:UNITY_EDITORUnity编辑器UNITY_EDITOR_WINWindows 操作系统.UNITY_EDITOR_OSXmacos操作系统UNITY_STANDALONE_OSX专门为macos(包括Universal, PPC,Intel architectures)平台的定义UNITY_STANDALONE_WIN专门为windows平台的定义UNITY_STANDALONE_LINUX专门为Linux平台的定义UNITY_STANDALONE独立平台 (Mac OS X, Windows or Linux).UNITY_WIIWII 游戏机平台UNITY_IOSiOS系统平台UNITY_IPHONEiPhoneUNITY_ANDROIDandroid系统平台UNITY_PS4ps4平台UNITY_SAMSUNGTV三星TV平台UNITY_XBOXONEXbox One 平台UNITY_TIZENTizen 平台UNITY_TVOSApple TV 平台UNITY_WSA#define directive for Universal Windows Platform. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend.UNITY_WSA_10_0#define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.UNITY_WINRTUNITY_WSA.UNITY_WINRT_10_0UNITY_WSA_10_0UNITY_WEBGL#define directive for WebGL.UNITY_FACEBOOKfaceBook平台(WebGL or Windows standalone).UNITY_ADS调用广告方法,版本 5.2 以后UNITY_ANALYTICS调用unity分析服务,版本5.2以后UNITY_ASSERTIONS控制指令的过程Unity版本判定方式:UNITY_X,UNITY_X_Y,UNITY_X_Y_Z 例如:

  UNITY_5unity5版本, 包含所有的5.x.y版本UNITY_5_0Unity5.0版本,包含所有的5.0.x版本UNITY_5_0_1Unity5.0.1版本打包的时候,选择File > Build Settings然后显示平台选择界面.



代码实例C#

// C#using UnityEngine;using System.Collections;public class PlatformDefines : MonoBehaviour {  void Start () {    #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  }          }

可以使用#if #elif

#if UNITY_EDITOR    Debug.Log("Unity Editor");#elif UNITY_IOS    Debug.Log("Unity iPhone");#else    Debug.Log("Any other platform");#endif
可以自定义宏定义,打开Other Settings窗口,选择Player Settings > Scripting Define Symbols

原创粉丝点击