- 编译宏设置
- 官网文档:https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
- 之前打了个Android包后,宏不起作用,被自己坑了,小记一下
打包时的小坑
只要在 File -> Build Settings 中 Switch Platform 选择好对应平台,预编译宏才能起作用,如
这段代码才会加入编译
#if UNITY_STANDALONE_WIN static public KeyDownEventListener Get(GameObject go) { KeyDownEventListener listener = go.GetComponent<KeyDownEventListener>(); if (listener == null) { listener = go.AddComponent<KeyDownEventListener>(); } return listener; } #endif
之前打了个Android,没有重新选择会pc平台,导致pc宏一直没起作用,被自己坑了
添加一个自定义宏
在 File -> Build Settings -> Player Settings 中,这里添加一个自定义宏 DEBUG_DRAW(不同的宏用分号 ; 隔开),然后 回车(才能生效)
在代码中就可以测试了(已经可以高亮了)