Unity场景中经常需要动态生成一些预制体物体,记录分享方便快捷的对象池使用方式。
public GameObject prefab;
public GameObject pool;// 对象池游戏物体
private Dictionary<string, Queue<GameObject>> objectPool = new Dictionary<string, Queue<GameObject>>();// 对象池字典,(string对象名字,对象队列)
///
<summary>
/// 从对象池中获取预制体生成的对象
/// </summary>
/// <param name="tprefab"></param>
/// <returns></returns>
public GameObject GetObject(GameObject tprefab)
{