EventBus.ts 637 B

12345678910111213141516171819202122232425262728
  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. }
  13. export default class EventBus extends EventTarget {
  14. private static _instance: EventBus;
  15. private constructor() {
  16. super();
  17. }
  18. public static getInstance(): EventBus {
  19. if (!this._instance) {
  20. this._instance = new EventBus();
  21. }
  22. return this._instance;
  23. }
  24. }