Unity3d 平台宏定义

1.依赖于平台的编译

Unity包含一个“平台相关的编译”功能。这包括一些预处理指令,让你分割你的脚本编译和专为支持的平台之一执行代码段。

您可以Unity编辑器中运行代码,这样你就可以专门为你的目标平台编译代码,并在编辑器中测试!

2.Platform #define directives

The platform #define directives that Unity supports for your scripts are as follows:

Property:Function:
UNITY_EDITORdefine directive for calling Unity Editor scripts from your game code.
UNITY_EDITOR_WINdefine directive for Editor code on Windows.
UNITY_EDITOR_OSXdefine directive for Editor code on Mac OSX.
UNITY_STANDALONE_OSXdefine directive for compiling/executing code specifically for OS X (including Universal, PPC and Intel architectures).
UNITY_STANDALONE_WINdefine directive for compiling/executing code specifically for Windows standalone applications.
UNITY_STANDALONE_LINUXdefine directive for compiling/executing code specifically for Linux standalone applications.
UNITY_STANDALONEdefine directive for compiling/executing code for any standalone platform (OS X, Windows or Linux).
UNITY_WIIdefine directive for compiling/executing code for the Wii console.
UNITY_IOSdefine directive for compiling/executing code for the iOS platform.
UNITY_IPHONEDeprecated. Use UNITY_IOS instead.
UNITY_ANDROIDdefine directive for the Android platform.
UNITY_PS3define directive for running PlayStation 3 code.
UNITY_PS4define directive for running PlayStation 4 code.
UNITY_SAMSUNGTVdefine directive for executing Samsung TV code.
UNITY_XBOX360define directive for executing Xbox 360 code.
UNITY_XBOXONEdefine directive for executing Xbox One code.
UNITY_TIZENdefine directive for the Tizen platform.
UNITY_TVOSdefine directive for the Apple TV platform.
UNITY_WP_8define directive for Windows Phone 8.
UNITY_WP_8_1define directive for Windows Phone 8.1.
UNITY_WSAdefine directive for Windows Store Apps. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core.
UNITY_WSA_8_0define directive for Windows Store Apps when targeting SDK 8.0.
UNITY_WSA_8_1define directive for Windows Store Apps when targeting SDK 8.1.
UNITY_WSA_10_0define directive for Windows Store Apps when targeting Universal Windows 10 Apps. Additionally WINDOWS_UWP and NETFX_CORE are defined when compiling C# files against .NET Core.
UNITY_WINRTEquivalent to UNITY_WP_8 \ UNITY_WSA.
UNITY_WINRT_8_0Equivalent to UNITY_WP_8 \ UNITY_WSA_8_0.
UNITY_WINRT_8_1Equivalent to UNITY_WP_8_1 \ UNITY_WSA_8_1. This is also defined when compiling against Universal SDK 8.1.
UNITY_WINRT_10_0Equivalent to UNITY_WSA_10_0
UNITY_WEBGLdefine directive for WebGL.
UNITY_ADSdefine directive for calling Unity Ads methods from your game code. Version 5.2 and above.
UNITY_ANALYTICSdefine directive for calling Unity Analytics methods from your game code. Version 5.2 and above.
UNITY_ASSERTIONSdefine directive for assertions control process.

From Unity 2.6.0 onwards, you can compile code selectively. The options available depend on the version of the Editor that you are working on. Given a version number X.Y.Z (for example, 2.6.0), Unity exposes three global #define directives in the following formats: UNITY_X, UNITY_X_Y and UNITY_X_Y_Z.

Here is an example of #define directives exposed in Unity 5.0.1:

UNITY_5 | #define directive for the release version of Unity 5, exposed in every 5.X.Y release.
UNITY_5_0 | #define directive for the major version of Unity 5.0, exposed in every 5.0.Z release.
UNITY_5_0_1 | #define directive for the minor version of Unity 5.0.1.
You can compile code selectively based on the earliest version of Unity required to compile or execute a given portion of code. Given the same version format as above (X.Y.Z), Unity exposes one global #define directive that can be used for this purpose, in the format UNITY_X_Y_OR_NEWER.

The supported #define directives are:

UNITY_5_3_OR_NEWER Global #define directive exposed starting from Unity 5.3.
You can also compile code selectively depending on the scripting back-end.

ENABLE_MONO Scripting back-end #define directive for Mono.
ENABLE_IL2CPP Scripting back-end #define directive for IL2CPP.
ENABLE_DOTNET Scripting back-end #define directive for .NET.
You can also use the DEVELOPMENT_BUILD #define directive to identify whether your script is running in a player which was built with the “Development Build” option enabled.

参考资料:unity官方文档

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值