123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { GameSysLogic } from "./gameSysLogic";
- export class GameLogicMgr {
- private static _inst: GameLogicMgr;
- public static get inst(): GameLogicMgr {
- if (this._inst == null) {
- this._inst = new GameLogicMgr();
- this._inst.init();
- }
- return this._inst;
- }
- isGamePause: boolean = false;
- sysLogics: Map<number, GameSysLogic> = new Map();
- switch(){
- this.isGamePause = !this.isGamePause;
- //@ts-ignore
- dragonBones.timeScale = this.isGamePause ? 0 : 1;
- }
- init(){
- //@ts-ignore
- let aniMgr = cc.director.getAnimationManager();
-
- if(!CC_EDITOR){
- aniMgr._oldUpdate = aniMgr.update;
- aniMgr.update = function(dt){
- if(GameLogicMgr.inst.isGamePause) return;
- aniMgr._oldUpdate(dt);
- }
- }
- cc.director.getScheduler().enableForTarget(this);
- cc.director.getScheduler().schedule(this.update, this, 0, cc.macro.REPEAT_FOREVER, 0, false);
- cc.director.getScheduler().schedule(this.updateSec, this, 1, cc.macro.REPEAT_FOREVER, 0, false);
- }
- update(dt){
- if (this.isGamePause) return;
- this.sysLogics.forEach((v)=>{
- v['update'](dt);
- });
- }
- updateSec(dt) {
- if (this.isGamePause) return;
- this.sysLogics.forEach((v)=>{
- v['updateSec'](dt);
- });
- }
- end(){
- cc.director.getScheduler().unschedule(this.update,this);
- cc.director.getScheduler().unschedule(this.updateSec,this);
- }
- addSysLogic(logic: GameSysLogic){
- this.sysLogics.set(logic.logicId, logic);
- }
- removeSysLogic(logic: GameSysLogic){
- this.sysLogics.delete(logic.logicId);
- }
- };
|