EV.ts 667 B

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