ManaReso.cs 26 KB

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