ManaReso.cs 23 KB

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