ManaReso.cs 23 KB

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