一、跨平臺宏定義
在Unity開發中,經常需要跨平臺操作,而Unity自帶了一些平臺宏定義如下:
名稱 | 描寫敘述 |
UNITY_EDITOR | Unity編輯器 |
UNITY_STANDALONE_OSX | 專門爲Mac OS(包括Universal,PPC和Intelarchitectures)平臺的定義 |
UNITY_DASHBOARD_WIDGET | Mac OS Dashboard widget (Mac OS儀表板小部件)。 |
UNITY_STANDALONE_WIN | Windows系統 |
UNITY_STANDALONE_LINUX | LINUX的獨立的應用程序 |
UNITY_STANDALONE | 獨立的平臺 (Mac, Windows or Linux). |
UNITY_WEBPLAYER | 網頁播放器(包括Windows和Mac Web播放器可執行文件)。 |
UNITY_WII | Wii遊戲機平臺。 |
UNITY_IPHONE | 蘋果系統 |
UNITY_ANDROID | 安卓系統 |
UNITY_PS3 | PlayStation 3 |
UNITY_XBOX360 | VBOX360系統 |
UNITY_NACL | 谷歌原生客戶端(使用這個必須另外使用UNITY_WEBPLAYER) |
二、使用方法
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
private string platform = string.Empty;
void Start () {
DebugPlatformMesaage();
//獲得當前運行平臺
Debug.Log("plat = " + Application.platform);
}
void DebugPlatformMesaage()
{
#if UNITY_EDITOR
platform ="hi,大家好,我是在unity編輯模式下";
#elif UNITY_XBOX360
platform="hi,大家好,我在XBOX360平臺";
#elif UNITY_IPHONE
platform="hi,大家好,我是IPHONE平臺";
#elif UNITY_ANDROID
platform="hi,大家好,我是ANDROID平臺";
#elif UNITY_STANDALONE_OSX
platform="hi,大家好,我是OSX平臺";
#elif UNITY_STANDALONE_WIN
platform="hi,大家好,我是Windows平臺";
#endif
Debug.Log("Current Platform:"+ platform);
}
}