fae2f1c33de6350c26fec47c7441e277eec07bcd.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Node, NodePool, instantiate, PrefabPool, _crd;
  4. function get_new_prefab_pool() {
  5. return new PrefabPool();
  6. }
  7. _export("default", get_new_prefab_pool);
  8. return {
  9. setters: [function (_cc) {
  10. _cclegacy = _cc.cclegacy;
  11. __checkObsolete__ = _cc.__checkObsolete__;
  12. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  13. Node = _cc.Node;
  14. NodePool = _cc.NodePool;
  15. instantiate = _cc.instantiate;
  16. }],
  17. execute: function () {
  18. _crd = true;
  19. _cclegacy._RF.push({}, "12f30kX+ltO4JZlGRue34gE", "PrefabPool", undefined);
  20. /** node对象池 */
  21. __checkObsolete__(['Node', 'NodePool', 'Prefab', 'instantiate']);
  22. PrefabPool = class PrefabPool {
  23. constructor() {
  24. this._pools = new Map();
  25. this._node = void 0;
  26. if (this._node == null) {
  27. this._node = new Node();
  28. this._node.active = false;
  29. }
  30. }
  31. getPool(path) {
  32. var pool = this._pools.get(path);
  33. if (pool == null) {
  34. pool = new NodePool();
  35. this._pools.set(path, pool);
  36. }
  37. return pool;
  38. }
  39. GetNode(p) {
  40. var pool = this.getPool(p.name);
  41. var node = pool.get();
  42. if (!node) {
  43. node = instantiate(p);
  44. node.name = p.name;
  45. }
  46. return node;
  47. }
  48. RecNode(node) {
  49. node.parent = this._node;
  50. this.getPool(node.name).put(node);
  51. }
  52. InitPool(p, n) {
  53. if (n === void 0) {
  54. n = 10;
  55. }
  56. var pool = this.getPool(p.name);
  57. for (var i = 0; i < n; i++) {
  58. var node = instantiate(p);
  59. node.name = p.name;
  60. node.parent = this._node;
  61. pool.put(node);
  62. }
  63. }
  64. Clear() {
  65. if (!this._node) return;
  66. this._node.removeAllChildren();
  67. this._pools.forEach((v, k) => {
  68. v.clear();
  69. });
  70. this._pools.clear();
  71. }
  72. getAllPoolNames() {
  73. return Object.keys(this._pools);
  74. }
  75. getPoolSize(poolName) {
  76. var pool = this._pools[poolName];
  77. if (pool) {
  78. return pool.size();
  79. }
  80. return 0;
  81. }
  82. };
  83. _cclegacy._RF.pop();
  84. _crd = false;
  85. }
  86. };
  87. });
  88. //# sourceMappingURL=fae2f1c33de6350c26fec47c7441e277eec07bcd.js.map