import { Node,NodePool, Prefab, instantiate} from "cc"; /** node对象池 */ class PrefabPool { private _pools:Map= new Map(); private _node:Node; constructor(){ if(this._node==null){ this._node=new Node(); this._node.active=false; } } private getPool(path:string):NodePool{ let pool= this._pools.get(path); if(pool==null){ pool= new NodePool(); this._pools.set(path,pool); } return pool; } public GetNode(p:Prefab):Node{ let pool= this.getPool(p.name); let node = pool.get(); if (!node){ node = instantiate (p); node.name=p.name; } return node; } public RecNode(node:Node):void{ node.parent=this._node; this.getPool(node.name).put(node); } public InitPool(p:Prefab,n:number=10):void{ let pool= this.getPool(p.name); for(let i=0;i{ v.clear(); }) this._pools.clear(); } public getAllPoolNames(): string[] { return Object.keys(this._pools); } public getPoolSize(poolName: string): number { const pool = this._pools[poolName]; if (pool) { return pool.size(); } return 0; } } export default function get_new_prefab_pool():PrefabPool { return new PrefabPool();}