UEBase.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { AudioConst } from "../../data/const/TypeConst";
  2. import GameDataCenter from "../../data/GameDataCenter";
  3. import EventMng from "../../manager/EventMng";
  4. import { uiCommon } from "../../utils/UICommon";
  5. import { BtnEvent } from "../fgui/mvc/FguiViewCtrl";
  6. import { Constructor } from "./Fundation";
  7. declare global {
  8. type UEClass<T> = Constructor<T> & {
  9. readonly BundleKey: string;
  10. readonly PrefabUrl: string;
  11. readonly CLS: string;
  12. // OnCollectResStatic?: (resCollector: IResCollector) => void;
  13. }
  14. }
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default abstract class UEBase extends cc.Component {
  18. /**通知事件列表 */
  19. private _notifyEventList: Map<string, Function> = new Map<string, Function>();
  20. registerCount: number = 0
  21. /**onLoad 会在组件被首次加载的时候被回调。且优先于任何start */
  22. onLoad() {
  23. }
  24. onDestroy() {
  25. try {
  26. let self = this;
  27. this._notifyEventList.forEach((f, key) => {
  28. // console.log("_notifyEventList key = "+key)
  29. EventMng.off(key, f, self);
  30. }, this);
  31. this._notifyEventList.clear();
  32. } catch (error) {
  33. console.error("onDisable->" + error)
  34. }
  35. if (this.registerCount > 0) {
  36. console.error(this.name + " 按钮注册后没off掉啊喂 \n(╯-_-)╯╧╧ ")
  37. }
  38. }
  39. /**注册notice事件,disable的时候会自动移除 */
  40. initEvent(eventName: string, cb: Function) {
  41. EventMng.on(eventName, cb, this);
  42. this._notifyEventList.set(eventName, cb);
  43. }
  44. RegisterClick(node: cc.Node, callback, target = null, params: any = [], audio: AudioConst = AudioConst.effect_click) {
  45. uiCommon.onRegisterEvent(node, callback, target, params, audio)
  46. }
  47. RemoveAllClick() {
  48. uiCommon.unRegisterEvent(this.node)
  49. }
  50. }