新增全局管理器
This commit is contained in:
12
demo/libs/framework/framework.d.ts
vendored
12
demo/libs/framework/framework.d.ts
vendored
@@ -791,6 +791,18 @@ declare class Emitter<T> {
|
|||||||
removeObserver(eventType: T, handler: Function): void;
|
removeObserver(eventType: T, handler: Function): void;
|
||||||
emit(eventType: T, data: any): 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 {
|
declare class ListPool {
|
||||||
private static readonly _objectQueue;
|
private static readonly _objectQueue;
|
||||||
static warmCache(cacheCount: number): void;
|
static warmCache(cacheCount: number): void;
|
||||||
|
|||||||
@@ -1118,6 +1118,10 @@ var Scene = (function (_super) {
|
|||||||
};
|
};
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
Time.update(egret.getTimer());
|
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();
|
this.entities.updateLists();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.update();
|
this.entityProcessors.update();
|
||||||
@@ -3933,6 +3937,51 @@ var Emitter = (function () {
|
|||||||
};
|
};
|
||||||
return Emitter;
|
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 () {
|
var ListPool = (function () {
|
||||||
function ListPool() {
|
function ListPool() {
|
||||||
}
|
}
|
||||||
|
|||||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
12
source/bin/framework.d.ts
vendored
12
source/bin/framework.d.ts
vendored
@@ -791,6 +791,18 @@ declare class Emitter<T> {
|
|||||||
removeObserver(eventType: T, handler: Function): void;
|
removeObserver(eventType: T, handler: Function): void;
|
||||||
emit(eventType: T, data: any): 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 {
|
declare class ListPool {
|
||||||
private static readonly _objectQueue;
|
private static readonly _objectQueue;
|
||||||
static warmCache(cacheCount: number): void;
|
static warmCache(cacheCount: number): void;
|
||||||
|
|||||||
@@ -1118,6 +1118,10 @@ var Scene = (function (_super) {
|
|||||||
};
|
};
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
Time.update(egret.getTimer());
|
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();
|
this.entities.updateLists();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.update();
|
this.entityProcessors.update();
|
||||||
@@ -3933,6 +3937,51 @@ var Emitter = (function () {
|
|||||||
};
|
};
|
||||||
return Emitter;
|
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 () {
|
var ListPool = (function () {
|
||||||
function ListPool() {
|
function ListPool() {
|
||||||
}
|
}
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -95,6 +95,11 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
public update(){
|
public update(){
|
||||||
Time.update(egret.getTimer());
|
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();
|
this.entities.updateLists();
|
||||||
|
|
||||||
if (this.entityProcessors)
|
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