GLOBAL-MACROS Module
Here are some of the macro used to determine the execution environment, these macros are global variables, can be accessed directly.
When the project is built, these macros will be preprocessed and discard unreachable code based on the built platform, for example:
if (CC_DEBUG) {
cc.log('debug');
}
else {
cc.log('release');
}
After build will become:
cc.log('release');
To determine whether the script is running on the specified platform, you can use the following expression:
{
"editor": CC_EDITOR,
"editor or preview": CC_DEV,
"editor or preview or build in debug mode": CC_DEBUG,
"web preview": CC_PREVIEW && !CC_JSB,
"simulator preview": CC_PREVIEW && CC_JSB,
"build in debug mode": CC_BUILD && CC_DEBUG,
"build in release mode": CC_BUILD && !CC_DEBUG,
}
Index
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_WECHATGAMEBooleanRunning in the WeChat's mini game.CC_QQPLAYBooleanRunning in the bricks.CC_RUNTIMEBooleanRunning in runtime environments.
Details
Properties
CC_EDITOR
Running in the editor.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:90 |
CC_PREVIEW
Preview in browser or simulator.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:93 |
CC_DEV
Running in the editor or preview.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:96 |
CC_DEBUG
Running in the editor or preview, or build in debug mode.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:99 |
CC_BUILD
Running in published project.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:102 |
CC_JSB
Running in native platform (mobile app, desktop app, or simulator).
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:105 |
CC_TEST
Running in the engine's unit test.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:108 |
CC_WECHATGAME
Running in the WeChat's mini game.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:111 |
CC_QQPLAY
Running in the bricks.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:114 |
CC_RUNTIME
Running in runtime environments.
| meta | description |
|---|---|
| Type | Boolean |
| Defined in | predefine.js:117 |