ManaReso.cs 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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.GetComponentInChildren<ADChest>(true);
  460. if (chest == null)
  461. {
  462. chest = tra.GetChild(0).AddComponent<ADChest>();
  463. chest.Initialize(tra.position.y, false, false);
  464. }
  465. else
  466. {
  467. chest.Initialize(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.GetComponentInChildren<PlazaRoomChest>(true);
  475. if (chest == null)
  476. {
  477. chest = tra.GetChild(0).AddComponent<PlazaRoomChest>();
  478. }
  479. return chest;
  480. }
  481. public static Drop GetDrop(ObjType objType)
  482. {
  483. ManaAudio.PlayClip(Clip.DropClip);
  484. Vector3 leftPos = Get("MiniLeft").position;
  485. Vector3 rightPos;
  486. if (ManaMiniGame.GameA || ManaMiniGame.GameC)
  487. {
  488. rightPos = Get("MiniRight1").position;
  489. }
  490. else
  491. {
  492. rightPos = Get("MiniRight2").position;
  493. }
  494. Vector3 pos = Vector3.Lerp(leftPos, rightPos, Random.Range(0, 1f));
  495. Transform tra;
  496. if (objType == ObjType.DropGold)
  497. {
  498. tra = Get(objType.ToString(), Folder.Scene, false, null, pos, objType, typeof(DropGold));
  499. }
  500. else if(objType == ObjType.DropDiamond)
  501. {
  502. tra = Get(objType.ToString(), Folder.Scene, false, null, pos, objType, typeof(DropDiamond));
  503. }
  504. else
  505. {
  506. throw new Exception();
  507. }
  508. Drop drop = tra.GetComponent<Drop>();
  509. drop.RegistImmed();
  510. drop.ResetStatus();
  511. return drop;
  512. }
  513. public static Flower GetFlower(FlowerInfo flowerInfo, Slot slot, bool collider)
  514. {
  515. Transform tra = Get("Flower", Folder.Scene, false, slot.transform, false, ObjType.Flower, typeof(Flower));
  516. tra.localScale = new Vector3(1, 1, 1);
  517. Flower flower = tra.GetComponent<Flower>();
  518. flower.RegistImmed();
  519. flower.FlowerInfo = flowerInfo;
  520. flower.Slot = slot;
  521. //flower.FlowerIcon.SetActive(true);
  522. //flower.FlowerIcon.SetAlpha(1);
  523. flower.SetShadow();
  524. flower.SetCollider(collider);
  525. return flower;
  526. }
  527. public static Flower GetFlower(FlowerInfo flowerInfo, Transform par)
  528. {
  529. Transform tra = Get("Flower", Folder.Scene, false, par, false, ObjType.Flower, typeof(Flower));
  530. tra.localScale = new Vector3(1, 1, 1);
  531. Flower flower = tra.GetComponent<Flower>();
  532. flower.RegistImmed();
  533. flower.FlowerInfo = flowerInfo;
  534. //flower.FlowerIcon.SetActive(true);
  535. //flower.FlowerIcon.SetAlpha(1);
  536. flower.SetShadow();
  537. flower.SetCollider(false);
  538. return flower;
  539. }
  540. public static TextPlus GetInfoItem(string infoItemName, Transform parent, ObjType objType)
  541. {
  542. Transform tra = Get(infoItemName, Folder.UI, false, parent, false, objType);
  543. TextPlus text = tra.GetComponent<TextPlus>();
  544. TweenRoot tween = text.CreateTweenGra(0, 1, 0.25f, true, true, Curve.EaseOutQuad);
  545. tween.OnBackwardFinish = () =>
  546. {
  547. Save(text);
  548. };
  549. return text;
  550. }
  551. 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)
  552. {
  553. Vector3 pos;
  554. if (scene)
  555. {
  556. pos = Camera.main.WorldToScreenPoint(posTra.position);
  557. }
  558. else
  559. {
  560. pos = posTra.position;
  561. }
  562. Transform tra = Get("HudText", Folder.UI, false, parTra, pos, ObjType.HudText, typeof(HudText));
  563. HudText hudText = tra.GetComponent<HudText>();
  564. hudText.Show(str, color, size, speed, time, stay);
  565. return hudText;
  566. }
  567. public static Ranktem GetRanktem(string rank, string praise, string serialNumber)
  568. {
  569. Transform tra = Get("RankItem", Folder.UI, false, Get("S_Grid"), false, ObjType.RankItem, typeof(Ranktem));
  570. Ranktem ranktem = tra.GetComponent<Ranktem>();
  571. ranktem.RegistImmed();
  572. ranktem.Reset(rank, praise, serialNumber);
  573. return ranktem;
  574. }
  575. public static CommentItem GetCommentItem(string nickname, string serialNumber, string content)
  576. {
  577. Transform tra = Get("CommentItem", Folder.UI, false, Get("Q_Grid"), false, ObjType.CommentItem, typeof(CommentItem));
  578. CommentItem commentItem = tra.GetComponent<CommentItem>();
  579. commentItem.RegistImmed();
  580. commentItem.Reset(nickname, serialNumber, content);
  581. return commentItem;
  582. }
  583. public static Transform GetElf(Flower flower, Vector4 offset, ElfType elfType)
  584. {
  585. Transform tra;
  586. Bounds bounds = flower.FlowerIcon.bounds;
  587. Vector3 pos = flower.FlowerIcon.transform.position + new Vector3(0, 0, -5f);
  588. Transform par = flower.transform;
  589. ObjType obj = elfType.ToString().Split('_')[0].ToEnum<ObjType>();
  590. pos.z -= Random.Range(0.001f, 0.1f);
  591. tra = Get(obj.ToString(), Folder.Scene, false, par, pos, obj);
  592. Elf elf = tra.GetChild(0).GetComponent<Elf>();
  593. if (elf == null)
  594. {
  595. elf = tra.GetChild(0).AddScript<Elf>();
  596. }
  597. tra.GetComponentInChildren<SpriteRenderer>().sprite = LoadSprite(elfType.ToString(), Folder.Atlas2);
  598. if (Random.Range(0f, 1f) <= 0.5f)
  599. {
  600. tra.SetEY(180);
  601. }
  602. else
  603. {
  604. tra.SetEY(0);
  605. }
  606. float offsetX = Mathf.Lerp(offset.x*bounds.extents.x, offset.y*bounds.extents.x, Random.Range(0f, 1f));
  607. float offsetY = Mathf.Lerp(offset.z, offset.w*bounds.extents.y, Random.Range(0f, 1f));
  608. tra.position += new Vector3(offsetX, offsetY, 0);
  609. elf.Flower = flower;
  610. elf.Animator.SetTrigger("Play");
  611. return tra;
  612. }
  613. public static Transform GetSkillItem(SkillRoot skillRoot)
  614. {
  615. Transform tra;
  616. if (skillRoot.SkillTab == SkillTab.Elf)
  617. {
  618. tra = Get("SkillItem", Folder.UI, false, Get("Fd_Grid"), false, ObjType.SkillItem);
  619. }
  620. else if (skillRoot.SkillTab == SkillTab.Store)
  621. {
  622. tra = Get("SkillItem", Folder.UI, false, Get("Fc_Grid"), false, ObjType.SkillItem);
  623. }
  624. else if (skillRoot.SkillTab == SkillTab.Magic)
  625. {
  626. tra = Get("SkillItem", Folder.UI, false, Get("Fb_Grid"), false, ObjType.SkillItem);
  627. }
  628. else if (skillRoot.SkillTab == SkillTab.Garden)
  629. {
  630. tra = Get("SkillItem", Folder.UI, false, Get("Fa_Grid"), false, ObjType.SkillItem);
  631. }
  632. else
  633. {
  634. throw new Exception();
  635. }
  636. skillRoot.SkillItem = tra;
  637. return tra;
  638. }
  639. public static Transform GetAchieveItem()
  640. {
  641. Transform tra = Get("AchieveItem", Folder.UI, false, ManaReso.Get("M_Grid"), false, ObjType.AchieveItem);
  642. return tra;
  643. }
  644. public static ParticleSystem GetFirework(Vector3 pos)
  645. {
  646. Transform tra = Get("Firework", Folder.Effect, false, null, pos, ObjType.Firework, typeof(Effect));
  647. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  648. particle.Play();
  649. return particle;
  650. }
  651. public static ParticleSystem GetLightwall()
  652. {
  653. Transform tra = Get("LightwallUI", Folder.Effect, false, Get("Canvas"), false, ObjType.LightwallUI, typeof(Effect));
  654. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  655. if(particle != null)
  656. particle.Play();
  657. return particle;
  658. }
  659. public static void AsyncLoad<T>(string goName, Folder folder, UnityAction callback = null)
  660. {
  661. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  662. AssetBundleRequest bundleRequest = Bundle.LoadAsync<T>(goName, folder);
  663. AsyncRequest asyncRequest = new AsyncRequest();
  664. asyncRequest.Request = bundleRequest;
  665. asyncRequest.Callback = callback;
  666. kv.Key = asyncRequest;
  667. kv.Value = () =>
  668. {
  669. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  670. };
  671. RequestList.Add(bundleRequest);
  672. InstantiateList.Add(kv);
  673. }
  674. public static void AsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  675. {
  676. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  677. AssetBundleRequest bundleRequest = Bundle.LoadAsync<object>(goName, folder);
  678. AsyncRequest asyncRequest = new AsyncRequest();
  679. asyncRequest.Request = bundleRequest;
  680. asyncRequest.Callback = callback;
  681. kv.Key = asyncRequest;
  682. kv.Value = () =>
  683. {
  684. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  685. if (objType != ObjType.Null)
  686. {
  687. ObjectPool.UniqueAdd(objType, new List<Transform>());
  688. }
  689. GameObject go;
  690. if (ui)
  691. {
  692. go = (GameObject)Instantiate(bundleRequest.asset, GameObject.Find("ManagerGame").transform.GetChild(0).GetChild(0));
  693. }
  694. else
  695. {
  696. go = (GameObject)Instantiate(bundleRequest.asset);
  697. }
  698. ObjPoolDic.Add(go, objType);
  699. go.name = go.name.Replace("(Clone)", "");
  700. Save(go);
  701. if (ui)
  702. {
  703. go.SetParent(GameObject.Find("ManagerGame").transform.GetChild(0).GetChild(0));
  704. }
  705. };
  706. RequestList.Add(bundleRequest);
  707. for (int i = 0; i < amt; i++)
  708. {
  709. InstantiateList.Add(kv);
  710. }
  711. }
  712. public static void AddAsyncLoad<T>(string goName, Folder folder, UnityAction callback = null)
  713. {
  714. AsyncList.Add
  715. (
  716. () =>
  717. {
  718. AsyncLoad<T>(goName, folder, callback);
  719. }
  720. );
  721. }
  722. public static void AddAsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  723. {
  724. AsyncList.Add
  725. (
  726. () =>
  727. {
  728. AsyncLoad(goName, amt, folder, objType, ui, canvas, callback);
  729. }
  730. );
  731. }
  732. public void StopAsync()
  733. {
  734. StopCoroutine(CoroLoad);
  735. StopCoroutine(CoroInstantiate);
  736. }
  737. public static IEnumerator IAsyncLoad()
  738. {
  739. while (true)
  740. {
  741. if (RequestList.Count > 0)
  742. {
  743. yield return null;
  744. }
  745. else
  746. {
  747. if (AsyncList.Valid() && !AsyncLoadLock)
  748. {
  749. AsyncLoadLock = true;
  750. Auxiliary.Instance.DelayCall
  751. (
  752. () =>
  753. {
  754. AsyncLoadLock = false;
  755. AsyncList[0].SafeInvoke();
  756. AsyncList.RemoveAt(0);
  757. },
  758. 1
  759. );
  760. yield return null;
  761. }
  762. else
  763. {
  764. yield return null;
  765. }
  766. }
  767. }
  768. }
  769. public static IEnumerator IAsyncInstancitate()
  770. {
  771. while (true)
  772. {
  773. if (AsyncInstantiateLock)
  774. {
  775. yield return null;
  776. }
  777. if (!InstantiateList.Valid())
  778. {
  779. yield return null;
  780. }
  781. else
  782. {
  783. if (Time.deltaTime > 0.333f)
  784. {
  785. yield return null;
  786. }
  787. if (!InstantiateList[0].Key.Request.isDone)
  788. {
  789. yield return null;
  790. }
  791. else
  792. {
  793. InstantiateList[0].Key.Callback.SafeInvoke();
  794. RequestList.Remove(InstantiateList[0].Key.Request);
  795. UnityAction action = InstantiateList[0].Value;
  796. InstantiateList.RemoveAt(0);
  797. AsyncInstantiateLock = true;
  798. Auxiliary.Instance.DelayCall
  799. (
  800. () =>
  801. {
  802. if (!Logo.Complete)
  803. {
  804. action.SafeInvoke();
  805. AsyncInstantiateLock = false;
  806. }
  807. },
  808. 1
  809. );
  810. yield return null;
  811. }
  812. }
  813. }
  814. }
  815. }