ManaReso.cs 26 KB

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