1 Star 0 Fork 1

zzjldc/UnityCommon

forked from icedRabbit/UnityCommon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
BasePool.cs 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
sun 提交于 2023-11-08 21:29 . init
using UnityEngine;
using UnityEngine.Pool;
public class BasePool<T> : MonoBehaviour where T : Component
{
[SerializeField] protected T prefab;
[SerializeField] int defaultSize = 100;
[SerializeField] int maxSize = 500;
ObjectPool<T> pool;
public int ActiveCount => pool.CountActive;
public int InactiveCount => pool.CountInactive;
public int TotalCount => pool.CountAll;
protected void Initialize(bool collectionCheck = true) =>
pool = new ObjectPool<T>(OnCreatePoolItem, OnGetPoolItem, OnReleasePoolItem, OnDestroyPoolItem, collectionCheck, defaultSize, maxSize);
protected virtual T OnCreatePoolItem() => Instantiate(prefab, transform);
protected virtual void OnGetPoolItem(T obj) => obj.gameObject.SetActive(true);
protected virtual void OnReleasePoolItem(T obj) => obj.gameObject.SetActive(false);
protected virtual void OnDestroyPoolItem(T obj) => Destroy(obj.gameObject);
public T Get() => pool.Get();
public void Release(T obj) => pool.Release(obj);
public void Clear() => pool.Clear();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zzjldc/unity-common.git
git@gitee.com:zzjldc/unity-common.git
zzjldc
unity-common
UnityCommon
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385