ResourceManager.cs 27 KB

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