网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

[unity3d]unity平台的预处理-创新互联

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

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都做网站、网站设计、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的西充网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

 名称 描述
UNITY_EDITORDefine for calling Unity Editor scripts from your game code.
UNITY_STANDALONE_OSXPlatform define for compiling/executing code specifically for Mac OS (This includes Universal, PPC and Intel architectures).
UNITY_DASHBOARD_WIDGETPlatform define when creating code for Mac OS dashboard widgets.
UNITY_STANDALONE_WINUse this when you want to compile/execute code for Windows stand alone applications.
UNITY_STANDALONE_LINUXUse this when you want to compile/execute code for Linux stand alone applications.
UNITY_STANDALONEUse this to compile/execute code for any standalone platform (Mac, Windows or Linux).
UNITY_WEBPLAYERPlatform define for web player content (this includes Windows and Mac Web player executables).
UNITY_WIIPlatform define for compiling/executing code for the Wii console.
UNITY_IPHONEPlatform define for compiling/executing code for the iPhone platform.
UNITY_ANDROIDPlatform define for the Android platform.
UNITY_PS3Platform define for running PlayStation 3 code.
UNITY_XBOX360Platform define for executing Xbox 360 code.
UNITY_NACLPlatform define when compiling code for Google native client (this will be set additionally to UNITY_WEBPLAYER).
UNITY_FLASHPlatform define when compiling code for Adobe Flash.

  以后我们可以根据如上宏定义就可以去轻而易举的很容易去在我们代码中加入判断了。我举个简单例子,如下:

using UnityEngine; using System.Collections;  public class Recompile : 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状态下的话,就能看见打印出:    [unity3d]unity平台的预处理

我们也可以自己定义宏定义,在PlayerSetting中定义:

[unity3d]unity平台的预处理

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

//新添加的内容 #if CUSTOM_ITF         customMsg = "我自定义了预编译"; #endif         Debug.Log(customMsg);

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

[unity3d]unity平台的预处理

  当我们把我们自定义的宏定义给去掉的时候,我们打印的信息就不会出来。

除了这些,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.

其实预编译在我们对unity开发的时候还有一个很好的作用,我们Debug的时候是IO,其实会消耗CPU的,从而影响了我们的性能,我们想在开发的时候进行Debug,但不想在到处的时候打印出,在这个时候我们就可以用预编译来判断他是否是在Editor状态下,从而做出相应的操作!
预处理命令从来不会被翻译为可执行中的命令,但会影响编译过程的各个方面。例如:使用预处理器指令可以禁止编译器编译代码的某一部分,如果计划发布两个版本的代码,即基本版本和有更多功能的企业版本,即可以使用这些预处理指令。在编译软件的基本版本时,使用预处理器指令还可以禁止编译器编译于额外相关的代码。另外,在编写提供调试信息的代码时,也可以使用预处理器指令。在销售软件时,一般不希望编译这部分代码。预处理器指令开头都有符号#。我们unity的不是分专业版和免费版吗,其实有可能就是用到了预编译,从而编译不同的版本。


如果对预编译不熟的同学可以去百度,或者谷歌下,我也是在查阅后才明白的!

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


本文题目:[unity3d]unity平台的预处理-创新互联
网站路径:http://bjjierui.cn/article/ddjeei.html

其他资讯