Unity3D 多平台 預編譯 宏定義


平台定義

UNITY_EDITOR 編輯器調用。

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或Linux)。

UNITY_WEBPLAYER 網頁播放器(包括Windows和Mac Web播放器可執行文件)。

UNITY_WII Wii游戲機平台。

UNITY_IPHONE iPhone平台。

UNITY_ANDROID Android平台。

UNITY_PS3 PlayStation 3。

UNITY_XBOX360 Xbox 360。

UNITY_NACL 谷歌原生客戶端(使用這個必須另外使用UNITY_WEBPLAYER)。

UNITY_FLASH Adobe Flash。

判斷Unity版本

也可以判斷Unity版本,目前支持的版本

UNITY_2_6 平台定義為主要版本的Unity 2.6。

UNITY_2_6_1 平台定義的特定版本1的主要版本2.6。

UNITY_3_0 平台定義為主要版本的Unity 3.0。

UNITY_3_0_0 平台定義的特定版本的Unity 3.0 0。

UNITY_3_1 平台定義為主要版本的Unity 3.1。

UNITY_3_2 平台定義為主要版本的Unity 3.2。

UNITY_3_3 平台定義為主要版本的Unity 3.3。

UNITY_3_4 平台定義為主要版本的Unity 3.4。

UNITY_3_5 平台定義為主要版本的Unity 3.5。

UNITY_4_0 平台定義為主要版本的Unity 4.0。

UNITY_4_0_1 主要版本4.0.1統一的平台定義。

UNITY_4_1 平台定義為主要版本的Unity 4.1。

UNITY_4_2 平台定義為主要版本的Unity 4.2。

運行平台

//獲得當前運行平台
   Debug.Log("plat = " + Application.platform);
 
//可以獲取到的平台類型  
   public enum RuntimePlatform  
    {  
        OSXEditor = 0,  
        OSXPlayer = 1,  
        WindowsPlayer = 2,  
        OSXWebPlayer = 3,  
        OSXDashboardPlayer = 4,  
        WindowsWebPlayer = 5,  
        WiiPlayer = 6,  
        WindowsEditor = 7,  
        IPhonePlayer = 8,  
        PS3 = 9,  
        XBOX360 = 10,  
        Android = 11,  
        NaCl = 12,  
        LinuxPlayer = 13,  
        FlashPlayer = 15,  
    }
 

示例

// JS
function Awake() {
  #if UNITY_EDITOR
    Debug.Log("Unity Editor");
  #endif

  #if UNITY_IPHONE
    Debug.Log("Iphone");
  #endif

  #if UNITY_STANDALONE_OSX
    Debug.Log("Stand Alone OSX");
  #endif

  #if UNITY_STANDALONE_WIN
    Debug.Log("Stand Alone Windows");
  #endif    
}


// C#
using UnityEngine;
using System.Collections;

public class PlatformDefines : MonoBehaviour {
  void Start () {

    #if UNITY_EDITOR
      Debug.Log("Unity Editor");
    #endif

    #if UNITY_IPHONE
      Debug.Log("Iphone");
    #endif

    #if UNITY_STANDALONE_OSX
    Debug.Log("Stand Alone OSX");
    #endif

    #if UNITY_STANDALONE_WIN
      Debug.Log("Stand Alone Windows");
    #endif

  }               
}


// Boo
import UnityEngine

class PlatformDefines (MonoBehaviour): 

    def Start ():
        ifdef UNITY_EDITOR:
            Debug.Log("Unity Editor")

        ifdef UNITY_IPHONE:
            Debug.Log("IPhone")

        ifdef UNITY_STANDALONE_OSX:
            Debug.Log("Stand Alone OSX")

        ifdef not UNITY_IPHONE:
            Debug.Log("not an iPhone")
 

文獻資料

API地址:http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM