**** 一定一定,在 loading的时候, 执行下这个方法。
EventMgr.getInstance();
1.单例模式
/**
* 单例模式基类
*/
export default class SingletonMgr {
static getInstance<T extends {}>(this: new () => T): T {
if (!(<any>this).__instance){
(<any>this).__instance = new this();
}
return (<any>this).__instance;
}
public static destroyInstance<T extends {}>(this: new () => T): void {
if ((<any>this).__instance){
(<any>this).__instance = null;
}
}
}
2. 脚本
import SingletonMgr from "./SingletonMgr";
export default class EventMgr extends SingletonMgr {
/**
* 全局事件
*/
public static event: cc.EventTarget = null;
constructor() {
super();
this.initialize();
}
private initialize(): void {
EventMgr.event = new cc.EventTa