System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, instantiate, Prefab, Vec3, _dec, _class, _class2, _crd, ccclass, property, PoolManager;

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      __checkObsolete__ = _cc.__checkObsolete__;
      __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
      _decorator = _cc._decorator;
      Component = _cc.Component;
      instantiate = _cc.instantiate;
      Prefab = _cc.Prefab;
      Vec3 = _cc.Vec3;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "bdc3cYFCvpCo7BF8M0f4m2x", "PoolManager", undefined);

      __checkObsolete__(['_decorator', 'Component', 'instantiate', 'Node', 'Pool', 'Prefab', 'Vec3']);

      ({
        ccclass,
        property
      } = _decorator);
      /**
       * 对象池管理器
       * 功能：
       * 1. 管理游戏对象的复用
       * 2. 减少频繁创建/销毁对象的性能开销
       * 3. 支持Prefab和Node两种类型的对象池
       */

      _export("PoolManager", PoolManager = (_dec = ccclass('PoolManager'), _dec(_class = (_class2 = class PoolManager extends Component {
        /**
         * 从对象池获取节点（支持Prefab或Node）
         * @param prefab - Prefab资源或节点模板
         * @param parent - 可选父节点
         * @returns 可复用的节点实例
         */
        static getNode(prefab, parent) {
          const poolKey = prefab instanceof Prefab ? prefab.data.name : prefab.name;
          let node = null; //从对象池获取可用节点

          const pool = this._objectPools.get(poolKey);

          if ((pool == null ? void 0 : pool.length) > 0) {
            node = pool.pop();
          } else {
            node = instantiate(prefab);
          } //初始化节点状态


          node.active = true;

          if (parent) {
            node.setParent(parent);
            node.position = Vec3.ZERO;
          }

          return node;
        }
        /**
         * 通过名称从对象池获取节点
         * @param poolKey - 对象池键名
         * @param parent - 可选父节点
         * @returns 可复用的节点实例（如果没有则返回null）
         */


        static getName(poolKey, parent) {
          const pool = this._objectPools.get(poolKey);

          const node = pool == null ? void 0 : pool.pop();

          if (node && parent) {
            node.setParent(parent);
          }

          return node != null ? node : null;
        }
        /**
         * 将节点回收到对象池
         * @param node - 要回收的节点
         */


        static putNode(node) {
          if (!(node != null && node.isValid)) return;
          const poolKey = node.name; //清理节点状态

          node.removeFromParent();
          node.active = false; //存入对象池

          if (poolKey) {
            if (!this._objectPools.has(poolKey)) {
              this._objectPools.set(poolKey, []);
            }

            this._objectPools.get(poolKey).push(node);
          } else {
            //没有有效名称的节点直接销毁
            node.destroy();
          }
        }
        /**
         * 获取指定对象池的大小
         * @param poolKey - 对象池键名
         * @returns 对象池中可用节点的数量
         */


        static getPoolSize(poolKey) {
          var _this$_objectPools$ge, _this$_objectPools$ge2;

          return (_this$_objectPools$ge = (_this$_objectPools$ge2 = this._objectPools.get(poolKey)) == null ? void 0 : _this$_objectPools$ge2.length) != null ? _this$_objectPools$ge : 0;
        }
        /**
         * 清空指定对象池
         * @param poolKey - 要清空的对象池键名
         */


        static clearPool(poolKey) {
          const pool = this._objectPools.get(poolKey);

          if (pool) {
            pool.forEach(node => node.destroy());

            this._objectPools.delete(poolKey);
          }
        }
        /**
         * 清空所有对象池
         */


        static clearAll() {
          this._objectPools.forEach((pool, key) => {
            pool.forEach(node => node.destroy());
          });

          this._objectPools.clear();
        }

      }, _class2._objectPools = new Map(), _class2)) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=a14187dd1665ad3978e1499981a567b21abfe4ab.js.map