主要参考资料: http://blog.csdn.net/henren555/article/details/42100881
在代码中主要是这样使用的,
1. 初始化
SpawnPool dogFacePool = PoolManager.Pools.Create("Dogface", this.gameObject);
2. 需要创建实例的时候
<1>如果目前还没有对应的实例
Transform dogFacePrefab;
PrefabPool prefabPool = new PrefabPool(dogFacePrefab);
dogFacePool.CreatePrefabPool(prefabPool);
<2> 现在就可以真正创建实例了
Transform inst;
inst = dogFacePool.Spawn(m_prefabDic[resPath], pos, rot);
3. 当要释放实例的时候
dogFacePool.Despawn(obj.transform);
4. 缓冲池里面的对象active变为true和false时,触发的事件(此脚本悬挂在缓冲池对象上):
private void OnSpawned(SpawnPool pool)
{
Debug.Log
(
string.Format
(
"OnSpawnedExample | OnSpawned running for '{0}' in pool '{1}'.",
this.name,
pool.poolName
)
);
}
private void OnDespawned(SpawnPool pool)
{
Debug.Log
(
string.Format
(
"OnSpawnedExample | OnDespawned unning for '{0}' in pool '{1}'.",
this.name,
pool.poolName
)
);
}