新增全局管理器

This commit is contained in:
yhh
2020-06-18 12:14:06 +08:00
parent 231276e39b
commit 915056203d
8 changed files with 175 additions and 2 deletions

View File

@@ -791,6 +791,18 @@ declare class Emitter<T> {
removeObserver(eventType: T, handler: Function): void;
emit(eventType: T, data: any): void;
}
declare class GlobalManager {
static globalManagers: GlobalManager[];
private _enabled;
enabled: boolean;
setEnabled(isEnabled: boolean): void;
onEnabled(): void;
onDisabled(): void;
update(): void;
static registerGlobalManager(manager: GlobalManager): void;
static unregisterGlobalManager(manager: GlobalManager): void;
static getGlobalManager<T extends GlobalManager>(type: any): T;
}
declare class ListPool {
private static readonly _objectQueue;
static warmCache(cacheCount: number): void;

View File

@@ -1118,6 +1118,10 @@ var Scene = (function (_super) {
};
Scene.prototype.update = function () {
Time.update(egret.getTimer());
for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) {
if (GlobalManager.globalManagers[i].enabled)
GlobalManager.globalManagers[i].update();
}
this.entities.updateLists();
if (this.entityProcessors)
this.entityProcessors.update();
@@ -3933,6 +3937,51 @@ var Emitter = (function () {
};
return Emitter;
}());
var GlobalManager = (function () {
function GlobalManager() {
}
Object.defineProperty(GlobalManager.prototype, "enabled", {
get: function () {
return this._enabled;
},
set: function (value) {
this.setEnabled(value);
},
enumerable: true,
configurable: true
});
GlobalManager.prototype.setEnabled = function (isEnabled) {
if (this._enabled != isEnabled) {
this._enabled = isEnabled;
if (this._enabled) {
this.onEnabled();
}
else {
this.onDisabled();
}
}
};
GlobalManager.prototype.onEnabled = function () { };
GlobalManager.prototype.onDisabled = function () { };
GlobalManager.prototype.update = function () { };
GlobalManager.registerGlobalManager = function (manager) {
this.globalManagers.push(manager);
manager.enabled = true;
};
GlobalManager.unregisterGlobalManager = function (manager) {
this.globalManagers.remove(manager);
manager.enabled = false;
};
GlobalManager.getGlobalManager = function (type) {
for (var i = 0; i < this.globalManagers.length; i++) {
if (this.globalManagers[i] instanceof type)
return this.globalManagers[i];
}
return null;
};
GlobalManager.globalManagers = [];
return GlobalManager;
}());
var ListPool = (function () {
function ListPool() {
}

File diff suppressed because one or more lines are too long