ResourceManager.cs 27 KB

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