GObjectPool.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using CombatLibrary.CombatLibrary.CombatCore.Utility;
  5. using Fort23.Core;
  6. #if !COMBAT_SERVER
  7. using UnityEngine;
  8. using Object = UnityEngine.Object;
  9. #endif
  10. namespace Fort23.UTool
  11. {
  12. public class GameObjectQueue
  13. {
  14. public string poolName
  15. {
  16. get { return _poolName; }
  17. }
  18. private bool _isDis;
  19. private string _poolName;
  20. private string _prefabName;
  21. #if !COMBAT_SERVER
  22. /// <summary>
  23. /// 池子的父亲
  24. /// </summary>
  25. private AssetHandle _PoolObjectFather;
  26. public bool isOne;
  27. private readonly List<IGObjectPoolInterface> _usePool = new List<IGObjectPoolInterface>();
  28. private readonly List<IGObjectPoolInterface> _queue = new List<IGObjectPoolInterface>();
  29. private readonly List<IGObjectPoolInterface> _destroyPool = new List<IGObjectPoolInterface>();
  30. private readonly List<IGObjectPoolInterface> _delayHide = new List<IGObjectPoolInterface>();
  31. public int initCopunt;
  32. public void Init(string poolName, string prefabName)
  33. {
  34. _poolName = poolName;
  35. _prefabName = prefabName;
  36. }
  37. public async CTask Enqueue(IGObjectPoolInterface poolInterface, bool isNotAwaitDelay = false)
  38. {
  39. if (poolInterface == null || poolInterface.own == null)
  40. {
  41. return;
  42. }
  43. if (_queue.Contains(poolInterface))
  44. {
  45. return;
  46. }
  47. if (_delayHide.Contains(poolInterface))
  48. {
  49. return;
  50. }
  51. _delayHide.Add(poolInterface);
  52. if (!isNotAwaitDelay)
  53. {
  54. await poolInterface.DelayHide();
  55. }
  56. if (_isDis)
  57. {
  58. return;
  59. }
  60. _delayHide.Remove(poolInterface);
  61. poolInterface.isUse = false;
  62. _usePool.Remove(poolInterface);
  63. if (poolInterface.own != null)
  64. {
  65. poolInterface.DormancyObj();
  66. this._queue.Add(poolInterface);
  67. }
  68. }
  69. public void AddDestroy(IGObjectPoolInterface poolInterface, bool immediately = false)
  70. {
  71. if (poolInterface.own == null)
  72. {
  73. return;
  74. }
  75. if (!_destroyPool.Contains(poolInterface))
  76. {
  77. if (immediately)
  78. {
  79. poolInterface.DestroyTimer = null;
  80. GameObjectDestroyPool.Instance.DestroyObject(poolInterface.own);
  81. }
  82. else
  83. {
  84. TimerComponent.Instance.Remove(poolInterface.DestroyTimer);
  85. poolInterface.DestroyTimer =
  86. TimerComponent.Instance.AddTimer(6000, delegate
  87. {
  88. _destroyPool.Remove(poolInterface);
  89. poolInterface.DestroyTimer = null;
  90. GameObjectDestroyPool.Instance.DestroyObject(poolInterface.own);
  91. });
  92. _destroyPool.Add(poolInterface);
  93. }
  94. }
  95. }
  96. public void DormancyPool()
  97. {
  98. List<IGObjectPoolInterface> alliG = new List<IGObjectPoolInterface>();
  99. IGObjectPoolInterface[] all = _usePool.ToArray();
  100. if (all != null)
  101. {
  102. alliG.AddRange(all);
  103. }
  104. for (int i = 0; i < alliG.Count; i++)
  105. {
  106. IGObjectPoolInterface poolInterface = alliG[i];
  107. Enqueue(poolInterface);
  108. }
  109. // _usePool.Clear();
  110. }
  111. public async CTask Preset<T>(Clock clock, bool isUseSynchronous) where T : IGObjectPoolInterface
  112. {
  113. DormancyPool();
  114. for (int i = 0; i < Count; i++)
  115. {
  116. IGObjectPoolInterface poolInterface = _queue[i];
  117. DisposePoolEntity(poolInterface);
  118. poolInterface.Preset();
  119. }
  120. for (int i = 0; i < _usePool.Count; i++)
  121. {
  122. IGObjectPoolInterface poolInterface = _usePool[i];
  123. DisposePoolEntity(poolInterface);
  124. poolInterface.Preset();
  125. }
  126. for (int i = 0; i < _destroyPool.Count; i++)
  127. {
  128. DisposePoolEntity(_destroyPool[i]);
  129. }
  130. _destroyPool.Clear();
  131. T OBJ = await Dequeue<T>(true, clock, isUseSynchronous);
  132. Enqueue(OBJ, true);
  133. }
  134. private async CTask<AssetHandle> LoadAsset(Clock clock, bool isUseSynchronous)
  135. {
  136. if (AssetBundleLoadManager.Instance != null)
  137. {
  138. CTask<AssetHandle> cTask =
  139. AssetBundleLoadManager.Instance.LoadAssetAsyncTask<GameObject>(_prefabName, clock: clock,
  140. isUseSynchronous: isUseSynchronous);
  141. AssetHandle assetHandle = await cTask;
  142. return assetHandle;
  143. }
  144. return null;
  145. }
  146. public T DequeuForSynchronize<T>(GameObject gameObject, bool isActive) where T : IGObjectPoolInterface
  147. {
  148. if (_queue.Count <= 0)
  149. {
  150. return CreateInstance<T>(isActive, gameObject);
  151. }
  152. if (_destroyPool.Count > 0)
  153. {
  154. for (int i = 0; i < _destroyPool.Count; i++)
  155. {
  156. DisposePoolEntity(_destroyPool[i]);
  157. }
  158. _destroyPool.Clear();
  159. }
  160. for (int i = 0; i < _queue.Count; i++)
  161. {
  162. if (_queue[i].own == null)
  163. {
  164. _queue.RemoveAt(i);
  165. i--;
  166. continue;
  167. }
  168. else
  169. {
  170. IGObjectPoolInterface objectPoolInterface = this._queue[0];
  171. _queue.RemoveAt(0);
  172. UseObject(objectPoolInterface, isActive);
  173. return (T)objectPoolInterface;
  174. }
  175. }
  176. return CreateInstance<T>(isActive, gameObject);
  177. }
  178. public async CTask<T> Dequeue<T>(bool isActive, Clock clock, bool isUseSynchronous)
  179. where T : IGObjectPoolInterface
  180. {
  181. for (int i = 0; i < _queue.Count; i++)
  182. {
  183. if (_queue[i].own == null)
  184. {
  185. _queue.RemoveAt(i);
  186. i--;
  187. continue;
  188. }
  189. else
  190. {
  191. IGObjectPoolInterface objectPoolInterface = this._queue[i];
  192. if (objectPoolInterface.own == null)
  193. {
  194. continue;
  195. }
  196. _queue.RemoveAt(i);
  197. UseObject(objectPoolInterface, isActive);
  198. return (T)objectPoolInterface;
  199. }
  200. }
  201. bool isUsePoolObject = false;
  202. if ((_PoolObjectFather == null || _PoolObjectFather.IsNull()) && !string.IsNullOrEmpty(_prefabName))
  203. {
  204. using (await CoroutineLockComponent.Instance.Wait(poolName, 20000))
  205. {
  206. if (_PoolObjectFather == null)
  207. {
  208. _PoolObjectFather = await LoadAsset(clock, isUseSynchronous);
  209. isUsePoolObject = true;
  210. }
  211. }
  212. }
  213. // if (clock != null && clock.isBreak)
  214. // {
  215. // if (isUsePoolObject)
  216. // {
  217. // Debug.LogError("已打断,但是有初始化数据" + _PoolObjectFather);
  218. // }
  219. // // return default;
  220. // }
  221. if (_queue.Count <= 0)
  222. {
  223. AssetHandle assetHandle = _PoolObjectFather;
  224. if (!isUsePoolObject)
  225. {
  226. assetHandle = await _PoolObjectFather.InstantiateSync(isUseSynchronous);
  227. }
  228. // AssetHandle assetHandle = isUsePoolObject ? _PoolObjectFather : _PoolObjectFather;
  229. return CreateInstance<T>(isActive, assetHandle);
  230. }
  231. if (_destroyPool.Count > 0)
  232. {
  233. for (int i = 0; i < _destroyPool.Count; i++)
  234. {
  235. DisposePoolEntity(_destroyPool[i]);
  236. }
  237. _destroyPool.Clear();
  238. }
  239. AssetHandle assetHandle2 = _PoolObjectFather;
  240. if (!isUsePoolObject)
  241. {
  242. assetHandle2 = await _PoolObjectFather.InstantiateSync(isUseSynchronous);
  243. }
  244. assetHandle2 = await assetHandle2.InstantiateSync(isUseSynchronous);
  245. return CreateInstance<T>(isActive, assetHandle2);
  246. }
  247. private T CreateInstance<T>(bool isActive, AssetHandle assetHandle) where T : IGObjectPoolInterface
  248. {
  249. if (assetHandle == null)
  250. {
  251. return default;
  252. }
  253. T poolInerface = Activator.CreateInstance<T>();
  254. GameObject go = assetHandle.AssetObject<GameObject>();
  255. GameObjectEntity objectEntity = go.GetComponent<GameObjectEntity>();
  256. if (objectEntity == null)
  257. {
  258. objectEntity = go.AddComponent<GameObjectEntity>();
  259. }
  260. objectEntity.IgObjectPoolInterface = poolInerface;
  261. objectEntity.OnDestroyCallBack = DestroyEntity;
  262. poolInerface.SetGameObject(go);
  263. poolInerface.poolObjName = _poolName;
  264. poolInerface.AssetHandle = assetHandle;
  265. UseObject(poolInerface, isActive);
  266. initCopunt++;
  267. return poolInerface;
  268. }
  269. private T CreateInstance<T>(bool isActive, GameObject gameObject) where T : IGObjectPoolInterface
  270. {
  271. if (gameObject == null)
  272. {
  273. return default;
  274. }
  275. T poolInerface = Activator.CreateInstance<T>();
  276. GameObject go = GameObject.Instantiate(gameObject);
  277. GameObjectEntity objectEntity = go.GetComponent<GameObjectEntity>();
  278. if (objectEntity == null)
  279. {
  280. objectEntity = go.AddComponent<GameObjectEntity>();
  281. }
  282. objectEntity.IgObjectPoolInterface = poolInerface;
  283. objectEntity.OnDestroyCallBack = DestroyEntity;
  284. poolInerface.SetGameObject(go);
  285. poolInerface.poolObjName = _poolName;
  286. poolInerface.AssetHandle = null;
  287. UseObject(poolInerface, isActive);
  288. initCopunt++;
  289. return poolInerface;
  290. }
  291. private void DestroyEntity(IGObjectPoolInterface poolInterface)
  292. {
  293. if (poolInterface != null)
  294. {
  295. _queue.Remove(poolInterface);
  296. _usePool.Remove(poolInterface);
  297. }
  298. else
  299. {
  300. return;
  301. }
  302. DisposePoolEntity(poolInterface);
  303. // poolInterface.DormancyObj();
  304. poolInterface.DestroyObj();
  305. poolInterface.AssetHandle?.Release();
  306. if (poolInterface.AssetHandle == _PoolObjectFather)
  307. {
  308. _PoolObjectFather = null;
  309. if (_queue.Count > 0)
  310. {
  311. _PoolObjectFather = _queue[0].AssetHandle;
  312. }
  313. }
  314. if (_queue.Count <= 0 && _usePool.Count <= 0) //池子已经被释放完,把父物体也释掉
  315. {
  316. GObjectPool.Instance.DestroyPool(poolName);
  317. }
  318. }
  319. private void UseObject(IGObjectPoolInterface objectPoolInterface, bool isActive)
  320. {
  321. _usePool.Add(objectPoolInterface);
  322. DisposePoolEntity(objectPoolInterface);
  323. // TimerComponent.Instance.Remove(objectPoolInterface.DestroyTimer);
  324. // GameObjectDestroyPool.Instance.RomoveDestroyObject(objectPoolInterface.own);
  325. objectPoolInterface.isUse = true;
  326. objectPoolInterface.ResetData();
  327. if (isActive)
  328. {
  329. objectPoolInterface.ActiveObj();
  330. }
  331. }
  332. public int Count => this._queue.Count;
  333. public void Dispose()
  334. {
  335. _isDis = true;
  336. for (int i = 0; i < Count; i++)
  337. {
  338. IGObjectPoolInterface poolInterface = _queue[i];
  339. DisposePoolEntity(poolInterface);
  340. if (poolInterface.own != null)
  341. {
  342. GameObjectEntity gameObjectEntity = poolInterface.own.GetComponent<GameObjectEntity>();
  343. if (gameObjectEntity != null)
  344. {
  345. gameObjectEntity.IgObjectPoolInterface = null;
  346. gameObjectEntity.OnDestroyCallBack = null;
  347. }
  348. poolInterface.own.SetActive(false);
  349. poolInterface.DormancyObj();
  350. poolInterface.DestroyObj();
  351. poolInterface.AssetHandle?.Release();
  352. GameObjectDestroyPool.Instance.DestroyObject(poolInterface.own);
  353. }
  354. }
  355. for (int i = 0; i < _delayHide.Count; i++)
  356. {
  357. IGObjectPoolInterface poolInterface = _delayHide[i];
  358. DisposePoolEntity(poolInterface);
  359. if (poolInterface.own != null)
  360. {
  361. GameObjectEntity gameObjectEntity = poolInterface.own.GetComponent<GameObjectEntity>();
  362. if (gameObjectEntity != null)
  363. {
  364. gameObjectEntity.IgObjectPoolInterface = null;
  365. gameObjectEntity.OnDestroyCallBack = null;
  366. }
  367. poolInterface.own.SetActive(false);
  368. poolInterface.DormancyObj();
  369. poolInterface.DestroyObj();
  370. poolInterface.AssetHandle?.Release();
  371. GameObjectDestroyPool.Instance.DestroyObject(poolInterface.own);
  372. }
  373. }
  374. for (int i = 0; i < _usePool.Count; i++)
  375. {
  376. IGObjectPoolInterface poolInterface = _usePool[i];
  377. DisposePoolEntity(poolInterface);
  378. if (poolInterface.own != null)
  379. {
  380. GameObjectEntity gameObjectEntity = poolInterface.own.GetComponent<GameObjectEntity>();
  381. if (gameObjectEntity != null)
  382. {
  383. gameObjectEntity.IgObjectPoolInterface = null;
  384. gameObjectEntity.OnDestroyCallBack = null;
  385. }
  386. poolInterface.own.SetActive(false);
  387. poolInterface.DormancyObj();
  388. poolInterface.DestroyObj();
  389. GameObjectDestroyPool.Instance.DestroyObject(poolInterface.own);
  390. }
  391. }
  392. _PoolObjectFather = null;
  393. _delayHide.Clear();
  394. _queue.Clear();
  395. _destroyPool.Clear();
  396. _usePool.Clear();
  397. }
  398. private void DisposePoolEntity(IGObjectPoolInterface poolInterface)
  399. {
  400. _destroyPool.Remove(poolInterface);
  401. TimerComponent.Instance.Remove(poolInterface.DestroyTimer);
  402. GameObjectDestroyPool.Instance.RomoveDestroyObject(poolInterface.own);
  403. poolInterface.DestroyTimer = null;
  404. }
  405. #endif
  406. }
  407. public class GObjectPool
  408. {
  409. private static GObjectPool _instance;
  410. public static GObjectPool Instance
  411. {
  412. get
  413. {
  414. if (_instance == null)
  415. {
  416. _instance = new GObjectPool();
  417. }
  418. return _instance;
  419. }
  420. }
  421. /// <summary>
  422. /// key是gameObject.name.GetHashCode();
  423. /// </summary>
  424. private readonly Dictionary<string, GameObjectQueue> _dictionary = new Dictionary<string, GameObjectQueue>();
  425. /// <summary>
  426. /// 在ab包里面的东西,都可以通过这个方法获取
  427. /// </summary>
  428. /// <param name="prefabName"></param>
  429. /// <param name="callBack"></param>
  430. /// <param name="clock"></param>
  431. /// <param name="Prestore"></param>
  432. /// <param name="poolName"></param>
  433. /// <typeparam name="T"></typeparam>
  434. /// <returns></returns>
  435. public async CTask<T> FetchAsync<T>(string prefabName, System.Action<T> callBack = null, Clock clock = null,
  436. bool Prestore = false, string poolName = null, bool isUseSynchronous = false)
  437. where T : IGObjectPoolInterface
  438. {
  439. if (!prefabName.Contains(".prefab"))
  440. {
  441. prefabName += ".prefab";
  442. }
  443. T poolInerface = await FetchObjectAsync<T>(prefabName, clock, Prestore, poolName,
  444. isUseSynchronous: isUseSynchronous);
  445. if (Prestore)
  446. {
  447. return default;
  448. }
  449. if (poolInerface == null)
  450. {
  451. return default;
  452. }
  453. if (clock != null && clock.isBreak)
  454. {
  455. Recycle(poolInerface);
  456. return default;
  457. }
  458. callBack?.Invoke(poolInerface);
  459. return poolInerface;
  460. }
  461. private string GetPoolName<T>(string name)
  462. {
  463. return name + typeof(T);
  464. }
  465. #if !COMBAT_SERVER
  466. public T FetchAsyncForGameObject<T>(GameObject gameObject, string poolName
  467. ) where T : IGObjectPoolInterface
  468. {
  469. T poolInerface = Fetch<T>(poolName, gameObject);
  470. if (poolInerface == null)
  471. {
  472. return default;
  473. }
  474. return poolInerface;
  475. }
  476. public T Fetch<T>(string poolName, GameObject gameObject, bool isActive = true) where T : IGObjectPoolInterface
  477. {
  478. string newPoolName = GetPoolName<T>(poolName);
  479. GameObjectQueue gameObjectQueue = null;
  480. if (!this._dictionary.TryGetValue(newPoolName, out gameObjectQueue))
  481. {
  482. gameObjectQueue = EnterPool<T>(newPoolName, null);
  483. }
  484. return gameObjectQueue.DequeuForSynchronize<T>(gameObject, isActive);
  485. }
  486. #endif
  487. private async CTask<T> FetchObjectAsync<T>(string prefabName, Clock clock, bool Prestore, string poolName,
  488. bool isActive = true, bool isUseSynchronous = false) where T : IGObjectPoolInterface
  489. {
  490. #if !COMBAT_SERVER
  491. try
  492. {
  493. GameObjectQueue gameObjectQueue = null;
  494. poolName = poolName == null ? prefabName : poolName;
  495. poolName = GetPoolName<T>(poolName);
  496. // 加一个协程锁,让同时加载资源的时候lock住
  497. // using (await CoroutineLockComponent.Instance.Wait(poolName,20000))
  498. {
  499. if (clock != null && clock.isBreak)
  500. {
  501. return default;
  502. }
  503. if (this._dictionary.TryGetValue(poolName, out gameObjectQueue))
  504. {
  505. if (Prestore)
  506. {
  507. await gameObjectQueue.Preset<T>(clock, isUseSynchronous);
  508. return default;
  509. }
  510. return await gameObjectQueue.Dequeue<T>(isActive, clock, isUseSynchronous);
  511. }
  512. if (!this._dictionary.TryGetValue(poolName, out gameObjectQueue))
  513. {
  514. gameObjectQueue = EnterPool<T>(poolName, prefabName);
  515. }
  516. if (gameObjectQueue == null)
  517. {
  518. return default;
  519. }
  520. if (Prestore)
  521. {
  522. await gameObjectQueue.Preset<T>(clock, isUseSynchronous);
  523. return default;
  524. }
  525. return await gameObjectQueue.Dequeue<T>(isActive, clock, isUseSynchronous);
  526. }
  527. }
  528. catch (Exception e)
  529. {
  530. LogTool.Exception(e);
  531. return default;
  532. }
  533. #else
  534. return default;
  535. #endif
  536. }
  537. #if !COMBAT_SERVER
  538. private Transform _parent;
  539. private GameObjectQueue EnterPool<T>(string poolName, string prefabName) where T : IGObjectPoolInterface
  540. {
  541. if (_parent == null)
  542. {
  543. _parent = new GameObject().transform;
  544. _parent.gameObject.name = "Pool";
  545. }
  546. GameObjectQueue queue = new GameObjectQueue();
  547. queue.Init(poolName, prefabName);
  548. _dictionary.Add(poolName, queue);
  549. return queue;
  550. }
  551. #endif
  552. public void Recycle(IGObjectPoolInterface poolInterface)
  553. {
  554. if (poolInterface == null)
  555. {
  556. return;
  557. }
  558. #if !COMBAT_SERVER
  559. GameObjectQueue queue;
  560. if (!this._dictionary.TryGetValue(poolInterface.poolObjName, out queue))
  561. {
  562. LogTool.Error("不再池子之中 " + poolInterface.poolObjName);
  563. return;
  564. }
  565. queue.Enqueue(poolInterface);
  566. #endif
  567. }
  568. public async CTask Recycle(IGObjectPoolInterface poolInterface, bool isNotAwaitDelay)
  569. {
  570. if (poolInterface == null)
  571. {
  572. return;
  573. }
  574. #if !COMBAT_SERVER
  575. GameObjectQueue queue;
  576. if (!this._dictionary.TryGetValue(poolInterface.poolObjName, out queue))
  577. {
  578. LogTool.Error("不再池子之中 " + poolInterface.poolObjName);
  579. return;
  580. }
  581. await queue.Enqueue(poolInterface, isNotAwaitDelay);
  582. #endif
  583. }
  584. public void RecycleForDestroy(IGObjectPoolInterface poolInterface, bool immediately = false)
  585. {
  586. if (poolInterface == null)
  587. {
  588. return;
  589. }
  590. #if !COMBAT_SERVER
  591. GameObjectQueue queue;
  592. if (!this._dictionary.TryGetValue(poolInterface.poolObjName, out queue))
  593. {
  594. LogTool.Error("不再池子之中 " + poolInterface.poolObjName);
  595. return;
  596. }
  597. queue.Enqueue(poolInterface);
  598. queue.AddDestroy(poolInterface, immediately);
  599. #endif
  600. }
  601. public void DestroyPool(string poolObjName)
  602. {
  603. #if !COMBAT_SERVER
  604. GameObjectQueue queue;
  605. if (!this._dictionary.TryGetValue(poolObjName, out queue))
  606. {
  607. // LogTool.Warning("没有这个池子 " + poolObjName);
  608. return;
  609. }
  610. _dictionary.Remove(poolObjName);
  611. queue.Dispose();
  612. #endif
  613. }
  614. /// <summary>
  615. /// 休眠一个池子
  616. /// </summary>
  617. /// <param name="poolName"></param>
  618. public void DormancyPool<T>(string poolName)
  619. {
  620. #if !COMBAT_SERVER
  621. GameObjectQueue queue;
  622. if (!this._dictionary.TryGetValue(poolName, out queue))
  623. {
  624. string poolObjName = GetPoolName<T>(poolName);
  625. if (!this._dictionary.TryGetValue(poolObjName, out queue))
  626. {
  627. // LogTool.Warning("没有这个池子 " + poolObjName);
  628. return;
  629. }
  630. }
  631. queue?.DormancyPool();
  632. #endif
  633. }
  634. /// <summary>
  635. /// 清除所有池子
  636. /// </summary>
  637. public void Clear()
  638. {
  639. Dispose();
  640. }
  641. /// <summary>
  642. /// 清除所有池子
  643. /// </summary>
  644. public void Dispose()
  645. {
  646. #if !COMBAT_SERVER
  647. foreach (KeyValuePair<string, GameObjectQueue> kv in this._dictionary)
  648. {
  649. kv.Value.Dispose();
  650. }
  651. this._dictionary.Clear();
  652. _instance = null;
  653. #endif
  654. }
  655. }
  656. }