EventBus.ts 741 B

123456789101112131415161718192021222324252627282930
  1. import { EventTarget } from 'cc';
  2. /**
  3. * 全局事件总线,用于模块间解耦通信。
  4. */
  5. export enum GameEvents {
  6. GAME_START = 'GAME_START',
  7. GAME_PAUSE = 'GAME_PAUSE',
  8. GAME_RESUME = 'GAME_RESUME',
  9. GAME_SUCCESS = 'GAME_SUCCESS',
  10. GAME_DEFEAT = 'GAME_DEFEAT',
  11. SHOP_UPDATED = 'SHOP_UPDATED',
  12. BLOCK_SELECTION_OPEN = 'BLOCK_SELECTION_OPEN',
  13. BLOCK_SELECTION_CLOSE = 'BLOCK_SELECTION_CLOSE'
  14. }
  15. export default class EventBus extends EventTarget {
  16. private static _instance: EventBus;
  17. private constructor() {
  18. super();
  19. }
  20. public static getInstance(): EventBus {
  21. if (!this._instance) {
  22. this._instance = new EventBus();
  23. }
  24. return this._instance;
  25. }
  26. }