ManaReso.cs 24 KB

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