123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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();
- let actionMgr = cc.director.getActionManager();
-
- if(!CC_EDITOR){
- aniMgr._oldUpdate = aniMgr.update;
- aniMgr.update = function(dt){
- if(GameLogicMgr.inst.isGamePause) return;
- aniMgr._oldUpdate(dt);
- }
- // @ts-ignore
- actionMgr._oldUpdate = actionMgr.update;
- actionMgr.update = function(dt){
- if(GameLogicMgr.inst.isGamePause) return;
- // @ts-ignore
- actionMgr._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);
- v.gameUpdate(dt);
- });
- let toDel = [];
- this.timer.forEach((v,k)=>{
- v.time -= dt;
- if(v.time <= 0) {
- v.call && v.call();
- toDel.push(k);
- }
- })
- toDel.forEach(v=>{
- this.timer.delete(v);
- })
- }
- updateSec(dt) {
- if (this.isGamePause) return;
- this.sysLogics.forEach((v)=>{
- // v['updateSec'](dt);
- v.gameUpdateSec(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);
- }
- timer:Map<number, {time: number, call: Function}> = new Map();
- idBase_timer = 0;
- setGameTimeout(call:Function, time: number){
- let id = this.idBase_timer++;
- this.timer.set(id, {time, call})
- return id;
- }
- clearGameTimeout(id){
- this.timer.delete(id);
- }
- };
|