ResourceManager.cs 27 KB

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