GLOBAL-MACROS 模块
这里是一些用来判断执行环境的宏,这些宏都是全局变量,直接访问即可。
在项目构建时,这些宏将会被预处理并根据构建的平台剔除不需要的代码,例如
if (CC_DEBUG) {
cc.log('debug');
}
else {
cc.log('release');
}
在构建后会只剩下
cc.log('release');
如需判断脚本是否运行于指定平台,可以用如下表达式:
{
"编辑器": CC_EDITOR,
"编辑器 或 预览": CC_DEV,
"编辑器 或 预览 或 构建调试": CC_DEBUG,
"网页预览": CC_PREVIEW && !CC_JSB,
"模拟器预览": CC_PREVIEW && CC_JSB,
"构建调试": CC_BUILD && CC_DEBUG,
"构建发行": CC_BUILD && !CC_DEBUG,
}
索引
属性(properties)
CC_EDITORBooleanRunning in the editor.CC_PREVIEWBooleanPreview in browser or simulator.CC_DEVBooleanRunning in the editor or preview.CC_DEBUGBooleanRunning in the editor or preview, or build in debug mode.CC_BUILDBooleanRunning in published project.CC_JSBBooleanRunning in native platform (mobile app, desktop app, or simulator).CC_TESTBooleanRunning in the engine's unit test.CC_RUNTIMEBooleanRunning in runtime environments.
Details
属性(properties)
CC_EDITOR
Running in the editor.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:90 |
CC_PREVIEW
Preview in browser or simulator.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:93 |
CC_DEV
Running in the editor or preview.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:96 |
CC_DEBUG
Running in the editor or preview, or build in debug mode.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:99 |
CC_BUILD
Running in published project.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:102 |
CC_JSB
Running in native platform (mobile app, desktop app, or simulator).
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:105 |
CC_TEST
Running in the engine's unit test.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:108 |
CC_RUNTIME
Running in runtime environments.
| meta | description |
|---|---|
| 类型 | Boolean |
| 定义于 | predefine.js:111 |