diff --git a/Assets/TEngine/Scripts/Runtime/GameObjectHelper/GameObjectHelper.cs b/Assets/TEngine/Scripts/Runtime/GameObjectHelper/GameObjectHelper.cs index 92c5cc95..db88c151 100644 --- a/Assets/TEngine/Scripts/Runtime/GameObjectHelper/GameObjectHelper.cs +++ b/Assets/TEngine/Scripts/Runtime/GameObjectHelper/GameObjectHelper.cs @@ -8,6 +8,12 @@ namespace TEngine.Runtime { private readonly Dictionary _poolDictionary = new Dictionary(); + /// + /// 注册对象池 + /// + /// 对象池名称 + /// 注册的GameObject + /// 容量 public void RegisterPool(string objectName, GameObject ret, int capacity = 100) { if (_poolDictionary.ContainsKey(objectName)) @@ -20,6 +26,11 @@ namespace TEngine.Runtime } } + /// + /// 注册对象池 + /// + /// 注册的GameObject + /// 容量 public void RegisterPool(GameObject ret, int capacity = 100) { if (_poolDictionary.ContainsKey(ret.name)) @@ -32,6 +43,12 @@ namespace TEngine.Runtime } } + /// + /// 从对象池获取物体,没有对象池则直接实例化 + /// + /// + /// + /// public GameObject Get(string objectName, Action callback = null) { GameObject ret = null; @@ -51,6 +68,11 @@ namespace TEngine.Runtime return ret; } + /// + /// 从对象池异步获取,没有对象池则直接实例化 + /// + /// + /// public void GetAsync(string objectName, Action callback) { if (_poolDictionary.ContainsKey(objectName) && _poolDictionary[objectName].Count > 0) @@ -68,6 +90,11 @@ namespace TEngine.Runtime } } + /// + /// 压入对象池,没有对象池则创建 + /// + /// + /// public void Push(string objectName, GameObject ret) { if (_poolDictionary.ContainsKey(objectName)) @@ -80,6 +107,10 @@ namespace TEngine.Runtime } } + /// + /// 压入对象池,没有对象池则创建 + /// + /// public void Push(GameObject ret) { if (_poolDictionary.ContainsKey(ret.name)) @@ -91,7 +122,11 @@ namespace TEngine.Runtime _poolDictionary.Add(ret.name, new PoolData(ret, this.gameObject)); } } - + + /// + /// 释放对象池 + /// + /// public void Release(string objectName) { if (_poolDictionary.ContainsKey(objectName)) @@ -104,6 +139,9 @@ namespace TEngine.Runtime } } + /// + /// 清理所有池子(建议切换场景使用) + /// public void Clear() { _poolDictionary.Clear();