logic.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { GameSysLogic } from "./gameSysLogic";
  2. export class GameLogicMgr {
  3. private static _inst: GameLogicMgr;
  4. public static get inst(): GameLogicMgr {
  5. if (this._inst == null) {
  6. this._inst = new GameLogicMgr();
  7. this._inst.init();
  8. }
  9. return this._inst;
  10. }
  11. isGamePause: boolean = false;
  12. sysLogics: Map<number, GameSysLogic> = new Map();
  13. switch(){
  14. this.isGamePause = !this.isGamePause;
  15. //@ts-ignore
  16. dragonBones.timeScale = this.isGamePause ? 0 : 1;
  17. }
  18. init(){
  19. //@ts-ignore
  20. let aniMgr = cc.director.getAnimationManager();
  21. if(!CC_EDITOR){
  22. aniMgr._oldUpdate = aniMgr.update;
  23. aniMgr.update = function(dt){
  24. if(GameLogicMgr.inst.isGamePause) return;
  25. aniMgr._oldUpdate(dt);
  26. }
  27. }
  28. cc.director.getScheduler().enableForTarget(this);
  29. cc.director.getScheduler().schedule(this.update, this, 0, cc.macro.REPEAT_FOREVER, 0, false);
  30. cc.director.getScheduler().schedule(this.updateSec, this, 1, cc.macro.REPEAT_FOREVER, 0, false);
  31. }
  32. update(dt){
  33. if (this.isGamePause) return;
  34. this.sysLogics.forEach((v)=>{
  35. v['update'](dt);
  36. });
  37. }
  38. updateSec(dt) {
  39. if (this.isGamePause) return;
  40. this.sysLogics.forEach((v)=>{
  41. v['updateSec'](dt);
  42. });
  43. }
  44. end(){
  45. cc.director.getScheduler().unschedule(this.update,this);
  46. cc.director.getScheduler().unschedule(this.updateSec,this);
  47. }
  48. addSysLogic(logic: GameSysLogic){
  49. this.sysLogics.set(logic.logicId, logic);
  50. }
  51. removeSysLogic(logic: GameSysLogic){
  52. this.sysLogics.delete(logic.logicId);
  53. }
  54. };