Unity_平台的预处理

在开发中,特别是unity的跨平台中,我们常常会在各个平台游走,如安卓版,苹果版,PC版……。在此不同的平台上,有可能我们须要做不同的操作。然而我们就能够用unity的自带的平台宏定义方式来做平台的推断。Unity帮我们定义了例如以下平台预处理:

名称描写叙述
UNITY_EDITORDefine for calling Unity Editor scripts from your game code.定义从您的游戏代码中调用Unity编辑器脚本。
UNITY_STANDALONE_OSXPlatform define for compiling/executing code specifically for Mac OS (This includes Universal, PPC and Intel architectures).平台定义为Mac OS(包括通用、PPC和Intel架构)的编译/执行代码。
UNITY_DASHBOARD_WIDGETPlatform define when creating code for Mac OS dashboard widgets.在为Mac OS仪表板小部件创建代码时,平台定义了。
UNITY_STANDALONE_WINUse this when you want to compile/execute code for Windows stand alone applications.当您想要为Windows独立应用程序编译/执行代码时,请使用它。
UNITY_STANDALONE_LINUXUse this when you want to compile/execute code for Linux stand alone applications.当您想要为Linux独立应用程序编译/执行代码时,请使用它。
UNITY_STANDALONEUse this to compile/execute code for any standalone platform (Mac, Windows or Linux).使用这个来为任何独立的平台(Mac、Windows或Linux)编译/执行代码。
UNITY_WEBPLAYERPlatform define for web player content (this includes Windows and Mac Web player executables).平台定义了Web播放器内容(包括Windows和Mac Web播放器可执行程序)。
UNITY_WIIPlatform define for compiling/executing code for the Wii console.平台定义了Wii控制台的编译/执行代码。
UNITY_IPHONEPlatform define for compiling/executing code for the iPhone platform.平台定义了iPhone平台的编译/执行代码。
UNITY_ANDROIDPlatform define for the Android platform.平台为Android平台定义。
UNITY_PS3Platform define for running PlayStation 3 code.平台定义了运行PlayStation 3代码。
UNITY_XBOX360Platform define for executing Xbox 360 code.平台定义用于执行xbox360代码。
UNITY_NACLPlatform define when compiling code for Google native client (this will be set additionally to UNITY_WEBPLAYER).平台在为Google native client编译代码时定义(这将被设置为unitywebplayer)。
UNITY_FLASHPlatform define when compiling code for Adobe Flash.平台在为Adobe Flash编译代码时定义。

以后我们能够依据如上宏定义就能够去轻而易举的非常easy去在我们代码中增加推断了。我举个简单样例,例如以下:

    using UnityEngine;  
    using System.Collections;  

    public class Test : MonoBehaviour  
    {  

        private string platform = string.Empty;  
        // Use this for initialization  
        void Start()  
        {  
            DebugPlatformMesaage();  
        }  

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

上面假设我是在Editor状态下的话,就能看见打印出:
这里写图片描述
我们也能够自定义宏定义,在PlayerSetting中定义:这就是预编译手段喽。。
这里写图片描述

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

版本号描写叙述
UNITY_2_6Platform define for the major version of Unity 2.6.
UNITY_2_6_1Platform define for specific version 1 from the major release 2.6.
UNITY_3_0Platform define for the major version of Unity 3.0.
UNITY_3_0_0Platform define for the specific version 0 of Unity 3.0.
UNITY_3_1Platform define for major version of Unity 3.1.
UNITY_3_2Platform define for major version of Unity 3.2.
UNITY_3_3Platform define for major version of Unity 3.3.
UNITY_3_4Platform define for major version of Unity 3.4.
UNITY_3_5Platform define for major version of Unity 3.5.
UNITY_4_0Platform define for major version of Unity 4.0.
UNITY_4_0_1Platform define for major version of Unity 4.0.1.
UNITY_4_1Platform define for major version of Unity 4.1.
UNITY_4_2Platform define for major version of Unity 4.2.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值