mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update GameObjectHelper.cs
This commit is contained in:
@@ -8,6 +8,12 @@ namespace TEngine.Runtime
|
|||||||
{
|
{
|
||||||
private readonly Dictionary<string, PoolData> _poolDictionary = new Dictionary<string, PoolData>();
|
private readonly Dictionary<string, PoolData> _poolDictionary = new Dictionary<string, PoolData>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册对象池
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectName">对象池名称</param>
|
||||||
|
/// <param name="ret">注册的GameObject</param>
|
||||||
|
/// <param name="capacity">容量</param>
|
||||||
public void RegisterPool(string objectName, GameObject ret, int capacity = 100)
|
public void RegisterPool(string objectName, GameObject ret, int capacity = 100)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(objectName))
|
if (_poolDictionary.ContainsKey(objectName))
|
||||||
@@ -20,6 +26,11 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 注册对象池
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ret">注册的GameObject</param>
|
||||||
|
/// <param name="capacity">容量</param>
|
||||||
public void RegisterPool(GameObject ret, int capacity = 100)
|
public void RegisterPool(GameObject ret, int capacity = 100)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(ret.name))
|
if (_poolDictionary.ContainsKey(ret.name))
|
||||||
@@ -32,6 +43,12 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从对象池获取物体,没有对象池则直接实例化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectName"></param>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public GameObject Get(string objectName, Action<GameObject> callback = null)
|
public GameObject Get(string objectName, Action<GameObject> callback = null)
|
||||||
{
|
{
|
||||||
GameObject ret = null;
|
GameObject ret = null;
|
||||||
@@ -51,6 +68,11 @@ namespace TEngine.Runtime
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从对象池异步获取,没有对象池则直接实例化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectName"></param>
|
||||||
|
/// <param name="callback"></param>
|
||||||
public void GetAsync(string objectName, Action<GameObject> callback)
|
public void GetAsync(string objectName, Action<GameObject> callback)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(objectName) && _poolDictionary[objectName].Count > 0)
|
if (_poolDictionary.ContainsKey(objectName) && _poolDictionary[objectName].Count > 0)
|
||||||
@@ -68,6 +90,11 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压入对象池,没有对象池则创建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectName"></param>
|
||||||
|
/// <param name="ret"></param>
|
||||||
public void Push(string objectName, GameObject ret)
|
public void Push(string objectName, GameObject ret)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(objectName))
|
if (_poolDictionary.ContainsKey(objectName))
|
||||||
@@ -80,6 +107,10 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 压入对象池,没有对象池则创建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ret"></param>
|
||||||
public void Push(GameObject ret)
|
public void Push(GameObject ret)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(ret.name))
|
if (_poolDictionary.ContainsKey(ret.name))
|
||||||
@@ -91,7 +122,11 @@ namespace TEngine.Runtime
|
|||||||
_poolDictionary.Add(ret.name, new PoolData(ret, this.gameObject));
|
_poolDictionary.Add(ret.name, new PoolData(ret, this.gameObject));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 释放对象池
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="objectName"></param>
|
||||||
public void Release(string objectName)
|
public void Release(string objectName)
|
||||||
{
|
{
|
||||||
if (_poolDictionary.ContainsKey(objectName))
|
if (_poolDictionary.ContainsKey(objectName))
|
||||||
@@ -104,6 +139,9 @@ namespace TEngine.Runtime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 清理所有池子(建议切换场景使用)
|
||||||
|
/// </summary>
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
_poolDictionary.Clear();
|
_poolDictionary.Clear();
|
||||||
|
Reference in New Issue
Block a user