ResourceManager.cs 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using UnityEngine.Events;
  4. using System;
  5. using System.Collections;
  6. using System.Linq.Expressions;
  7. using System.ComponentModel;
  8. using System.Collections.Generic;
  9. using Object = UnityEngine.Object;
  10. using Random = UnityEngine.Random;
  11. using Component = UnityEngine.Component;
  12. public enum Folder
  13. {
  14. UI,
  15. Atlas,
  16. Atlas2,
  17. Effect,
  18. Audio,
  19. Scene,
  20. Config,
  21. Discard,
  22. PlazaRoom,
  23. }
  24. public enum ObjType
  25. {
  26. Null,
  27. Firework,
  28. LightwallUI,
  29. Player,
  30. Page,
  31. Flower,
  32. Garden,
  33. Tutorial,
  34. CloseItem,
  35. DressRoom,
  36. Canvas,
  37. GroupA,
  38. GroupB,
  39. GroupC,
  40. GroupD,
  41. GroupE,
  42. EventSystem,
  43. MainCamera,
  44. ChestTimer,
  45. NickName,
  46. MessageBox,
  47. HudText,
  48. MailItem,
  49. C_InfoItem,
  50. X_InfoItem,
  51. SkillItem,
  52. SignItem,
  53. RankItem,
  54. PlazaRoomItem,
  55. FlowerItem,
  56. AchieveItem,
  57. CommentItem,
  58. Music,
  59. Star,
  60. 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. private static string UnityDefaultSuffix = "(Clone)";
  356. public static Transform Get(string goName, Folder folder, bool compile, Transform par, bool worldSpace, ObjType objType = ObjType.Null, Type type = null)
  357. {
  358. Transform tra = Get(objType);
  359. if (tra == null)
  360. {
  361. GameObject go = Load<GameObject>(goName, folder, objType);
  362. go = Instantiate(go, par, worldSpace);
  363. go.name = go.name.Replace(UnityDefaultSuffix, "");
  364. if (compile)
  365. {
  366. Auxiliary.CompileDic(go.transform, TraDic);
  367. }
  368. if (objType != ObjType.Null)
  369. {
  370. ObjPoolDic.Add(go, objType);
  371. }
  372. if (type != null)
  373. {
  374. go.AddComponent(type);
  375. }
  376. return go.transform;
  377. }
  378. else
  379. {
  380. if (compile)
  381. {
  382. Auxiliary.CompileDic(tra, TraDic);
  383. }
  384. GameObject prefab = Load<GameObject>(goName, folder, objType);
  385. tra.SetParent(par);
  386. if (worldSpace)
  387. {
  388. tra.position = prefab.transform.position;
  389. }
  390. else
  391. {
  392. tra.localPosition = prefab.transform.position;
  393. }
  394. if (type != null)
  395. {
  396. if (tra.GetComponent(type) == null)
  397. {
  398. tra.AddComponent(type);
  399. }
  400. }
  401. return tra;
  402. }
  403. }
  404. public static Transform Get(string goName, Folder folder, bool compile, Transform par, Vector3 pos, ObjType objType = ObjType.Null, Type type = null)
  405. {
  406. Transform tra = Get(objType);
  407. if (tra == null)
  408. {
  409. GameObject go = Load<GameObject>(goName, folder, objType);
  410. go = Instantiate(go, pos, Quaternion.identity, par);
  411. go.name = go.name.Replace(UnityDefaultSuffix, "");
  412. if (compile)
  413. {
  414. Auxiliary.CompileDic(go.transform, TraDic);
  415. }
  416. if (objType != ObjType.Null)
  417. {
  418. ObjPoolDic.Add(go, objType);
  419. }
  420. if (type != null)
  421. {
  422. go.AddComponent(type);
  423. }
  424. return go.transform;
  425. }
  426. else
  427. {
  428. if (compile)
  429. {
  430. Auxiliary.CompileDic(tra, TraDic);
  431. }
  432. tra.SetParent(par);
  433. tra.position = pos;
  434. if (type != null)
  435. {
  436. if (tra.GetComponent(type) == null)
  437. {
  438. tra.AddComponent(type);
  439. }
  440. }
  441. return tra;
  442. }
  443. }
  444. private static float StarMinOffset = -0.0001f;
  445. private static float StarMaxOffset = -0.001f;
  446. public static Star GetStar()
  447. {
  448. int slotIndex = Random.Range(0, GardenManager.TotalSlotAmtInOnePage);
  449. bool forceLeft = slotIndex == GardenManager.RightTopSlotIndex || slotIndex == GardenManager.RightDownSlotIndex;
  450. bool forceRight = slotIndex == GardenManager.LeftTopSlotIndex || slotIndex == GardenManager.LeftDownSlotIndex;
  451. slotIndex += Garden.CurPage* GardenManager.TotalSlotAmtInOnePage;
  452. Slot slot = GardenManager.SlotList[slotIndex];
  453. Vector3 pos = slot.transform.position;
  454. Transform tra = Get(ResourceLabel.Star, Folder.Scene, false, null, pos, ObjType.Star);
  455. Star star = tra.GetComponent<Star>();
  456. tra.parent = slot.transform;
  457. tra.SetLZ(-0.1f + Random.Range(StarMinOffset, StarMaxOffset));
  458. if (star == null)
  459. {
  460. star = tra.AddComponent<Star>();
  461. star.Initialize(pos.y, forceLeft, forceRight);
  462. }
  463. else
  464. {
  465. star.Initialize(pos.y, forceLeft, forceRight);
  466. }
  467. return star;
  468. }
  469. public static ADChest GetADChest()
  470. {
  471. Transform tra = Get(ResourceLabel.ADChest, Folder.Scene, false, Get(GardenLabel.SlotPage), true, ObjType.ADChest);
  472. ADChest chest = tra.GetComponentInChildren<ADChest>(true);
  473. if (chest == null)
  474. {
  475. chest = tra.GetChild(0).AddComponent<ADChest>();
  476. chest.Initialize(tra.position.y, false, false);
  477. }
  478. else
  479. {
  480. chest.Initialize(tra.position.y, false, false);
  481. }
  482. return chest;
  483. }
  484. public static PlazaRoomChest GetPlazaRoomChest(Vector3 position)
  485. {
  486. Transform tra = Get(ResourceLabel.PlazaRoomChest, Folder.Scene, false, Get(ResourceLabel.PlazaRoom), position, ObjType.PlazaRoomChest);
  487. PlazaRoomChest chest = tra.GetComponentInChildren<PlazaRoomChest>(true);
  488. if (chest == null)
  489. {
  490. chest = tra.GetChild(0).AddComponent<PlazaRoomChest>();
  491. }
  492. return chest;
  493. }
  494. public static Drop GetDrop(ObjType objType)
  495. {
  496. AudioManager.PlayClip(AudioLabel.Minigame_DropAward);
  497. Vector3 leftPos = Get(GardenLabel.MiniLeft).position;
  498. Vector3 rightPos;
  499. if (MiniGameManager.PunchGame || MiniGameManager.FindGame)
  500. {
  501. rightPos = Get(GardenLabel.MiniRight1).position;
  502. }
  503. else
  504. {
  505. rightPos = Get(GardenLabel.MiniRight2).position;
  506. }
  507. Vector3 pos = Vector3.Lerp(leftPos, rightPos, Random.Range(0, 1f));
  508. Transform tra;
  509. if (objType == ObjType.DropGold)
  510. {
  511. tra = Get(ResourceLabel.DropGold, Folder.Scene, false, null, pos, objType, typeof(DropGold));
  512. }
  513. else if(objType == ObjType.DropDiamond)
  514. {
  515. tra = Get(ResourceLabel.DropDiamond, Folder.Scene, false, null, pos, objType, typeof(DropDiamond));
  516. }
  517. else
  518. {
  519. throw new Exception();
  520. }
  521. Drop drop = tra.GetComponent<Drop>();
  522. drop.InitAtOnce();
  523. drop.ResetStatus();
  524. return drop;
  525. }
  526. public static Flower GetFlower(FlowerInfo flowerInfo, Slot slot, bool collider)
  527. {
  528. Transform tra = Get(ResourceLabel.Flower, Folder.Scene, false, slot.transform, false, ObjType.Flower, typeof(Flower));
  529. tra.localScale = new Vector3(1, 1, 1);
  530. Flower flower = tra.GetComponent<Flower>();
  531. flower.InitAtOnce();
  532. flower.FlowerInfo = flowerInfo;
  533. flower.Slot = slot;
  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.SetShadow();
  546. flower.SetCollider(false);
  547. return flower;
  548. }
  549. public static TextPlus GetInfoItem(string infoItemName, Transform parent, ObjType objType)
  550. {
  551. Transform tra = Get(infoItemName, Folder.UI, false, parent, false, objType);
  552. TextPlus text = tra.GetComponent<TextPlus>();
  553. TweenRoot tween = text.CreateTweenGra(0, 1, 0.25f, true, true, Curve.EaseOutQuad);
  554. tween.OnBackwardFinish = () =>
  555. {
  556. Save(text);
  557. };
  558. return text;
  559. }
  560. public static HudText GetHudText(string str, Color color, int size, Transform posTra, Transform parTra, bool scene, float speed = 7.5f, float time = 0.5f, float stay = 0.5f)
  561. {
  562. Vector3 pos;
  563. if (scene)
  564. {
  565. pos = Camera.main.WorldToScreenPoint(posTra.position);
  566. }
  567. else
  568. {
  569. pos = posTra.position;
  570. }
  571. Transform tra = Get(ResourceLabel.HudText, Folder.UI, false, parTra, pos, ObjType.HudText, typeof(HudText));
  572. HudText hudText = tra.GetComponent<HudText>();
  573. hudText.Show(str, color, size, speed, time, stay);
  574. return hudText;
  575. }
  576. public static Ranktem GetRanktem(string rank, string praise, string serialNumber)
  577. {
  578. Transform tra = Get(ResourceLabel.RankItem, Folder.UI, false, Get(ObjectLabel.S_Grid), false, ObjType.RankItem, typeof(Ranktem));
  579. Ranktem ranktem = tra.GetComponent<Ranktem>();
  580. ranktem.InitAtOnce();
  581. ranktem.Reset(rank, praise, serialNumber);
  582. return ranktem;
  583. }
  584. public static CommentItem GetCommentItem(string nickname, string serialNumber, string content)
  585. {
  586. Transform tra = Get(ResourceLabel.CommentItem, Folder.UI, false, Get(ObjectLabel.Q_Grid), false, ObjType.CommentItem, typeof(CommentItem));
  587. CommentItem commentItem = tra.GetComponent<CommentItem>();
  588. commentItem.InitAtOnce();
  589. commentItem.Reset(nickname, serialNumber, content);
  590. return commentItem;
  591. }
  592. private static char ElfSeperator = '_';
  593. private static float ElfMinOffset = 0.001f;
  594. private static float ElfMaxOffset = 0.1f;
  595. public static Transform GetElf(Flower flower, Vector4 offset, ElfType elfType)
  596. {
  597. Transform tra;
  598. Bounds bounds = flower.FlowerIcon.bounds;
  599. Vector3 pos = flower.FlowerIcon.transform.position + new Vector3(0, 0, -5f);
  600. Transform par = flower.transform;
  601. ObjType obj = elfType.ToString().Split(ElfSeperator)[0].ToEnum<ObjType>();
  602. pos.z -= Random.Range(ElfMinOffset, ElfMaxOffset);
  603. tra = Get(obj.ToString(), Folder.Scene, false, par, pos, obj);
  604. Elf elf = tra.GetChild(0).GetComponent<Elf>();
  605. if (elf == null)
  606. {
  607. elf = tra.GetChild(0).AddScript<Elf>();
  608. }
  609. tra.GetComponentInChildren<SpriteRenderer>().sprite = LoadSprite(elfType.ToString(), Folder.Atlas2);
  610. if (Random.Range(0f, 1f) <= 0.5f)
  611. {
  612. tra.SetEY(180);
  613. }
  614. else
  615. {
  616. tra.SetEY(0);
  617. }
  618. float offsetX = Mathf.Lerp(offset.x*bounds.extents.x, offset.y*bounds.extents.x, Random.Range(0f, 1f));
  619. float offsetY = Mathf.Lerp(offset.z, offset.w*bounds.extents.y, Random.Range(0f, 1f));
  620. tra.position += new Vector3(offsetX, offsetY, 0);
  621. elf.Flower = flower;
  622. elf.Animator.SetTrigger("Play");
  623. return tra;
  624. }
  625. public static Transform GetSkillItem(SkillRoot skillRoot)
  626. {
  627. Transform tra;
  628. if (skillRoot.SkillTab == SkillTab.Elf)
  629. {
  630. tra = Get(ResourceLabel.SkillItem, Folder.UI, false, Get(ObjectLabel.Fd_Grid), false, ObjType.SkillItem);
  631. }
  632. else if (skillRoot.SkillTab == SkillTab.Store)
  633. {
  634. tra = Get(ResourceLabel.SkillItem, Folder.UI, false, Get(ObjectLabel.Fc_Grid), false, ObjType.SkillItem);
  635. }
  636. else if (skillRoot.SkillTab == SkillTab.Magic)
  637. {
  638. tra = Get(ResourceLabel.SkillItem, Folder.UI, false, Get(ObjectLabel.Fb_Grid), false, ObjType.SkillItem);
  639. }
  640. else if (skillRoot.SkillTab == SkillTab.Garden)
  641. {
  642. tra = Get(ResourceLabel.SkillItem, Folder.UI, false, Get(ObjectLabel.Fa_Grid), false, ObjType.SkillItem);
  643. }
  644. else
  645. {
  646. throw new Exception();
  647. }
  648. skillRoot.SkillItem = tra;
  649. return tra;
  650. }
  651. public static Transform GetAchieveItem()
  652. {
  653. Transform tra = Get(ResourceLabel.AchieveItem, Folder.UI, false, Get(ObjectLabel.M_Grid), false, ObjType.AchieveItem);
  654. return tra;
  655. }
  656. public static ParticleSystem GetFirework(Vector3 pos)
  657. {
  658. Transform tra = Get(ResourceLabel.Firework, Folder.Effect, false, null, pos, ObjType.Firework, typeof(Effect));
  659. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  660. particle.Play();
  661. return particle;
  662. }
  663. public static ParticleSystem GetLightwall()
  664. {
  665. Transform tra = Get(ResourceLabel.LightwallUI, Folder.Effect, false, Get(ObjectLabel.Canvas), false, ObjType.LightwallUI, typeof(Effect));
  666. ParticleSystem particle = tra.GetComponent<ParticleSystem>();
  667. if(particle != null)
  668. particle.Play();
  669. return particle;
  670. }
  671. public static void AsyncLoad<T>(string goName, Folder folder, UnityAction callback = null)
  672. {
  673. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  674. AssetBundleRequest bundleRequest = Bundle.LoadAsync<T>(goName, folder);
  675. AsyncRequest asyncRequest = new AsyncRequest();
  676. asyncRequest.Request = bundleRequest;
  677. asyncRequest.Callback = callback;
  678. kv.Key = asyncRequest;
  679. kv.Value = () =>
  680. {
  681. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  682. };
  683. RequestList.Add(bundleRequest);
  684. InstantiateList.Add(kv);
  685. }
  686. public static void AsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  687. {
  688. KV<AsyncRequest, UnityAction> kv = new KV<AsyncRequest, UnityAction>();
  689. AssetBundleRequest bundleRequest = Bundle.LoadAsync<object>(goName, folder);
  690. AsyncRequest asyncRequest = new AsyncRequest();
  691. asyncRequest.Request = bundleRequest;
  692. asyncRequest.Callback = callback;
  693. kv.Key = asyncRequest;
  694. kv.Value = () =>
  695. {
  696. ObjDic.UniqueAdd(goName, bundleRequest.asset);
  697. if (objType != ObjType.Null)
  698. {
  699. ObjectPool.UniqueAdd(objType, new List<Transform>());
  700. }
  701. GameObject go;
  702. if (ui)
  703. {
  704. go = (GameObject)Instantiate(bundleRequest.asset, GameObject.Find(LogoSceneLabel.ManagerGame).transform.GetChild(0).GetChild(0));
  705. }
  706. else
  707. {
  708. go = (GameObject)Instantiate(bundleRequest.asset);
  709. }
  710. ObjPoolDic.Add(go, objType);
  711. go.name = go.name.Replace(UnityDefaultSuffix, "");
  712. Save(go);
  713. if (ui)
  714. {
  715. go.SetParent(GameObject.Find(LogoSceneLabel.ManagerGame).transform.GetChild(0).GetChild(0));
  716. }
  717. };
  718. RequestList.Add(bundleRequest);
  719. for (int i = 0; i < amt; i++)
  720. {
  721. InstantiateList.Add(kv);
  722. }
  723. }
  724. public static void AddAsyncLoad<T>(string goName, Folder folder, UnityAction callback = null)
  725. {
  726. AsyncList.Add
  727. (
  728. () =>
  729. {
  730. AsyncLoad<T>(goName, folder, callback);
  731. }
  732. );
  733. }
  734. public static void AddAsyncLoad(string goName, int amt, Folder folder, ObjType objType, bool ui = false, bool canvas = false, UnityAction callback = null)
  735. {
  736. AsyncList.Add
  737. (
  738. () =>
  739. {
  740. AsyncLoad(goName, amt, folder, objType, ui, canvas, callback);
  741. }
  742. );
  743. }
  744. public void StopAsync()
  745. {
  746. StopCoroutine(CoroLoad);
  747. StopCoroutine(CoroInstantiate);
  748. }
  749. public static IEnumerator IAsyncLoad()
  750. {
  751. while (true)
  752. {
  753. if (RequestList.Count > 0)
  754. {
  755. yield return null;
  756. }
  757. else
  758. {
  759. if (AsyncList.Valid() && !AsyncLoadLock)
  760. {
  761. AsyncLoadLock = true;
  762. Auxiliary.Instance.DelayCall
  763. (
  764. () =>
  765. {
  766. AsyncLoadLock = false;
  767. AsyncList[0].SafeInvoke();
  768. AsyncList.RemoveAt(0);
  769. },
  770. 1
  771. );
  772. yield return null;
  773. }
  774. else
  775. {
  776. yield return null;
  777. }
  778. }
  779. }
  780. }
  781. public static IEnumerator IAsyncInstancitate()
  782. {
  783. while (true)
  784. {
  785. if (AsyncInstantiateLock)
  786. {
  787. yield return null;
  788. }
  789. if (!InstantiateList.Valid())
  790. {
  791. yield return null;
  792. }
  793. else
  794. {
  795. if (Time.deltaTime > 0.333f)
  796. {
  797. yield return null;
  798. }
  799. if (!InstantiateList[0].Key.Request.isDone)
  800. {
  801. yield return null;
  802. }
  803. else
  804. {
  805. InstantiateList[0].Key.Callback.SafeInvoke();
  806. RequestList.Remove(InstantiateList[0].Key.Request);
  807. UnityAction action = InstantiateList[0].Value;
  808. InstantiateList.RemoveAt(0);
  809. AsyncInstantiateLock = true;
  810. Auxiliary.Instance.DelayCall
  811. (
  812. () =>
  813. {
  814. if (!Logo.Complete)
  815. {
  816. action.SafeInvoke();
  817. AsyncInstantiateLock = false;
  818. }
  819. },
  820. 1
  821. );
  822. yield return null;
  823. }
  824. }
  825. }
  826. }
  827. }