ManaReso.cs 23 KB

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