import { LocalEmitter } from "./LocalEmitter"; const { ccclass, property } = cc._decorator; @ccclass export default class EmitterBase { _comp_id_: number = LocalEmitter.newCompId(); getCompId() { return this._comp_id_; } //注册监听 on(event: string, fn: Function) { LocalEmitter.inst.on(this.getCompId(), event, fn); } //移除监听 off(event: string = null, fn: Function = null) { LocalEmitter.inst.off(this.getCompId(), event, fn); } // 发送事件 emit(event: string = null, obj: any = null) { LocalEmitter.inst.emit(event, obj); } removeAllListeners() { LocalEmitter.inst.off(this.getCompId()); } initListener(config:{[key:string]:number}){ for(let key in config){ this.on(config[key].toString(), this[key].bind(this)); } } }