GObjectPool.cs 25 KB

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