ManaReso.cs 26 KB

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