对象池
2017-11-01 本文已影响0人
貪狼大人
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PoolController : SingletonMono<PoolController> {
Dictionary<string, SubPool> Mypool = new Dictionary<string, SubPool>();
//根据名字返回对象
public GameObject Spawn(string name)
{
SubPool pool;
if (!Mypool.ContainsKey(name))
{
//注册新池子
biuldpool(name);
}
pool = Mypool[name];
return pool.Spawn();
}
public void UnSpawn(GameObject obj)
{
foreach (SubPool pool in Mypool.Values)
{
if (pool.ContainObj(obj))
{
print("999");
pool.UnSpawn(obj);
break;
}
}
}
public void UnSpawnAll()
{
foreach (SubPool pool in Mypool.Values)
{
pool.UnSpawnAll();
}
}
//注册新池子
private void biuldpool(string name)
{
GameObject obj = Resources.Load<GameObject>(name);
SubPool pool = new SubPool(obj); Mypool.Add(name, pool);
}
}