ManaReso.cs 26 KB

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