Update ObjectPool And MenPool

This commit is contained in:
ALEXTANG
2022-08-03 19:26:02 +08:00
parent f1322f0a76
commit b0021b3bf0
3 changed files with 12 additions and 15 deletions

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Diagnostics;
using Debug = UnityEngine.Debug;
namespace TEngine
{
@@ -10,22 +9,16 @@ namespace TEngine
void Destroy();
}
public interface MemPoolBase
public interface IMemPoolBase
{
string GetName();
int GetPoolItemCount();
void ClearPool();
}
public class MemPool
{
}
public class MemPoolMgr : TSingleton<MemPoolMgr>
{
List<MemPoolBase> m_listPool = new List<MemPoolBase>();
List<IMemPoolBase> m_listPool = new List<IMemPoolBase>();
[Conditional("UNITY_EDITOR")]
public void ShowCount()
@@ -35,12 +28,12 @@ namespace TEngine
{
var pool = m_listPool[i];
totalCnt += pool.GetPoolItemCount();
TLogger.LogInfo("[pool][{0}] [{1}]", pool.GetName(), pool.GetPoolItemCount());
TLogger.LogInfoSuccessd("[pool][{0}] [{1}]", pool.GetName(), pool.GetPoolItemCount());
}
TLogger.LogInfo("-------------------------memory pool count: {0}", totalCnt);
TLogger.LogInfoSuccessd("-------------------------memory pool count: {0}", totalCnt);
}
public void RegMemPool(MemPoolBase pool)
public void RegMemPool(IMemPoolBase pool)
{
m_listPool.Add(pool);
}
@@ -55,7 +48,7 @@ namespace TEngine
}
}
public class GameMemPool<T> : TSingleton<GameMemPool<T>>, MemPoolBase where T : IMemPoolObject, new()
public class GameMemPool<T> : TSingleton<GameMemPool<T>>, IMemPoolBase where T : IMemPoolObject, new()
{
private List<T> m_objPool = new List<T>();

View File

@@ -3,7 +3,11 @@ using UnityEngine.Events;
namespace TEngine
{
public static class ListPool<T>
/// <summary>
/// 对象池管理器
/// </summary>
/// <typeparam name="T"></typeparam>
public static class ObjectPoolMgr<T>
{
private static readonly ObjectPool<List<T>> m_ListPool = new ObjectPool<List<T>>(null, Clear);

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: ce3d838c8607a1442acaee8b2ff1b7af
guid: 521d4cc35b3e9d84d9ad2e5de2c4cc09
MonoImporter:
externalObjects: {}
serializedVersion: 2