1. 程式人生 > >Unity3D -- 平臺巨集定義

Unity3D -- 平臺巨集定義

本文章轉譯自官方文件

Property: Function:
UNITY_EDITOR Unity編輯器
UNITY_EDITOR_WIN Windows 作業系統.
UNITY_EDITOR_OSX macos作業系統
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_WII WII 遊戲機平臺
UNITY_IOS iOS系統平臺
UNITY_IPHONE iPhone
UNITY_ANDROID android系統平臺
UNITY_PS4 ps4平臺
UNITY_SAMSUNGTV 三星TV平臺
UNITY_XBOXONE Xbox One 平臺
UNITY_TIZEN Tizen 平臺
UNITY_TVOS Apple 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_WINRT UNITY_WSA.
UNITY_WINRT_10_0 UNITY_WSA_10_0
UNITY_WEBGL #define directive for WebGL.
UNITY_FACEBOOK faceBook平臺(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_5 unity5版本, 包含所有的5.x.y版本
UNITY_5_0 Unity5.0版本,包含所有的5.0.x版本
UNITY_5_0_1 Unity5.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