ManaReso.cs 26 KB

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