ManaReso.cs 24 KB

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