ManaReso.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Collections;
  6. using System.Linq.Expressions;
  7. using System.ComponentModel;
  8. using System.Collections.Generic;
  9. using Object = UnityEngine.Object;
  10. using Random = UnityEngine.Random;
  11. using Component = UnityEngine.Component;
  12. public enum Folder
  13. {
  14. UI,
  15. Atlas,
  16. Effect,
  17. Audio,
  18. Scene,
  19. Config,
  20. }
  21. public enum ObjType
  22. {
  23. Null,
  24. Firework,
  25. LightwallUI,
  26. PlayerPink,
  27. PlayerBlond,
  28. PlayerBrown,
  29. Page,
  30. Flower,
  31. Garden,
  32. Tutorial,
  33. Canvas,
  34. GroupA,
  35. GroupB,
  36. GroupC,
  37. GroupD,
  38. EventSystem,
  39. MainCamera,
  40. HudText,
  41. SkillItem,
  42. SignItem,
  43. FlowerItem,
  44. AchieveItem,
  45. Music,
  46. DropGold,
  47. DropDiamond,
  48. BeeRed,
  49. BeeBlue,
  50. BeeWhite,
  51. BeePurple,
  52. BeeYellow,
  53. ButterflyRed,
  54. ButterflyBlue,
  55. ButterflyWhite,
  56. ButterflyPurple,
  57. ButterflyYellow,
  58. }
  59. public class AsyncRequest
  60. {
  61. public UnityAction Callback;
  62. public AssetBundleRequest Request;
  63. }
  64. public class ManaReso : Regist
  65. {
  66. #region 变量
  67. public static bool AsyncLoadLock;
  68. public static bool AsyncInstantiateLock;
  69. public static Coroutine CoroLoad;
  70. public static Coroutine CoroInstantiate;
  71. public static ManaReso Instance;
  72. public static List<UnityAction> AsyncList = new List<UnityAction>();
  73. public static List<AssetBundleRequest> RequestList = new List<AssetBundleRequest>();
  74. public static List<KV<AsyncRequest, UnityAction>> InstantiateList = new List<KV<AsyncRequest, UnityAction>>();
  75. public static Dictionary<string, Object> ObjDic = new Dictionary<string, Object>();
  76. public static Dictionary<string, Transform> TraDic = new Dictionary<string, Transform>();
  77. public static Dictionary<GameObject, ObjType> ObjPoolDic = new Dictionary<GameObject, ObjType>();
  78. public static Dictionary<ObjType, List<Transform>> ObjectPool = new Dictionary<ObjType, List<Transform>>();
  79. #endregion
  80. public override void RegistImmed()
  81. {
  82. Instance = this;
  83. Transform objPool = new GameObject("ObjPool").transform;
  84. objPool.parent = transform;
  85. objPool.SetActive(false);
  86. TraDic.Add(objPool.name, objPool);
  87. CoroLoad = StartCoroutine(IAsyncLoad());
  88. CoroInstantiate = StartCoroutine(IAsyncInstancitate());
  89. }
  90. #region TraDic
  91. public static T Get<T>(string goName, bool warn = true)
  92. {
  93. Transform tra;
  94. if (TraDic.TryGetValue(goName, out tra))
  95. {
  96. T t = tra.GetComponent<T>();
  97. if (t == null)
  98. {
  99. throw new Exception(goName);
  100. }
  101. return t;
  102. }
  103. else
  104. {
  105. if (warn)
  106. {
  107. throw new Exception(goName);
  108. }
  109. else
  110. {
  111. return default(T);
  112. }
  113. }
  114. }
  115. public static T[] Gets<T>(string goName, bool warn = true)
  116. {
  117. Transform tra;
  118. if (TraDic.TryGetValue(goName, out tra))
  119. {
  120. T[] t = tra.GetComponentsInChildren<T>();
  121. if (t == null)
  122. {
  123. throw new Exception(goName);
  124. }
  125. return t;
  126. }
  127. else
  128. {
  129. if (warn)
  130. {
  131. throw new Exception(goName);
  132. }
  133. else
  134. {
  135. return default(T[]);
  136. }
  137. }
  138. }
  139. public static Transform Get(string goName, bool warn = true)
  140. {
  141. Transform tra;
  142. if (TraDic.TryGetValue(goName, out tra))
  143. {
  144. return tra;
  145. }
  146. else
  147. {
  148. if (warn)
  149. {
  150. throw new Exception(goName);
  151. }
  152. else
  153. {
  154. return null;
  155. }
  156. }
  157. }
  158. #endregion
  159. #region ObjPool
  160. public static void Release()
  161. {
  162. //ObjDic = new Dictionary<string, Object>();
  163. //Bundle.UI.Unload(true);
  164. //Bundle.Effect.Unload(true);
  165. //Bundle.Audio.Unload(true);
  166. //Bundle.Scene.Unload(true);
  167. //Bundle.Config.Unload(true);
  168. }
  169. public static void Save<T>(T t, bool warn = false) where T : Component
  170. {
  171. Save(t.gameObject);
  172. }
  173. public static void Save(GameObject go, bool warn = false)
  174. {
  175. ObjType objType;
  176. if (!ObjPoolDic.TryGetValue(go, out objType))
  177. {
  178. throw new Exception();
  179. }
  180. List<Transform> traList;
  181. if (ObjectPool.TryGetValue(objType, out traList))
  182. {
  183. if (traList.Contains(go.transform))
  184. {
  185. if (warn)
  186. {
  187. return;
  188. }
  189. else
  190. {
  191. throw new Exception();
  192. }
  193. }
  194. go.SetActive(false);
  195. traList.Add(go.transform);
  196. go.transform.SetParent(Get("ObjPool"));
  197. }
  198. else
  199. {
  200. throw new Exception();
  201. }
  202. }
  203. public static bool Contains<T>(T t) where T : Component
  204. {
  205. return Contains(t.gameObject);
  206. }
  207. public static bool Contains(GameObject go)
  208. {
  209. foreach (var kv in ObjectPool)
  210. {
  211. if (kv.Value.Contains(go.transform))
  212. {
  213. return true;
  214. }
  215. }
  216. return false;
  217. }
  218. public static Transform Get(ObjType objType)
  219. {
  220. List<Transform> traList;
  221. if (ObjectPool.TryGetValue(objType, out traList))
  222. {
  223. if (traList.Count > 0)
  224. {
  225. Transform tra = traList[0];
  226. tra.SetActive(true);
  227. traList.RemoveAt(0);
  228. return tra.transform;
  229. }
  230. }
  231. return null;
  232. }
  233. #endregion
  234. #region ShortCut
  235. public static void SetText(string goName)
  236. {
  237. Text text = Get<Text>(goName);
  238. text.text = Language.GetStr("UI", goName);
  239. }
  240. public static void SetText(string goName, string str)
  241. {
  242. Text text = Get<Text>(goName);
  243. text.text = str;
  244. }
  245. public static void SetSprite(string goName, Sprite sprite)
  246. {
  247. Image image = Get<Image>(goName);
  248. image.sprite = sprite;
  249. }
  250. public static void SetActive(string goName, bool active)
  251. {
  252. Get(goName).SetActive(active);
  253. }
  254. public static void SetButtonEvent(string goName, UnityAction onClick)
  255. {
  256. Button button = Get<Button>(goName);
  257. button.onClick = new Button.ButtonClickedEvent();
  258. button.onClick.AddListener(onClick);
  259. }
  260. public static void AddButtonEvent(string goName, UnityAction onClick)
  261. {
  262. Button button = Get<Button>(goName);
  263. button.onClick.AddListener(onClick);
  264. }
  265. public static void PushButtonEvent(string goName, UnityAction onClick)
  266. {
  267. Button button = Get<Button>(goName);
  268. Button.ButtonClickedEvent click = button.onClick;
  269. button.onClick = new Button.ButtonClickedEvent();
  270. button.onClick.AddListener(onClick);
  271. button.onClick.AddListener(click.Invoke);
  272. }
  273. public static void AddButtonEventOnetime(string goName, UnityAction onClick)
  274. {
  275. Button button = Get<Button>(goName);
  276. onClick += () =>
  277. {
  278. button.onClick.RemoveListener(onClick);
  279. };
  280. button.onClick.AddListener(onClick);
  281. }
  282. public static void PushButtonEventOnetime(string goName, UnityAction onClick)
  283. {
  284. Button button = Get<Button>(goName);
  285. onClick += () =>
  286. {
  287. button.onClick.RemoveListener(onClick);
  288. };
  289. Button.ButtonClickedEvent click = button.onClick;
  290. button.onClick = new Button.ButtonClickedEvent();
  291. button.onClick.AddListener(onClick);
  292. button.onClick.AddListener(click.Invoke);
  293. }
  294. #endregion
  295. public static T Load<T>(string goName, Folder folder, ObjType objType = ObjType.Null) where T : Object
  296. {
  297. Object obj;
  298. if (ObjDic.TryGetValue(goName, out obj))
  299. {
  300. if (objType != ObjType.Null)
  301. {
  302. ObjectPool.UniqueAdd(objType, new List<Transform>());
  303. }
  304. return (T) obj;
  305. }
  306. else
  307. {
  308. T t = Bundle.Load<T>(goName, folder);
  309. if (t == null)
  310. {
  311. throw new Exception(goName);
  312. }
  313. ObjDic.Add(goName, t);
  314. if (objType != ObjType.Null)
  315. {
  316. ObjectPool.UniqueAdd(objType, new List<Transform>());
  317. }
  318. return t;
  319. }
  320. }
  321. public static Sprite LoadSprite(string goName, Folder folder)
  322. {
  323. return Load<Sprite>(goName, folder);
  324. }
  325. public static Transform Get(string goName, Folder folder, bool compile, Transform par, bool worldSpace, ObjType objType = ObjType.Null, Type type = null)
  326. {
  327. Transform tra = Get(objType);
  328. if (tra == null)
  329. {
  330. GameObject go = Load<GameObject>(goName, folder, objType);
  331. go = Instantiate(go, par, worldSpace);
  332. go.name = go.name.Replace("(Clone)", "");
  333. if (compile)
  334. {
  335. Auxiliary.CompileDic(go.transform, TraDic);
  336. }
  337. if (objType != ObjType.Null)
  338. {
  339. ObjPoolDic.Add(go, objType);
  340. }
  341. if (type != null)
  342. {
  343. go.AddComponent(type);
  344. }
  345. return go.transform;
  346. }
  347. else
  348. {
  349. if (compile)
  350. {
  351. Auxiliary.CompileDic(tra, TraDic);
  352. }
  353. GameObject prefab = Load<GameObject>(goName, folder, objType);
  354. tra.SetParent(par);
  355. if (worldSpace)
  356. {
  357. tra.position = prefab.transform.position;
  358. }
  359. else
  360. {
  361. tra.localPosition = prefab.transform.position;
  362. }
  363. if (type != null)
  364. {
  365. if (tra.GetComponent(type) == null)
  366. {
  367. tra.AddComponent(type);
  368. }
  369. }
  370. return tra;
  371. }
  372. }
  373. public static Transform Get(string goName, Folder folder, bool compile, Transform par, Vector3 pos, ObjType objType = ObjType.Null, Type type = null)
  374. {
  375. Transform tra = Get(objType);
  376. if (tra == null)
  377. {
  378. GameObject go = Load<GameObject>(goName, folder, objType);
  379. go = Instantiate(go, pos, Quaternion.identity, par);
  380. go.name = go.name.Replace("(Clone)", "");
  381. if (compile)
  382. {
  383. Auxiliary.CompileDic(go.transform, TraDic);
  384. }
  385. if (objType != ObjType.Null)
  386. {
  387. ObjPoolDic.Add(go, objType);
  388. }
  389. if (type != null)
  390. {
  391. go.AddComponent(type);
  392. }
  393. return go.transform;
  394. }
  395. else
  396. {
  397. if (compile)
  398. {
  399. Auxiliary.CompileDic(tra, TraDic);
  400. }
  401. tra.SetParent(par);
  402. tra.position = pos;
  403. if (type != null)
  404. {
  405. if (tra.GetComponent(type) == null)
  406. {
  407. tra.AddComponent(type);
  408. }
  409. }
  410. return tra;
  411. }
  412. }
  413. public static Drop GetDrop(ObjType objType)
  414. {
  415. ManaAudio.PlayClip(Clip.DropClip);
  416. Vector3 pos = Vector3.Lerp(Get("MiniLeft").position, Get("MiniRight").position, Random.Range(0, 1f));
  417. Transform tra;
  418. if (objType == ObjType.DropGold)
  419. {
  420. tra = Get(objType.ToString(), Folder.UI, false, null, pos, objType, typeof(DropGold));
  421. }
  422. else if(objType == ObjType.DropDiamond)
  423. {
  424. tra = Get(objType.ToString(), Folder.UI, false, null, pos, objType, typeof(DropDiamond));
  425. }
  426. else
  427. {
  428. throw new Exception();
  429. }
  430. Drop drop = tra.GetComponent<Drop>();
  431. drop.RegistImmed();
  432. drop.ResetStatus();
  433. return drop;
  434. }
  435. public static Flower GetFlower(FlowerInfo flowerInfo, Slot slot, bool collider)
  436. {
  437. Transform tra = Get("Flower", Folder.Scene, false, slot.transform, false, ObjType.Flower, typeof(Flower));
  438. tra.localScale = new Vector3(1, 1, 1);
  439. Flower flower = tra.GetComponent<Flower>();
  440. flower.RegistImmed();
  441. flower.FlowerInfo = flowerInfo;
  442. flower.Slot = slot;
  443. flower.SetCollider(collider);
  444. return flower;
  445. }
  446. public static Flower GetFlower(FlowerInfo flowerInfo, Transform par)
  447. {
  448. Transform tra = Get("Flower", Folder.Scene, false, par, false, ObjType.Flower, typeof(Flower));
  449. tra.localScale = new Vector3(1, 1, 1);
  450. Flower flower = tra.GetComponent<Flower>();
  451. flower.RegistImmed();
  452. flower.FlowerInfo = flowerInfo;
  453. flower.SetCollider(false);
  454. return flower;
  455. }
  456. public static HudText GetHudText(string str, Color color, int size, Transform posTra, Transform parTra, bool scene, float speed = 7.5f, float time = 0.5f)
  457. {
  458. Vector3 pos;
  459. if (scene)
  460. {
  461. pos = Camera.main.WorldToScreenPoint(posTra.position);
  462. }
  463. else
  464. {
  465. pos = posTra.position;
  466. }
  467. Transform tra = Get("HudText", Folder.UI, false, parTra, pos, ObjType.HudText, typeof(HudText));
  468. HudText hudText = tra.GetComponent<HudText>();
  469. hudText.Show(str, color, size, speed, time);
  470. return hudText;
  471. }
  472. public static Transform GetElf(Flower flower, Vector4 offset, ObjType obj)
  473. {
  474. Transform tra;
  475. Bounds bounds = flower.FlowerIcon.bounds;
  476. Vector3 pos = flower.FlowerIcon.transform.position;
  477. Transform par = flower.transform;
  478. pos.z -= Random.Range(0.001f, 0.1f);
  479. tra = Get(obj.ToString(), Folder.Scene, false, par, pos, obj);
  480. Elf elf = tra.GetChild(0).GetComponent<Elf>();
  481. if (elf == null)
  482. {
  483. elf = tra.GetChild(0).AddScript<Elf>();
  484. }
  485. if (Random.Range(0f, 1f) <= 0.5f)
  486. {
  487. tra.SetEY(180);
  488. }
  489. else
  490. {
  491. tra.SetEY(0);
  492. }
  493. float offsetX = Mathf.Lerp(offset.x*bounds.extents.x, offset.y*bounds.extents.x, Random.Range(0f, 1f));
  494. float offsetY = Mathf.Lerp(offset.z, offset.w*bounds.extents.y, Random.Range(0f, 1f));
  495. tra.position += new Vector3(offsetX, offsetY, 0);
  496. elf.Flower = flower;
  497. elf.Animator.SetTrigger("Play");
  498. return tra;
  499. }
  500. public static Transform GetSkillItem(SkillRoot skillRoot)
  501. {
  502. Transform tra;
  503. if (skillRoot.SkillTab == SkillTab.Elf)
  504. {
  505. tra = Get("SkillItem", Folder.UI, false, Get("Fd_Grid"), false, ObjType.SkillItem);
  506. }
  507. else if (skillRoot.SkillTab == SkillTab.Store)
  508. {
  509. tra = Get("SkillItem", Folder.UI, false, Get("Fc_Grid"), false, ObjType.SkillItem);
  510. }
  511. else if (skillRoot.SkillTab == SkillTab.Magic)
  512. {
  513. tra = Get("SkillItem", Folder.UI, false, Get("Fb_Grid"), false, ObjType.SkillItem);
  514. }
  515. else if (skillRoot.SkillTab == SkillTab.Garden)
  516. {
  517. tra = Get("SkillItem", Folder.UI, false, Get("Fa_Grid"), false, ObjType.SkillItem);
  518. }
  519. else
  520. {
  521. throw new Exception();
  522. }
  523. skillRoot.SkillItem = tra;
  524. return tra;
  525. }
  526. public static Transform GetAchieveItem()
  527. {
  528. Transform tra = Get("AchieveItem", Folder.UI, false, ManaReso.Get("M_Grid"), false, ObjType.AchieveItem);
  529. return tra;
  530. }
  531. public static ParticleSystem GetFirework(Vector3 pos)
  532. {
  533. Transform tra = Get("Firework", Folder.Effect, false, null, pos, ObjType.Firework, typeof(Effect));
  534. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  535. particle.Play();
  536. return particle;
  537. }
  538. public static ParticleSystem GetLightwall()
  539. {
  540. Transform tra = Get("LightwallUI", Folder.Effect, false, Get("Canvas"), false, ObjType.LightwallUI, typeof(Effect));
  541. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  542. particle.Play();
  543. return particle;
  544. }
  545. public static void AsyncLoad(string goName, Folder folder, UnityAction callback = null)
  546. {
  547. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  548. AssetBundleRequest bundleRequest = Bundle.LoadAsync(goName, folder);
  549. AsyncRequest asyncRequest = new AsyncRequest();
  550. asyncRequest.Request = bundleRequest;
  551. asyncRequest.Callback = callback;
  552. kv.Key = asyncRequest;
  553. kv.Value = () =>
  554. {
  555. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  556. };
  557. RequestList.Add(bundleRequest);
  558. InstantiateList.Add(kv);
  559. }
  560. public static void AsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  561. {
  562. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  563. AssetBundleRequest bundleRequest = Bundle.LoadAsync(goName, folder);
  564. AsyncRequest asyncRequest = new AsyncRequest();
  565. asyncRequest.Request = bundleRequest;
  566. asyncRequest.Callback = callback;
  567. kv.Key = asyncRequest;
  568. kv.Value = () =>
  569. {
  570. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  571. if (objType != ObjType.Null)
  572. {
  573. ObjectPool.UniqueAdd(objType, new List<Transform>());
  574. }
  575. GameObject go;
  576. if (ui)
  577. {
  578. go = (GameObject)Instantiate(bundleRequest.asset, GameObject.Find("ManagerGame").transform.GetChild(0).GetChild(0));
  579. }
  580. else
  581. {
  582. go = (GameObject)Instantiate(bundleRequest.asset);
  583. }
  584. ObjPoolDic.Add(go, objType);
  585. go.name = go.name.Replace("(Clone)", "");
  586. Save(go);
  587. if (ui)
  588. {
  589. go.SetParent(GameObject.Find("ManagerGame").transform.GetChild(0).GetChild(0));
  590. }
  591. };
  592. RequestList.Add(bundleRequest);
  593. for (int i = 0; i < amt; i++)
  594. {
  595. InstantiateList.Add(kv);
  596. }
  597. }
  598. public static void AddAsyncLoad(string goName, Folder folder, UnityAction callback = null)
  599. {
  600. AsyncList.Add
  601. (
  602. () =>
  603. {
  604. AsyncLoad(goName, folder, callback);
  605. }
  606. );
  607. }
  608. public static void AddAsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  609. {
  610. AsyncList.Add
  611. (
  612. () =>
  613. {
  614. AsyncLoad(goName, amt, folder, objType, ui, canvas, callback);
  615. }
  616. );
  617. }
  618. public static void AddAsyncPlayer(string player)
  619. {
  620. AsyncList.Add
  621. (
  622. () =>
  623. {
  624. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  625. AssetBundleRequest bundleRequest = Bundle.LoadAsync("Player", Folder.Scene);
  626. AsyncRequest asyncRequest = new AsyncRequest();
  627. asyncRequest.Request = bundleRequest;
  628. asyncRequest.Callback = null;
  629. kv.Key = asyncRequest;
  630. kv.Value = () =>
  631. {
  632. GameObject go = (GameObject)Instantiate(bundleRequest.asset);
  633. go.name = go.name.Replace("(Clone)", "");
  634. ObjDic.UniqueAdd("Player", bundleRequest.asset);
  635. ObjType objType;
  636. if (player == "PlayerPink")
  637. {
  638. objType = ObjType.PlayerPink;
  639. ObjectPool.Add(objType, new List<Transform>());
  640. go.AddScript<Player>().BuildPink();
  641. ObjPoolDic.Add(go, objType);
  642. }
  643. else if (player == "PlayerBlond")
  644. {
  645. objType = ObjType.PlayerBlond;
  646. ObjectPool.Add(objType, new List<Transform>());
  647. go.AddScript<Player>().BuildBlond();
  648. ObjPoolDic.Add(go, objType);
  649. }
  650. else if(player == "PlayerBrown")
  651. {
  652. objType = ObjType.PlayerBrown;
  653. ObjectPool.Add(objType, new List<Transform>());
  654. go.AddScript<Player>().BuildBrown();
  655. ObjPoolDic.Add(go, objType);
  656. }
  657. else
  658. {
  659. throw new Exception();
  660. }
  661. Save(go);
  662. };
  663. RequestList.Add(bundleRequest);
  664. InstantiateList.Add(kv);
  665. }
  666. );
  667. }
  668. public void StopAsync()
  669. {
  670. StopCoroutine(CoroLoad);
  671. StopCoroutine(CoroInstantiate);
  672. }
  673. public static IEnumerator IAsyncLoad()
  674. {
  675. while (true)
  676. {
  677. if (RequestList.Count > 0)
  678. {
  679. yield return null;
  680. }
  681. else
  682. {
  683. if (AsyncList.Valid() && !AsyncLoadLock)
  684. {
  685. AsyncLoadLock = true;
  686. Auxiliary.Instance.DelayCall
  687. (
  688. () =>
  689. {
  690. AsyncLoadLock = false;
  691. AsyncList[0].SafeInvoke();
  692. AsyncList.RemoveAt(0);
  693. },
  694. 1
  695. );
  696. yield return null;
  697. }
  698. else
  699. {
  700. yield return null;
  701. }
  702. }
  703. }
  704. }
  705. public static IEnumerator IAsyncInstancitate()
  706. {
  707. while (true)
  708. {
  709. if (AsyncInstantiateLock)
  710. {
  711. yield return null;
  712. }
  713. if (!InstantiateList.Valid())
  714. {
  715. yield return null;
  716. }
  717. else
  718. {
  719. if (Time.deltaTime > 0.333f)
  720. {
  721. yield return null;
  722. }
  723. if (!InstantiateList[0].Key.Request.isDone)
  724. {
  725. yield return null;
  726. }
  727. else
  728. {
  729. InstantiateList[0].Key.Callback.SafeInvoke();
  730. RequestList.Remove(InstantiateList[0].Key.Request);
  731. UnityAction action = InstantiateList[0].Value;
  732. InstantiateList.RemoveAt(0);
  733. AsyncInstantiateLock = true;
  734. Auxiliary.Instance.DelayCall
  735. (
  736. () =>
  737. {
  738. action.SafeInvoke();
  739. AsyncInstantiateLock = false;
  740. },
  741. 1
  742. );
  743. yield return null;
  744. }
  745. }
  746. }
  747. }
  748. }