EventMng.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Dictionary } from "./General";
  2. //事件管理类
  3. export class EventMng {
  4. private static _ins: EventMng;
  5. static get Ins(): EventMng {
  6. if (this._ins == null)
  7. this._ins = new EventMng();
  8. return this._ins;
  9. }
  10. /**
  11. * 注册事件
  12. * @param name 事件名
  13. * @param action 方法
  14. * @param target 执行回调的目标对象
  15. */
  16. static Register_Event(name: string, action: Function, target?: any) {
  17. if (!cc.systemEvent.hasEventListener(name)) {
  18. cc.systemEvent.on(name, action, target);
  19. } else {
  20. console.log("this event key has exist")
  21. }
  22. }
  23. /**
  24. * 删除事件
  25. * @param name 事件名
  26. * @param action 方法
  27. * @param target 执行回调的目标对象
  28. */
  29. static Remove_Event(name: string, action: Function, target?: any) {
  30. if (cc.systemEvent.hasEventListener(name)) {
  31. cc.systemEvent.off(name, action, target);
  32. } else {
  33. console.log("this event key has no exist");
  34. }
  35. }
  36. /**
  37. * 派发事件 执行事件
  38. * @param name 事件名
  39. * @param arg1 参数1
  40. * @param arg2 参数2
  41. * @param arg3 参数3
  42. * @param arg4 参数4
  43. * @param arg5 参数5
  44. */
  45. static Execute_Event(name: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any, arg5?: any) {
  46. if (cc.systemEvent.hasEventListener(name)) {
  47. cc.systemEvent.emit(name, arg1, arg2, arg3, arg4, arg5);
  48. } else {
  49. console.log("this event key has no exist");
  50. }
  51. }
  52. }