Files
esengine/source/src/Utils/GlobalManager.ts

49 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-07-23 11:00:46 +08:00
module es {
export class GlobalManager {
public static globalManagers: GlobalManager[] = [];
private _enabled: boolean;
2020-06-18 12:14:06 +08:00
2020-07-23 11:00:46 +08:00
public get enabled(){
return this._enabled;
}
public set enabled(value: boolean){
this.setEnabled(value);
}
public setEnabled(isEnabled: boolean){
if (this._enabled != isEnabled){
this._enabled = isEnabled;
if (this._enabled){
this.onEnabled();
} else {
this.onDisabled();
}
2020-06-18 12:14:06 +08:00
}
}
2020-07-23 11:00:46 +08:00
public onEnabled(){}
2020-06-18 12:14:06 +08:00
2020-07-23 11:00:46 +08:00
public onDisabled(){}
2020-06-18 12:14:06 +08:00
2020-07-23 11:00:46 +08:00
public update(){}
2020-06-18 12:14:06 +08:00
2020-07-23 11:00:46 +08:00
public static registerGlobalManager(manager: GlobalManager){
this.globalManagers.push(manager);
manager.enabled = true;
}
2020-06-18 12:14:06 +08:00
2020-07-23 11:00:46 +08:00
public static unregisterGlobalManager(manager: GlobalManager){
this.globalManagers.remove(manager);
manager.enabled = false;
2020-06-18 12:14:06 +08:00
}
2020-07-23 11:00:46 +08:00
public static getGlobalManager<T extends GlobalManager>(type){
for (let i = 0; i < this.globalManagers.length; i ++){
if (this.globalManagers[i] instanceof type)
return this.globalManagers[i] as T;
}
return null;
}
2020-06-18 12:14:06 +08:00
}
2020-07-23 11:00:46 +08:00
}