ResourceManager.cs 26 KB

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