ManaReso.cs 26 KB

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