111 lines
2.8 KiB
C#
111 lines
2.8 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public class CachePoolManager:MBSingletonManager<CachePoolManager>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Dictionary<string, List<GameObject>> objDic = new Dictionary<string, List<GameObject>>();
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public Dictionary<string, Transform> nodes = new Dictionary<string, Transform>();
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// ȡ<><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj"><3E><><EFBFBD><EFBFBD></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public GameObject Take(GameObject obj)
|
|||
|
|
{
|
|||
|
|
GameObject recordingObj = null;
|
|||
|
|
|
|||
|
|
if (objDic.ContainsKey(obj.name) && objDic[obj.name].Count > 0)
|
|||
|
|
{
|
|||
|
|
recordingObj = objDic[obj.name][0];
|
|||
|
|
objDic[obj.name].RemoveAt(0);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
recordingObj = GameObject.Instantiate(obj);
|
|||
|
|
}
|
|||
|
|
recordingObj.transform.SetParent(null);
|
|||
|
|
recordingObj.name = obj.name;
|
|||
|
|
recordingObj.gameObject.SetActive(true);
|
|||
|
|
|
|||
|
|
return recordingObj;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Ԥ<><D4A4><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void Prestrain(GameObject obj,int number)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < number; i++)
|
|||
|
|
{
|
|||
|
|
GameObject recordingObj = GameObject.Instantiate(obj);
|
|||
|
|
Put(recordingObj);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="obj"><3E><><EFBFBD><EFBFBD></param>
|
|||
|
|
public void Put(GameObject obj)
|
|||
|
|
{
|
|||
|
|
string name = obj.name;
|
|||
|
|
obj.gameObject.SetActive(false);
|
|||
|
|
if (objDic.ContainsKey(name))
|
|||
|
|
{
|
|||
|
|
objDic[name].Add(obj);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
objDic.Add(name, new List<GameObject>() { obj });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (nodes.ContainsKey(obj.name))
|
|||
|
|
{
|
|||
|
|
obj.transform.SetParent(nodes[obj.name]);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
GameObject node = new GameObject(obj.name);
|
|||
|
|
node.transform.SetParent(this.transform);
|
|||
|
|
obj.transform.SetParent(node.transform);
|
|||
|
|
node.transform.localPosition = Vector3.zero;
|
|||
|
|
node.transform.localScale = Vector3.one;
|
|||
|
|
nodes.Add(obj.name, node.transform);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
public void Clear()
|
|||
|
|
{
|
|||
|
|
StartCoroutine(IE_Destroy());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><><EFBFBD>յ<EFBFBD>Э<EFBFBD><D0AD>
|
|||
|
|
/// </summary>
|
|||
|
|
private IEnumerator IE_Destroy()
|
|||
|
|
{
|
|||
|
|
for (int i = this.transform.childCount-1; i >=0; i--)
|
|||
|
|
{
|
|||
|
|
Destroy(this.transform.GetChild(i).gameObject);
|
|||
|
|
yield return null;
|
|||
|
|
}
|
|||
|
|
objDic.Clear();
|
|||
|
|
nodes.Clear();
|
|||
|
|
}
|
|||
|
|
}
|