新增全局管理器
This commit is contained in:
@@ -95,6 +95,11 @@ class Scene extends egret.DisplayObjectContainer {
|
||||
public update(){
|
||||
Time.update(egret.getTimer());
|
||||
|
||||
for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i --){
|
||||
if (GlobalManager.globalManagers[i].enabled)
|
||||
GlobalManager.globalManagers[i].update();
|
||||
}
|
||||
|
||||
this.entities.updateLists();
|
||||
|
||||
if (this.entityProcessors)
|
||||
|
||||
46
source/src/Utils/GlobalManager.ts
Normal file
46
source/src/Utils/GlobalManager.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
class GlobalManager {
|
||||
public static globalManagers: GlobalManager[] = [];
|
||||
private _enabled: boolean;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public onEnabled(){}
|
||||
|
||||
public onDisabled(){}
|
||||
|
||||
public update(){}
|
||||
|
||||
public static registerGlobalManager(manager: GlobalManager){
|
||||
this.globalManagers.push(manager);
|
||||
manager.enabled = true;
|
||||
}
|
||||
|
||||
public static unregisterGlobalManager(manager: GlobalManager){
|
||||
this.globalManagers.remove(manager);
|
||||
manager.enabled = false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user