[Game Development][Unity]The use of macro definitions

Several Ways of Writing Platform Judgment

The first way of writing #if and #endif

//Android平台
#if UNITY_ANDROID
   Debug.Log("Android");
#endif
//苹果平台
#if UNITY_IPHONE
    Debug.Log("IOS");
#endif
//Windows平台
#if UNITY_STANDALONE_WIN
    Debug.Log("Windows");
#endif

The second #if #else #endif writing method supports logical operators!

// #if !UNITY_EDITOR逻辑运算符!同样适用
#if UNITY_EDITOR    
    const string GAMEDLL = "__Internal";
#else
    const string GAMEDLL = "gamed";
#endif

The third way of writing #if #elif #endif

#if UNITY_EDITOR 
    const string GAMEDLL = "Editor";
#elif UNITY_IPHONE
    const string GAMEDLL = "IOS";
#elif UNITY_ANDROID
    const string GAMEDLL = "Android";
#endif

C# code judgment platform

if (Application.platform == RuntimePlatform.Android)
    {
        Debug.Log("Android");
    }else if(Application.platform == RuntimePlatform.IPhonePlayer)
    {
        Debug.Log("IOS");
    }
    else if (Application.platform == RuntimePlatform.WindowsEditor)
    {
        Debug.Log("Window");
    }
}

The platforms supported by Unity #define directives are as follows:

Attributes:

Function:

UNITY_EDITOR

#define directive for calling Unity editor scripts from game code.

UNITY_EDITOR_WIN

#define directive for editor code on Windows.

UNITY_EDITOR_OSX

#define directives for editor code on Mac OS X

UNITY_STANDALONE_OSX

#define directive specifically for compiling/executing code for Mac OS X (including Universal, PPC and Intel architectures).

UNITY_STANDALONE_WIN

#define directive for compiling/executing code specifically for Windows standalone applications.

UNITY_STANDALONE_LINUX

#define directive for compiling/executing code specifically for Linux standalone applications.

UNITY_STANDALONE

#define directive for compiling/executing code for any independent platform (Mac OS X, Windows or Linux).

UNITY_WII

Compile/execute #define directives for Wii console code.

UNITY_IOS

#define directive for compiling/executing iOS platform code.

UNITY_IPHONE

obsolete. Use UNITY_IOS instead.

UNITY_ANDROID

The #define directive for the Android platform.

UNITY_PS4

#define directive to run PlayStation 4 code.

UNITY_SAMSUNGTV

Execute the #define directive of the Samsung TV code.

UNITY_XBOXONE

A #define directive that executes Xbox One code.

UNITY_TIZEN

The #define directive for the Tizen platform.

UNITY_TVOS

The #define directive for the Apple TV platform.

UNITY_WSA

通用Windows平台的#define指令。此外,NETFX_CORE是在针对.NET Core编译C#文件并使用.NET脚本后端时定义的。

UNITY_WSA_10_0

通用Windows平台的#define指令。另外,WINDOWS_UWP是在针对.NET Core编译C#文件时定义的。

UNITY_WINRT

与UNITY_WSA相同。

UNITY_WINRT_10_0

相当于UNITY_WSA_10_0

UNITY_WEBGL

WebGL的#define指令。

UNITY_FACEBOOK

Facebook平台的#define指令(WebGL或Windows独立版)。

UNITY_ADS

从游戏代码调用Unity Ads方法的#define指令。版本5.2及以上。

UNITY_ANALYTICS

从游戏代码调用Unity Analytics方法的#define指令。版本5.2及以上。

UNITY_ASSERTIONS

断言控制过程的#define指令。


自定义宏

Guess you like

Origin blog.csdn.net/liuyongjie1992/article/details/131435790