• GLOBAL-MACROS 模块
    • 索引
      • 属性(properties)
  • Details
    • 属性(properties)
      • CC_EDITOR
      • CC_PREVIEW
      • CC_DEV
      • CC_DEBUG
      • CC_BUILD
      • CC_JSB
      • CC_TEST
      • CC_WECHATGAME
      • CC_QQPLAY
      • CC_RUNTIME

    GLOBAL-MACROS 模块

    这里是一些用来判断执行环境的宏,这些宏都是全局变量,直接访问即可。在项目构建时,这些宏将会被预处理并根据构建的平台剔除不需要的代码,例如

    1. if (CC_DEBUG) {
    2. cc.log('debug');
    3. }
    4. else {
    5. cc.log('release');
    6. }

    在构建后会只剩下

    1. cc.log('release');

    如需判断脚本是否运行于指定平台,可以用如下表达式:

    1. {
    2. "编辑器": CC_EDITOR,
    3. "编辑器 或 预览": CC_DEV,
    4. "编辑器 或 预览 或 构建调试": CC_DEBUG,
    5. "网页预览": CC_PREVIEW && !CC_JSB,
    6. "模拟器预览": CC_PREVIEW && CC_JSB,
    7. "构建调试": CC_BUILD && CC_DEBUG,
    8. "构建发行": CC_BUILD && !CC_DEBUG,
    9. }

    索引

    属性(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.
    metadescription
    类型Boolean
    定义于predefine.js:90
    CC_PREVIEW
    Preview in browser or simulator.
    metadescription
    类型Boolean
    定义于predefine.js:93
    CC_DEV
    Running in the editor or preview.
    metadescription
    类型Boolean
    定义于predefine.js:96
    CC_DEBUG
    Running in the editor or preview, or build in debug mode.
    metadescription
    类型Boolean
    定义于predefine.js:99
    CC_BUILD
    Running in published project.
    metadescription
    类型Boolean
    定义于predefine.js:102
    CC_JSB
    Running in native platform (mobile app, desktop app, or simulator).
    metadescription
    类型Boolean
    定义于predefine.js:105
    CC_TEST
    Running in the engine's unit test.
    metadescription
    类型Boolean
    定义于predefine.js:108
    CC_WECHATGAME
    Running in the Wechat's mini game.
    metadescription
    类型Boolean
    定义于predefine.js:111
    CC_QQPLAY
    Running in the bricks.
    metadescription
    类型Boolean
    定义于predefine.js:114
    CC_RUNTIME
    Running in runtime environments.
    metadescription
    类型Boolean
    定义于predefine.js:117