GObjectPool.cs 24 KB

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