8e81d067c8870d70331d8b9656a976c1f558e5de.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. let 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. let pool = this.getPool(p.name);
  41. let 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 = 10) {
  53. let pool = this.getPool(p.name);
  54. for (let i = 0; i < n; i++) {
  55. let node = instantiate(p);
  56. node.name = p.name;
  57. node.parent = this._node;
  58. pool.put(node);
  59. }
  60. }
  61. Clear() {
  62. if (!this._node) return;
  63. this._node.removeAllChildren();
  64. this._pools.forEach((v, k) => {
  65. v.clear();
  66. });
  67. this._pools.clear();
  68. }
  69. getAllPoolNames() {
  70. return Object.keys(this._pools);
  71. }
  72. getPoolSize(poolName) {
  73. const pool = this._pools[poolName];
  74. if (pool) {
  75. return pool.size();
  76. }
  77. return 0;
  78. }
  79. };
  80. _cclegacy._RF.pop();
  81. _crd = false;
  82. }
  83. };
  84. });
  85. //# sourceMappingURL=8e81d067c8870d70331d8b9656a976c1f558e5de.js.map