ManaReso.cs 26 KB

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