| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import { _decorator } from 'cc';
- import { BaseSingleton } from '../Core/BaseSingleton';
- import EventBus, { GameEvents } from '../Core/EventBus';
- import { PhysicsManager } from '../Core/PhysicsManager';
- import { EnemyController } from '../CombatSystem/EnemyController';
- const { ccclass } = _decorator;
- @ccclass('CombatStateManager')
- export class CombatStateManager extends BaseSingleton {
- public static _instance: CombatStateManager;
- protected init() {
- const bus = EventBus.getInstance();
- bus.on(GameEvents.GAME_START, this.onStart, this);
- bus.on(GameEvents.GAME_PAUSE, this.onPause, this);
- bus.on(GameEvents.GAME_RESUME, this.onResume, this);
- bus.on(GameEvents.GAME_SUCCESS, this.onEnd, this);
- bus.on(GameEvents.GAME_DEFEAT, this.onEnd, this);
- }
- private onStart() {
- const system = PhysicsManager.getInstance()?.getSystem();
- if (system) system.enable = true;
- EnemyController.getInstance()?.resumeSpawning();
- }
- private onPause() {
- const sys = PhysicsManager.getInstance()?.getSystem();
- if (sys) sys.enable = false;
- EnemyController.getInstance()?.pauseSpawning();
- }
- private onResume() {
- const s = PhysicsManager.getInstance()?.getSystem();
- if (s) s.enable = true;
- EnemyController.getInstance()?.resumeSpawning();
- }
- private onEnd() {
- EnemyController.getInstance()?.pauseSpawning();
- }
- }
|