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_EDITOR Boolean Running in the editor.
  • CC_PREVIEW Boolean Preview in browser or simulator.
  • CC_DEV Boolean Running in the editor or preview.
  • CC_DEBUG Boolean Running in the editor or preview, or build in debug mode.
  • CC_BUILD Boolean Running in published project.
  • CC_JSB Boolean Running in native platform (mobile app, desktop app, or simulator).
  • CC_TEST Boolean Running in the engine's unit test.
  • CC_WECHATGAME Boolean Running in the WeChat's mini game.
  • CC_QQPLAY Boolean Running in the bricks.
  • CC_RUNTIME Boolean Running 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

results matching ""

    No results matching ""