"use strict"; cc._RF.push(module, '152ffFhQnBGO6orkFqGXRZv', 'bridge.pool'); // Scripts/zbridge/cmps/bridge.pool.js "use strict"; /****************************************************************** * * 桥接节点池 * ******************************************************************/ var NxObject = require("nx.object"); var BridgeNodePool = cc.Class({ "extends": NxObject, name: "BridgeNodePool", // 初始化 initialize: function initialize(_args) { if (!this._super(_args)) { return false; } // 创建节点池 this.np = new cc.NodePool(); var count = _args.count || 10; this.prefab = _args.prefab; this.key = _args.key || "pool"; // 存量初始化 for (var i = 0; i < count; ++i) { var node = cc.instantiate(this.prefab); node.poolKey = this.key; this.np.put(node); } return true; }, // 销毁 uninitialize: function uninitialize() { this.np.clear(); // USPER return this._super(); }, // 复用 get: function get() { // nx.debug( `>$>>${this.key}取:${this.np.size()}` ); var node = this.np.get(); if (node) { return node; } // 追加 // nx.debug( `${this.key}触发复用,数量超限新建` ); node = cc.instantiate(this.prefab); node.poolKey = this.key; return node; }, // 回收 put: function put(_node) { this.np.put(_node); // nx.debug( `>$>>${this.key}存:${this.np.size()}` ); } }); module.exports = BridgeNodePool; cc._RF.pop();