ManaReso.cs 24 KB

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