123456789101112131415161718192021222324252627282930313233343536373839 |
- import EventMgr from "./EventMgr";
- //场景基类
- cc.Class({
- extends: cc.Component,
- properties: {
-
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad () {
- this.eventArr = []; //存储添加的事件
- },
- start () {
- },
- // update (dt) {},
- registerListener(name, cb){
- this.eventArr.push([name, cb]);
- EventMgr.on(name, cb, this);
- },
- removeListener(){
- for(let i=0; i < this.eventArr.length; i++){
- EventMgr.off(this.eventArr[i][0], this.eventArr[i][1], this);
- }
- this.eventArr = [];
- },
- onDestroy(){
- this.removeListener();
- }
- });
|