【问题标题】:How to define property which would allow me to call other Component's method?如何定义允许我调用其他组件方法的属性?
【发布时间】:2019-11-10 17:11:42
【问题描述】:

我正在创建一个组件,在其中我可能需要调用一些其他组件的方法,但我事先不知道它将是哪个组件,所以我猜"cc.Event" 是我任务的最佳人选。

当我这样做时,它不会起作用:

@ccclass
export default class Helloworld extends cc.Component {

    @property({ type: cc.Event })
    public event: cc.Event = new cc.Event("", true);

}

但我想像我们在 CCButton 中那样做:

我怎样才能做到这一点?我在CCButton 来源中查找,我可以看到它指向inspector.js,但我在任何地方都找不到这个检查器文件。

【问题讨论】:

    标签: typescript cocoscreator


    【解决方案1】:

    这就是它的工作原理。

    @ccclass
    export default class Helloworld extends cc.Component {
        mySuperDuperFunction(_ev, customparam) {
            cc.log("hi , i am super duper !",_ev, customparam); // log will output on debug compile.
        }
    }
    
    1. 将此作为组件拖到您的节点中
    2. 将此节点添加到您的按钮事件中
    3. 为组件组合选择HelloWorld
    4. 从列表中选择mySuperDuperFunction

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-19
      • 2018-11-30
      • 2016-02-23
      • 2011-03-14
      • 2021-02-03
      • 1970-01-01
      相关资源
      最近更新 更多