EV.ts 797 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { EventTarget } from "cc";
  2. export enum EV_TYPE {
  3. USER_GOOD_REFRESH = 10001,
  4. FAMILY_STATUS_UPDATE = 10002,
  5. FAMILY_DATA_UPDATE = 10003,
  6. FAMILY_MEMBER_UPDATE = 10004,
  7. FAMILY_SEARCH_RESULT = 10005,
  8. }
  9. export default class EV {
  10. private static _ins: EV;
  11. public static get ins(): EV {
  12. if (!EV._ins) {
  13. EV._ins = new EV();
  14. }
  15. return EV._ins;
  16. }
  17. private e: EventTarget;
  18. constructor() {
  19. this.e = new EventTarget();
  20. }
  21. public on(event: EV_TYPE, callback: (...args: any[]) => void, target: any) {
  22. this.e.on(event, callback, target);
  23. }
  24. public off(event: EV_TYPE, callback: (...args: any[]) => void, target: any) {
  25. this.e.off(event, callback, target);
  26. }
  27. public emit(event: EV_TYPE, ...args: any[]) {
  28. this.e.emit(event, ...args);
  29. }
  30. }