123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import EventMng from "../../manager/EventMng";
- import { Constructor } from "./Fundation";
- declare global {
- type UEClass<T> = Constructor<T> & {
- readonly BundleKey: string;
- readonly PrefabUrl: string;
- readonly CLS: string;
- // OnCollectResStatic?: (resCollector: IResCollector) => void;
- }
- }
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default abstract class UEBase extends cc.Component {
- /**通知事件列表 */
- private _notifyEventList: Map<string, Function> = new Map<string, Function>();
- registerCount: number = 0
- /**onLoad 会在组件被首次加载的时候被回调。且优先于任何start */
- onLoad() {
- }
- onDestroy() {
- try {
- let self = this;
- this._notifyEventList.forEach((f, key) => {
- // console.log("_notifyEventList key = "+key)
- EventMng.off(key, f, self);
- }, this);
- this._notifyEventList.clear();
- } catch (error) {
- console.error("onDisable->" + error)
- }
- if (this.registerCount > 0) {
- console.error(this.name + " 按钮注册后没off掉啊喂 \n(╯-_-)╯╧╧ ")
- }
- }
- /**注册notice事件,disable的时候会自动移除 */
- initEvent(eventName: string, cb: Function) {
- EventMng.on(eventName, cb, this);
- this._notifyEventList.set(eventName, cb);
- }
- }
|