如图,创建空物体并命名 PoolManager,添加 脚本 spawn pool,并添加 如上图右边一些 参数,prefab为 Resources中 的预置体。
添加 空物体并 改名,如上图,并添加脚本。
using UnityEngine;
using System.Collections;
using PathologicalGames;
public class AssembleModel : MonoBehaviour
{
//创建
public Transform Spawner(string prefabs, string names = "", string SpawnPools = "prefabs")
{
Transform inst;
SpawnPool shapesPool = PoolManager.Pools[SpawnPools];
inst = shapesPool.Spawn(Resources.Load<Transform>(prefabs));
if (names == "")
names = prefabs + Time.timeScale;
inst.name = names;
return inst;
} //全体删除
public void Despawner(string SpawnPools = "prefabs")
{
SpawnPool shapesPool = PoolManager.Pools[SpawnPools];
shapesPool.DespawnAll();
}
//单个删除
public void Despawn(Transform transform, string SpawnPools = "prefabs")
{
SpawnPool shapesPool = PoolManager.Pools[SpawnPools]; shapesPool.Despawn(transform);
}
}
继承上面的类就可以 方便动态加载 物体或删除物体。