求大佬指教:engine层增加一个组件,属性面板 properties报错

在engine/cocos2d/core/components 文件目录下,随便增加一个组件脚本如下:

执行完gulp build-dev 之后重启creaotr, 随便点击场景上的节点,提示 TypeError如下:


右侧属性面板无法打开:

通过对比,分别在 cocos2d/core/components/index.js 中增加了 require(’’./xxx)

和在 engine/modules.js 中 增加

重新构建后,依旧报错。
请问下,engine层中如何增加一个自定义的组件

我也想知道

每日一顶…

看来只能周末花时间去研究了

我尽量还原截图里的组件代码,我这里没有问题,在 index.js 和 modules.json 添加相应的内容就添加好了组件

官方的提交记录也是只在这两个地方加了内容

提交链接


组件

/**
 * Who
 * @class WhoComponet
 * @extends Component
 */
var WhoComponet = cc.Class({
    name: 'WhoComponet',
    extends: require('./CCComponent'),

    editor: CC_EDITOR && {
        // help: 'i18n:COMPONENT.help_url.safe_area',
        menu: 'i18n:MAIN_MENU.component.ui/WhoComponent',
        // inspector: 'packages://inspector/inspectors/comps/safe-area.js',
        executeInEditMode: true,
        // requireComponent: Widget,
    },

    properties: {
        
        /**
         * !#en Content string of RichText.
         * !#zh 富文本显示的文本内容。
         * @property {String} string
         */
        string: {
            default: '<color=#00ff00>Rich</c><color=#0fffff>Text</color>',
            multiline: true,
            tooltip: CC_DEV && 'i18n:COMPONENT.richtext.string'
        },

    },

    ctor() {
        this._textArray = null;
        this._labelSegments = [];
        this._labelSegmentsCache = [];
        this._linesWidth = [];
    },

    onLoad() {
        cc.log("success!");
    },

    onDestroy() {
        cc.log("byebye!");
    }

});

module.exports = WhoComponet;

index.js

    require('./WhoComponet'),

modules.json

 {
    "name": "WhoComponet",
    "since": "2.4.0",
    "entries": [
        "./cocos2d/core/components/WhoComponet.js"
    ]
  }

效果

我用的是 2.4.3-rc4 测试的,供参考

2赞

终于有大神回了:joy:,我晚上回去试试,不应该啊,我的是1.9.3
谢谢啦