ResourceManager.cs 27 KB

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