BaseScene.js 648 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import EventMgr from "./EventMgr";
  2. //场景基类
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. },
  7. // LIFE-CYCLE CALLBACKS:
  8. onLoad () {
  9. this.eventArr = []; //存储添加的事件
  10. },
  11. start () {
  12. },
  13. // update (dt) {},
  14. registerListener(name, cb){
  15. this.eventArr.push([name, cb]);
  16. EventMgr.on(name, cb, this);
  17. },
  18. removeListener(){
  19. for(let i=0; i < this.eventArr.length; i++){
  20. EventMgr.off(this.eventArr[i][0], this.eventArr[i][1], this);
  21. }
  22. this.eventArr = [];
  23. },
  24. onDestroy(){
  25. this.removeListener();
  26. }
  27. });