You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace XWFramework.ObjectTool
|
|
|
|
|
{
|
|
|
|
|
public class SubPool
|
|
|
|
|
{
|
|
|
|
|
List<GameObject> pool;
|
|
|
|
|
|
|
|
|
|
GameObject m_prefab;
|
|
|
|
|
|
|
|
|
|
Transform m_parent;
|
|
|
|
|
public SubPool(GameObject prefab, Transform parent)
|
|
|
|
|
{
|
|
|
|
|
pool = new List<GameObject>();
|
|
|
|
|
m_prefab = prefab;
|
|
|
|
|
m_parent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//ȡ<><C8A1>
|
|
|
|
|
public GameObject Spawn()
|
|
|
|
|
{
|
|
|
|
|
foreach (GameObject obj in pool)
|
|
|
|
|
{
|
|
|
|
|
if (!obj.activeInHierarchy)
|
|
|
|
|
{
|
|
|
|
|
obj.SetActive(true);
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameObject gb = GameObject.Instantiate(m_prefab);
|
|
|
|
|
pool.Add(gb);
|
|
|
|
|
gb.transform.SetParent(m_parent);
|
|
|
|
|
return gb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
public void UnSpawn(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (!pool.Contains(obj))
|
|
|
|
|
{
|
|
|
|
|
pool.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
obj.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public void UnSpawnAll()
|
|
|
|
|
{
|
|
|
|
|
foreach (GameObject obj in pool)
|
|
|
|
|
{
|
|
|
|
|
if (obj.activeInHierarchy)
|
|
|
|
|
{
|
|
|
|
|
obj.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
public bool Contains(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
return pool.Contains(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|