Unity平台的预处理

Unity平台的预处理

在开发中,特别是unity的跨平台中,我们常常会在各个平台游走,如安卓版,苹果版,PC版......。在此不同的平台上,有可能我们须要做不同的操作。

然而我们就能够用unity的自带的平台宏定义方式来做平台的推断。


Unity帮我们定义了例如以下平台预处理:

名称

 描写叙述

UNITY_EDITOR

Unity编辑器

UNITY_STANDALONE_OSX

专门为Mac OS(包括UniversalPPCIntelarchitectures)平台的定义

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

网页播放器(包括WindowsMac Web播放器可执行文件)。

UNITY_WII

Wii游戏机平台。

UNITY_IPHONE

苹果系统

UNITY_ANDROID

安卓系统

UNITY_PS3

PlayStation 3

UNITY_XBOX360

VBOX360系统

UNITY_NACL

谷歌原生客户端(使用这个必须另外使用UNITY_WEBPLAYER

UNITY_FLASH

Adobe Flash

 

1.   using UnityEngine; 
2.   using System.Collections; 
3.     
4.   publicclassRecompile:MonoBehaviour 
5.   {    
6.       privatestring platform =string.Empty; 
7.       // Use this for initialization 
8.       voidStart() 
9.       { 
10.          DebugPlatformMesaage(); 
11.      } 
12.      voidDebugPlatformMesaage() 
13.      { 
14.   
15.  #ifUNITY_EDITOR 
16.          platform ="hi,大家好,我是在unity编辑模式下"; 
17.  #elifUNITY_XBOX360 
18.         platform="hi,大家好,我在XBOX360平台"; 
19.  #elifUNITY_IPHONE 
20.         platform="hi,大家好,我是IPHONE平台"; 
21.  #elifUNITY_ANDROID 
22.         platform="hi,大家好,我是ANDROID平台"; 
23.  #elifUNITY_STANDALONE_OSX 
24.         platform="hi,大家好,我是OSX平台"; 
25.  #elifUNITY_STANDALONE_WIN 
26.         platform="hi,大家好,我是Windows平台"; 
27.  #endif 
28.          Debug.Log("CurrentPlatform:"+ platform); 
29.      } 
30.  } 
 

上面假设我是在Editor状态下的话,就能看见打印出:

 我们也能够自定义宏定义,在PlayerSetting中定义:

 比如我在上面圈起来的地方填写一个CUSTOM_ITF这个预编译指令。然后在DebugPlatformMesaage函数尾部增加这句话:

 

1.  //新加入的内容 

2.  #if CUSTOM_ITF 

3.          customMsg ="我自己定义了预编译"; 

4.  #endif 

5.          Debug.Log(customMsg); 

 

然后我们执行看下,你就能在控制台看见我们输出的信息了:

 

除了这些,unity中还有各个版本号的宏定义,一般开发插件的大牛都会用到。

 

 

UNITY_2_6

Platform define for the major version of Unity 2.6.

UNITY_2_6_1

Platform define for specific version 1 from the major release 2.6.

UNITY_3_0

Platform define for the major version of Unity 3.0.

UNITY_3_0_0

Platform define for the specific version 0 of Unity 3.0.

UNITY_3_1

Platform define for major version of Unity 3.1.

UNITY_3_2

Platform define for major version of Unity 3.2.

UNITY_3_3

Platform define for major version of Unity 3.3.

UNITY_3_4

Platform define for major version of Unity 3.4.

UNITY_3_5

Platform define for major version of Unity 3.5.

UNITY_4_0

Platform define for major version of Unity 4.0.

UNITY_4_0_1

Platform define for major version of Unity 4.0.1.

UNITY_4_1

Platform define for major version of Unity 4.1.

UNITY_4_2

Platform define for major version of Unity 4.2.

 

 

补充:

1/ 获得当前运行平台

1.  //获得当前运行平台

2.     Debug.Log("plat ="+Application.platform);

1.  //可以获取到的平台类型 

2.     publicenumRuntimePlatform 

3.      { 

4.          OSXEditor=0, 

5.          OSXPlayer=1, 

6.          WindowsPlayer=2, 

7.          OSXWebPlayer=3, 

8.          OSXDashboardPlayer=4, 

9.          WindowsWebPlayer=5, 

10.          WiiPlayer=6, 

11.          WindowsEditor=7, 

12.          IPhonePlayer=8, 

13.          PS3 =9, 

14.          XBOX360 =10, 

15.          Android=11, 

16.          NaCl=12, 

17.          LinuxPlayer=13, 

18.          FlashPlayer=15, 

19.      }

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值