[游戏开发][Unity]宏定义的使用

平台判定的几种写法

第一种#if 与#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

第二种 #if #else #endif写法 ,支持逻辑运算符!

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

第三种 #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#代码判定平台

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");
    }
}

Unity支持的平台#define指令如下:

属性:

功能:

UNITY_EDITOR

从游戏代码调用Unity编辑器脚本的#define指令。

UNITY_EDITOR_WIN

Windows上编辑器代码的#define指令。

UNITY_EDITOR_OSX

Mac OS X上编辑器代码的#define指令

UNITY_STANDALONE_OSX

#define伪指令,专门用于编译/执行Mac OS X(包括Universal,PPC和Intel体系结构)的代码。

UNITY_STANDALONE_WIN

#define指令,用于编译/执行专门针对Windows独立应用程序的代码。

UNITY_STANDALONE_LINUX

#define指令,用于编译/执行专门针对Linux独立应用程序的代码。

UNITY_STANDALONE

#define伪指令,用于编译/执行任何独立平台(Mac OS X,Windows或Linux)的代码。

UNITY_WII

编译/执行Wii控制台代码的#define指令。

UNITY_IOS

编译/执行iOS平台代码的#define指令。

UNITY_IPHONE

已过时。改用UNITY_IOS。

UNITY_ANDROID

Android平台的#define指令。

UNITY_PS4

运行PlayStation 4代码的#define指令。

UNITY_SAMSUNGTV

执行三星电视代码的#define指令。

UNITY_XBOXONE

执行Xbox One代码的#define指令。

UNITY_TIZEN

Tizen平台的#define指令。

UNITY_TVOS

Apple TV平台的#define指令。

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指令。


自定义宏

猜你喜欢

转载自blog.csdn.net/liuyongjie1992/article/details/131435790
今日推荐