logic.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. let actionMgr = cc.director.getActionManager();
  22. if(!CC_EDITOR){
  23. aniMgr._oldUpdate = aniMgr.update;
  24. aniMgr.update = function(dt){
  25. if(GameLogicMgr.inst.isGamePause) return;
  26. aniMgr._oldUpdate(dt);
  27. }
  28. // @ts-ignore
  29. actionMgr._oldUpdate = actionMgr.update;
  30. actionMgr.update = function(dt){
  31. if(GameLogicMgr.inst.isGamePause) return;
  32. // @ts-ignore
  33. actionMgr._oldUpdate(dt);
  34. }
  35. }
  36. cc.director.getScheduler().enableForTarget(this);
  37. cc.director.getScheduler().schedule(this.update, this, 0, cc.macro.REPEAT_FOREVER, 0, false);
  38. cc.director.getScheduler().schedule(this.updateSec, this, 1, cc.macro.REPEAT_FOREVER, 0, false);
  39. }
  40. update(dt){
  41. if (this.isGamePause) return;
  42. this.sysLogics.forEach((v)=>{
  43. // v['update'](dt);
  44. v.gameUpdate(dt);
  45. });
  46. }
  47. updateSec(dt) {
  48. if (this.isGamePause) return;
  49. this.sysLogics.forEach((v)=>{
  50. // v['updateSec'](dt);
  51. v.gameUpdateSec(dt);
  52. });
  53. }
  54. end(){
  55. cc.director.getScheduler().unschedule(this.update,this);
  56. cc.director.getScheduler().unschedule(this.updateSec,this);
  57. }
  58. addSysLogic(logic: GameSysLogic){
  59. this.sysLogics.set(logic.logicId, logic);
  60. }
  61. removeSysLogic(logic: GameSysLogic){
  62. this.sysLogics.delete(logic.logicId);
  63. }
  64. };