ResourceManager.cs 27 KB

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