Phaser.PluginManager = function (game, parent){ this.game = game; this._parent = parent; this.plugins = [] ; this._pluginsLength = 0; } ; Phaser.PluginManager.prototype = { add: function (plugin){ var result = false ; if (typeof plugin === 'function') { plugin = new plugin(this.game, this._parent); } else { plugin.game = this.game; plugin.parent = this._parent; } if (typeof plugin.preUpdate === 'function') { plugin.hasPreUpdate = true ; result = true ; } if (typeof plugin.update === 'function') { plugin.hasUpdate = true ; result = true ; } if (typeof plugin.postUpdate === 'function') { plugin.hasPostUpdate = true ; result = true ; } if (typeof plugin.render === 'function') { plugin.hasRender = true ; result = true ; } if (typeof plugin.postRender === 'function') { plugin.hasPostRender = true ; result = true ; } if (result) { if (plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) { plugin.active = true ; } if (plugin.hasRender || plugin.hasPostRender) { plugin.visible = true ; } this._pluginsLength = this.plugins.push(plugin); if (typeof plugin.init === 'function') { _AN_Call_init('init', plugin); } return plugin; } else { return null ; } } , remove: function (plugin){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p] === plugin) { plugin.destroy(); this.plugins.splice(this._p, 1); this._pluginsLength-- ; return ; } } } , removeAll: function (){ for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ this.plugins[this._p].destroy(); } this.plugins.length = 0; this._pluginsLength = 0; } , preUpdate: function (){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) { this.plugins[this._p].preUpdate(); } } } , update: function (){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p].active && this.plugins[this._p].hasUpdate) { this.plugins[this._p].update(); } } } , postUpdate: function (){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) { this.plugins[this._p].postUpdate(); } } } , render: function (){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p].visible && this.plugins[this._p].hasRender) { this.plugins[this._p].render(); } } } , postRender: function (){ if (this._pluginsLength === 0) { return ; } for (this._p = 0; this._p < this._pluginsLength; this._p++ ){ if (this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) { this.plugins[this._p].postRender(); } } } , destroy: function (){ this.plugins.length = 0; this._pluginsLength = 0; this.game = null ; this._parent = null ; } } ;