通过Unity预编译文件smcs.rsp文件添加预编译命令

可以在Unity Assets目录下创建smcs.rsp文件,并向其中添加预编译命令,其会在unity启动时执行,比如新建一个smcs.rsp文件,向其中添加内容:
-define:MYDEF
然后就可以在脚本中加入宏判断:

if MYDEF

….

endif

其原理是启动Unity时会执行unity目录下的smcs.exe文件并添加预编译命令,也可以通过cmd运行smcs.exe逐个添加预编译命令。
另外还有可以创建gmcs.rsp文件,对应Editor脚本中的预编译命令。
详细:
Custom Preprocessor Directives

It is also possible to define your own preprocessor directives to control which code gets included when compiling. To do this you must add in the “Assets/” folder a text file with the extra directives. The name of the file depends on the language you are using :

C#
/Assets/smcs.rsp

C# - Editor Scripts
/Assets/gmcs.rsp

UnityScript
/Assets/us.rsp

Boo
/Assets/boo.rsp

As an example, if you include the single line ‘-define:UNITY_DEBUG’ in your smcs.rsp file the define UNITY_DEBUG will exist as a global define for C# scripts, except for Editor scripts.
Every time you make make changes to the .rsp files a recompilation needs to be done for them to be effective. You can do this by updating or reimporting a single script (.js, .cs or .boo) file.
The usage of the .rsp files is described in the help of the smcs application, included in the Editor installation folder. You can get more information by running : “smcs -help”.

比如如果想要在C#语言中使用指针,必须标记为unsafe的,默认情况下unity中使用unsafe标记会报错,可以在项目中添加smcs.rsp文件并加入-unsafe预编译命令,就可以编译通过。

作者:MrLSN
链接:http://www.jianshu.com/p/9833ce1e2ec6
來源:简书

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值