ResourceManager.cs 27 KB

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