using System; using System.Collections.Generic; namespace BF { public class PoolManager : ManagerBase { static PoolManager instance; public static PoolManager Create() { BFLog.LogAssert(instance == null, "This method only allows BFMain to call once"); instance = new PoolManager(); instance.Init(); return instance; } private PoolManager() { } public override void Init() { base.Init(); GameObjPool = new GameObjectPool(); } public override void Destroy() { foreach (var item in classPoolDict) { classPoolDict[item.Key].Clear(); } classPoolDict.Clear(); instance = null; } Dictionary classPoolDict = new Dictionary(); public GameObjectPool GameObjPool { get; private set; } public ClassPool GetClassPool(int size = 100) where T : class { var t = typeof(T); classPoolDict.TryGetValue(t, out IObjectPool pool); if (pool == null) { var newPool = ClassPool.Create(size); classPoolDict.Add(t, newPool); return newPool; } return pool as ClassPool; } } }