EV.ts 702 B

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