mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update ObjectPool And MenPool
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Debug = UnityEngine.Debug;
|
|
||||||
|
|
||||||
namespace TEngine
|
namespace TEngine
|
||||||
{
|
{
|
||||||
@@ -10,22 +9,16 @@ namespace TEngine
|
|||||||
void Destroy();
|
void Destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface MemPoolBase
|
public interface IMemPoolBase
|
||||||
{
|
{
|
||||||
string GetName();
|
string GetName();
|
||||||
int GetPoolItemCount();
|
int GetPoolItemCount();
|
||||||
void ClearPool();
|
void ClearPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MemPool
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class MemPoolMgr : TSingleton<MemPoolMgr>
|
public class MemPoolMgr : TSingleton<MemPoolMgr>
|
||||||
{
|
{
|
||||||
List<MemPoolBase> m_listPool = new List<MemPoolBase>();
|
List<IMemPoolBase> m_listPool = new List<IMemPoolBase>();
|
||||||
|
|
||||||
[Conditional("UNITY_EDITOR")]
|
[Conditional("UNITY_EDITOR")]
|
||||||
public void ShowCount()
|
public void ShowCount()
|
||||||
@@ -35,12 +28,12 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
var pool = m_listPool[i];
|
var pool = m_listPool[i];
|
||||||
totalCnt += pool.GetPoolItemCount();
|
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);
|
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>();
|
private List<T> m_objPool = new List<T>();
|
||||||
|
|
||||||
|
@@ -3,7 +3,11 @@ using UnityEngine.Events;
|
|||||||
|
|
||||||
namespace TEngine
|
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);
|
private static readonly ObjectPool<List<T>> m_ListPool = new ObjectPool<List<T>>(null, Clear);
|
||||||
|
|
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ce3d838c8607a1442acaee8b2ff1b7af
|
guid: 521d4cc35b3e9d84d9ad2e5de2c4cc09
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
Reference in New Issue
Block a user