ManaReso.cs 24 KB

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