Files
fc/dev/project/library/imports/41/41117fb4-8afe-410b-994a-e6021bfde259.js
T

99 lines
2.1 KiB
JavaScript
Raw Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, '41117+0iv5BC5lK5gIb/eJZ', 'bridge.pool.manager');
// Scripts/zbridge/cmps/bridge.pool.manager.js
"use strict";
/******************************************************************
*
* 桥接对象池管理器
*
******************************************************************/
cc.Class({
"extends": cc.Component,
ctor: function ctor() {
this.pools = {};
},
onLoad: function onLoad() {
nx.pools = this;
this.clean();
},
onDestroy: function onDestroy() {
if (window.nx) {
nx.pools = null;
this.clean();
}
},
// 获取单池(通过Node节点)
getPool: function getPool(_key, _node, _initCount) {
if (_initCount === void 0) {
_initCount = 10;
}
// 存在返回
var pool = this.pools[_key];
if (pool) {
return pool;
}
// 新建无模板
if (!_node) {
nx.error("[\u5BF9\u8C61\u6C60]\u4E0D\u5B58\u5728" + _key + ",\u83B7\u53D6\u5931\u8D25!");
return null;
}
// Prefab实例化
if (_node instanceof cc.Prefab) {
_node = cc.instantiate(_node);
}
// 新建
pool = nx.factory.create("bridge.pool", {
key: _key,
prefab: _node,
count: _initCount
});
this.pools[_key] = pool;
return pool;
},
// 对象回收
put: function put(_node) {
if (!_node) {
return;
}
if (nx.dt.strEmpty(_node.poolKey)) {
nx.error("回收失败,没有关联池信息!");
_node.removeFromParent(true);
return;
}
// 池子不存在
var pool = this.pools[_node.poolKey];
if (!pool) {
nx.warn("[回收失败,没有关联池:", _node.poolKey);
_node.removeFromParent(true);
return;
}
// 回收
_node.position = cc.Vec2.ZERO;
pool.put(_node);
},
// 全子节点回收
putChildren: function putChildren(_node) {
var chds = _node.children;
while (chds.length > 0) {
this.put(chds[0]);
}
_node.removeAllChildren(false);
},
// 清理
clean: function clean() {
for (var k in this.pools) {
nx.factory.remove(this.pools[k]);
}
this.pools = {};
}
});
cc._RF.pop();