Bundle.cs 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Diagnostics;
  7. using System.IO;
  8. using System.Xml;
  9. using assetBundleUtility;
  10. using DragonBones;
  11. #if UNITY_EDITOR
  12. using UnityEditor;
  13. #endif
  14. using Debug = UnityEngine.Debug;
  15. using Object = UnityEngine.Object;
  16. public class Bundle : MonoBehaviour
  17. {
  18. #region
  19. public static bool CopyComplete
  20. {
  21. get { return CopyCount == 0; }
  22. }
  23. public static bool UpdateComplete;
  24. //public static AssetBundle NewDressConfig;
  25. public static AssetBundle NewDressSke;
  26. public static AssetBundle NewDressTex;
  27. //public static AssetBundle NewLanguage;
  28. //public static AssetBundle NewFlowerConfig;
  29. public static AssetBundle NewFlowerTex;
  30. //public static List<XmlAttributeCollection> NewDressroomConfigs = new List<XmlAttributeCollection>();
  31. //public static List<XmlAttributeCollection> NewFlowerConfigs = new List<XmlAttributeCollection>();
  32. public static List<string> HotUpdateAssetBundleNames=new List<string>
  33. {
  34. ResourceLabel.Config,
  35. //ResourceLabel.NewDressConfig,
  36. ResourceLabel.NewDressSke,
  37. ResourceLabel.NewDressTex,
  38. //ResourceLabel.NewLanguage,
  39. //ResourceLabel.NewFlowerConfig,
  40. ResourceLabel.NewFlowerTex,
  41. };
  42. //public List<Object> NewDressConfigList;
  43. public List<Object> NewDressSkeList;
  44. public List<Object> NewDressTexList;
  45. public List<Object> NewDressTexConfigList;
  46. public List<Object> NewDressSpriteList;
  47. //public List<Object> NewLanguageList;
  48. //public List<Object> NewFlowerConfigList;
  49. public List<Object> NewFlowerSpriteList;
  50. public static Bundle Instance;
  51. public static bool Complete;
  52. public static AssetBundle Atlas;
  53. public static AssetBundle Atlas2;
  54. public static AssetBundle Defaul;
  55. public static AssetBundle UI;
  56. public static AssetBundle Effect;
  57. public static AssetBundle Audio;
  58. public static AssetBundle Scene;
  59. public static AssetBundle Config;
  60. public static AssetBundle Discard;
  61. public static AssetBundle PlazaRoom;
  62. public Texture2D AtlasTexture;
  63. public Texture2D ExpressionTexture;
  64. public List<Object> DefaultList;
  65. public List<Object> UiList;
  66. public List<Object> AtlasList;
  67. public List<Sprite> Atlas2List;
  68. public List<Object> EffectList;
  69. public List<Object> AudioList;
  70. public List<Object> SceneList;
  71. public List<Object> ConfigList;
  72. public List<Object> DiscardList;
  73. public List<Object> PlazaRoomList;
  74. #endregion
  75. public void Begin()
  76. {
  77. Instance = this;
  78. LoadAll
  79. (
  80. () => Complete = true
  81. );
  82. }
  83. public static T Load<T>(string goName, Folder folder) where T : Object
  84. {
  85. if (Initializer.Instance.DebugMode)
  86. {
  87. #region MyRegion
  88. if (folder == Folder.UI)
  89. {
  90. for (int i = 0; i < Instance.UiList.Count; i++)
  91. {
  92. if (Instance.UiList[i].name == goName)
  93. {
  94. return (T) Instance.UiList[i];
  95. }
  96. }
  97. }
  98. if (folder == Folder.Default)
  99. {
  100. for (int i = 0; i < Instance.DefaultList.Count; i++)
  101. {
  102. if (Instance.DefaultList[i].name == goName)
  103. {
  104. return (T)Instance.DefaultList[i];
  105. }
  106. }
  107. }
  108. else if (folder == Folder.Audio)
  109. {
  110. for (int i = 0; i < Instance.AudioList.Count; i++)
  111. {
  112. if (Instance.AudioList[i].name == goName)
  113. {
  114. return (T) Instance.AudioList[i];
  115. }
  116. }
  117. }
  118. else if (folder == Folder.Config)
  119. {
  120. for (int i = 0; i < Instance.ConfigList.Count; i++)
  121. {
  122. if (Instance.ConfigList[i].name == goName)
  123. {
  124. return (T) Instance.ConfigList[i];
  125. }
  126. }
  127. }
  128. else if (folder == Folder.Effect)
  129. {
  130. for (int i = 0; i < Instance.EffectList.Count; i++)
  131. {
  132. if (Instance.EffectList[i].name == goName)
  133. {
  134. return (T) Instance.EffectList[i];
  135. }
  136. }
  137. }
  138. else if (folder == Folder.Scene)
  139. {
  140. if (goName == "Expression")
  141. {
  142. return (T) (Object) Sprite.Create(Instance.ExpressionTexture, new Rect(0, 0, Instance.AtlasTexture.width, Instance.AtlasTexture.height), new Vector2(0.5f, 0.5f));
  143. }
  144. for (int i = 0; i < Instance.SceneList.Count; i++)
  145. {
  146. if (Instance.SceneList[i].name == goName)
  147. {
  148. return (T) Instance.SceneList[i];
  149. }
  150. }
  151. }
  152. else if (folder == Folder.Discard)
  153. {
  154. for (int i = 0; i < Instance.DiscardList.Count; i++)
  155. {
  156. if (Instance.DiscardList[i].name == goName)
  157. {
  158. return (T) Instance.DiscardList[i];
  159. }
  160. }
  161. }
  162. else if (folder == Folder.Atlas)
  163. {
  164. if (goName == "Atlas")
  165. {
  166. return (T) (Object) Sprite.Create(Instance.AtlasTexture, new Rect(0, 0, Instance.AtlasTexture.width, Instance.AtlasTexture.height), new Vector2(0.5f, 0.5f));
  167. }
  168. for (int i = 0; i < Instance.AtlasList.Count; i++)
  169. {
  170. if (Instance.AtlasList[i].name == goName)
  171. {
  172. return (T) Instance.AtlasList[i];
  173. }
  174. }
  175. }
  176. else if (folder == Folder.PlazaRoom)
  177. {
  178. for (int i = 0; i < Instance.PlazaRoomList.Count; i++)
  179. {
  180. if (Instance.PlazaRoomList[i].name == goName)
  181. {
  182. return (T) Instance.PlazaRoomList[i];
  183. }
  184. }
  185. }
  186. //else if (folder == Folder.Dress)
  187. //{
  188. // for (int i = 0; i < Instance.DressList.Count; i++)
  189. // {
  190. // if (Instance.DressList[i].name == goName)
  191. // {
  192. // return (T)Instance.DressList[i];
  193. // }
  194. // }
  195. //}
  196. #endregion
  197. }
  198. else
  199. {
  200. #region MyRegion
  201. if (folder == Folder.UI)
  202. {
  203. return UI.LoadAsset<T>(goName);
  204. }
  205. else if (folder == Folder.Audio)
  206. {
  207. return Audio.LoadAsset<T>(goName);
  208. }
  209. else if (folder == Folder.Default)
  210. {
  211. return Defaul.LoadAsset<T>(goName);
  212. }
  213. else if (folder == Folder.Config)
  214. {
  215. return Config.LoadAsset<T>(goName);
  216. }
  217. else if (folder == Folder.Effect)
  218. {
  219. return Effect.LoadAsset<T>(goName);
  220. }
  221. else if (folder == Folder.Scene)
  222. {
  223. return Scene.LoadAsset<T>(goName);
  224. }
  225. else if (folder == Folder.Atlas)
  226. {
  227. return Atlas.LoadAsset<T>(goName);
  228. }
  229. else if (folder == Folder.Atlas2)
  230. {
  231. return Atlas2.LoadAsset<T>(goName);
  232. }
  233. else if (folder == Folder.Discard)
  234. {
  235. return Discard.LoadAsset<T>(goName);
  236. }
  237. else if (folder == Folder.PlazaRoom)
  238. {
  239. return PlazaRoom.LoadAsset<T>(goName);
  240. }
  241. #endregion
  242. }
  243. DebugManager.Log(goName + " " + folder);
  244. throw new Exception(goName + " " + folder);
  245. }
  246. public static void LoadAtlasSprites()
  247. {
  248. if (Initializer.Instance.DebugMode)
  249. {
  250. for (int i = 0; i < Instance.Atlas2List.Count; i++)
  251. {
  252. ResourceManager.ObjectDictionary.UniqueAdd(Instance.Atlas2List[i].name, Instance.Atlas2List[i]);
  253. }
  254. #if UNITY_EDITOR
  255. string assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture", Folder.Scene));
  256. Object[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
  257. for (int i = 0; i < objects.Length; i++)
  258. {
  259. Sprite sprite = objects[i] as Sprite;
  260. if (sprite != null)
  261. {
  262. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  263. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  264. }
  265. }
  266. #endif
  267. }
  268. else
  269. {
  270. #region MyRegion
  271. Sprite[] sprites = Atlas2.LoadAllAssets<Sprite>();
  272. for (int i = 0; i < sprites.Length; i++)
  273. {
  274. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  275. }
  276. sprites = Atlas.LoadAllAssets<Sprite>();
  277. for (int i = 0; i < sprites.Length; i++)
  278. {
  279. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  280. }
  281. sprites = Scene.LoadAssetWithSubAssets<Sprite>("FlowerItemAtlas1");
  282. for (int i = 0; i < sprites.Length; i++)
  283. {
  284. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  285. }
  286. Object[] objects = Scene.LoadAssetWithSubAssets("stand_texture", typeof(Sprite));
  287. for (int i = 0; i < objects.Length; i++)
  288. {
  289. Sprite sprite = (Sprite) objects[i];
  290. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  291. ResourceManager.SpriteDictionary.UniqueAdd(sprite.name, sprite);
  292. }
  293. #endregion
  294. }
  295. }
  296. //public static void LoadAllDressBundleAssetsIntoDragonbone()
  297. //{
  298. // UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(DressLabel.Dress_ske, Folder.Dress));
  299. // foreach (var dressName in DressLabel.dressNames)
  300. // {
  301. // ResourceManager.Load<Texture2D>(dressName, Folder.Dress);
  302. // UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(dressName + "_tex", Folder.Dress), dressName);
  303. // }
  304. // Sprite[] sprites = Dress.LoadAllAssets<Sprite>();
  305. // if (Initializer.Instance.DebugMode)
  306. // {
  307. // for (int i = 0; i < Instance.DressList.Count; i++)
  308. // {
  309. // Sprite sprite = Instance.DressList[i] as Sprite;
  310. // if (sprite != null)
  311. // {
  312. // PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  313. // ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  314. // }
  315. // }
  316. // }
  317. // else
  318. // {
  319. // for (int i = 0; i < sprites.Length; i++)
  320. // {
  321. // PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
  322. // ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  323. // }
  324. // }
  325. //}
  326. public static AssetBundleRequest LoadAsync<T>(string goName, Folder folder)
  327. {
  328. if (folder == Folder.UI)
  329. {
  330. return UI.LoadAssetAsync<T>(goName);
  331. }
  332. else if (folder == Folder.Audio)
  333. {
  334. return Audio.LoadAssetAsync<T>(goName);
  335. }
  336. else if (folder == Folder.Default)
  337. {
  338. return Defaul.LoadAssetAsync<T>(goName);
  339. }
  340. else if (folder == Folder.Config)
  341. {
  342. return Config.LoadAssetAsync<T>(goName);
  343. }
  344. else if (folder == Folder.Effect)
  345. {
  346. return Effect.LoadAssetAsync<T>(goName);
  347. }
  348. else if (folder == Folder.Scene)
  349. {
  350. return Scene.LoadAssetAsync<T>(goName);
  351. }
  352. else if (folder == Folder.Atlas)
  353. {
  354. return Atlas.LoadAssetAsync<T>(goName);
  355. }
  356. else if (folder == Folder.Discard)
  357. {
  358. return Discard.LoadAssetAsync<T>(goName);
  359. }
  360. else
  361. {
  362. throw new Exception();
  363. }
  364. }
  365. public static AssetBundleRequest LoadAllAsync<T>(Folder folder)
  366. {
  367. if (folder == Folder.Atlas2)
  368. {
  369. return Atlas2.LoadAllAssetsAsync<T>();
  370. }
  371. else
  372. {
  373. throw new Exception();
  374. }
  375. }
  376. public static string GetStreamPath()
  377. {
  378. if (Application.isEditor)
  379. // return "file://" + System.Environment.CurrentDirectory.Replace("\\", "/"); // Use the build output folder directly.
  380. return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/"; //user local stream
  381. else if (Application.isWebPlayer)
  382. return System.IO.Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/StreamingAssets";
  383. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  384. return "file://" + Application.streamingAssetsPath + "/Bundle/IOS/";
  385. else if (Application.isMobilePlatform || Application.isConsolePlatform)
  386. return Application.streamingAssetsPath + "/Bundle/Android/";
  387. else // For standalone player.
  388. return "file://" + Application.streamingAssetsPath;
  389. //return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";
  390. }
  391. public static string GetPersistingPath()
  392. {
  393. if (Application.platform == RuntimePlatform.IPhonePlayer)
  394. return "file://" + Application.persistentDataPath;
  395. else if (Application.isMobilePlatform)
  396. return Application.streamingAssetsPath;
  397. else
  398. return "file://" + Application.persistentDataPath;
  399. }
  400. public static string GetStreamingUrlPath()
  401. {
  402. if (Application.platform == RuntimePlatform.IPhonePlayer)
  403. return "file://" + Application.streamingAssetsPath;
  404. else if (Application.isMobilePlatform)
  405. return Application.streamingAssetsPath;
  406. else
  407. return "file://" + Application.streamingAssetsPath;
  408. }
  409. public void LoadAll(UnityAction callback)
  410. {
  411. Initializer.Instance.StartCoroutine(ILoadAll(callback));
  412. }
  413. public static IEnumerator ILoadAll(UnityAction callback)
  414. {
  415. yield return LoadDefaul();
  416. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  417. {
  418. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PlayerConfig, Folder.Default, () =>
  419. {
  420. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  421. HttpManager.GetBuyPackLimitFlag();
  422. });
  423. }
  424. else
  425. {
  426. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  427. HttpManager.GetBuyPackLimitFlag();
  428. }
  429. //yield return LoadDiscard();
  430. yield return LoadUI();
  431. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  432. //{
  433. // ResourceManager.AddAsyncLoad(ResourceLabel.Canvas, 1, Folder.UI, ObjType.Canvas);
  434. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupA, 1, Folder.UI, ObjType.GroupA, true);
  435. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupB, 1, Folder.UI, ObjType.GroupB, true);
  436. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupC, 1, Folder.UI, ObjType.GroupC, true);
  437. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupE, 1, Folder.UI, ObjType.GroupE, true);
  438. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupD, 1, Folder.UI, ObjType.GroupD, true);
  439. // ResourceManager.AddAsyncLoad(ResourceLabel.EventSystem, 1, Folder.UI, ObjType.EventSystem);
  440. // ResourceManager.AddAsyncLoad(ResourceLabel.MainCamera, 1, Folder.UI, ObjType.MainCamera);
  441. // //ResourceManager.AddAsyncLoad("SkillItem", 31, Folder.UI, ObjType.SkillItem, true);
  442. // //ResourceManager.AddAsyncLoad("SignItem", 21, Folder.UI, ObjType.SignItem, true);
  443. // //ResourceManager.AddAsyncLoad("FlowerItem", 17, Folder.UI, ObjType.FlowerItem, true);
  444. // //ResourceManager.AddAsyncLoad("AchieveItem", 2, Folder.UI, ObjType.AchieveItem, true);
  445. //}
  446. yield return LoadScene();
  447. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  448. //{
  449. // ResourceManager.AddAsyncLoad(ResourceLabel.Flower, 9, Folder.Scene, ObjType.Flower);
  450. // ResourceManager.AddAsyncLoad(ResourceLabel.Page, 2, Folder.Scene, ObjType.SlotPage);
  451. // ResourceManager.AddAsyncLoad(ResourceLabel.Garden, 1, Folder.Scene, ObjType.Garden);
  452. // ResourceManager.AddAsyncLoad(ResourceLabel.DressRoom, 1, Folder.UI, ObjType.DressRoom);
  453. //}
  454. yield return LoadAudio();
  455. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  456. //{
  457. // ResourceManager.AddAsyncLoad(ResourceLabel.Music, 1, Folder.Audio, ObjType.Music);
  458. //}
  459. yield return LoadAtlas2();
  460. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  461. //{
  462. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SkillConfig, Folder.Config);
  463. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PackConfig, Folder.Config);
  464. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AbilityConfig, Folder.Config);
  465. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AchieveConfig, Folder.Config);
  466. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.VisitConfig, Folder.Config);
  467. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AwardConfig, Folder.Config);
  468. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.FlowerConfig, Folder.Config);
  469. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.OfflineConfig, Folder.Config);
  470. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SigninConfig, Folder.Config);
  471. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.DressroomConfig, Folder.Config);
  472. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.English, Folder.Config);
  473. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseSimplified, Folder.Config);
  474. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseTraditional, Folder.Config);
  475. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BtnClip, Folder.Audio);
  476. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.SkillClip, Folder.Audio);
  477. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.ErrorClip, Folder.Audio);
  478. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.DropClip, Folder.Audio);
  479. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CloseClip, Folder.Audio);
  480. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.FlowerClip, Folder.Audio);
  481. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BubbleClip, Folder.Audio);
  482. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CurrentClip, Folder.Audio);
  483. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.MiniEndClip, Folder.Audio);
  484. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandTex, Folder.Config);
  485. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandSke, Folder.Config);
  486. // ResourceManager.AddAsyncLoad<Texture2D>(ResourceLabel.StandTexture, Folder.Scene);
  487. //}
  488. yield return LoadAtlas();
  489. yield return LoadEffect();
  490. SpriteAsset.AddAllBundleSpriteInfo();
  491. if (callback != null)
  492. {
  493. callback.Invoke();
  494. }
  495. }
  496. public static IEnumerator LoadUI()
  497. {
  498. WWW www = new WWW(GetStreamPath() + "ui");
  499. yield return www;
  500. if (string.IsNullOrEmpty(www.error))
  501. {
  502. UI = www.assetBundle;
  503. }
  504. else
  505. {
  506. Debug.Log(www.error);
  507. }
  508. }
  509. public static IEnumerator LoadAtlas()
  510. {
  511. WWW www = new WWW(GetStreamPath() + "atlas");
  512. yield return www;
  513. if (string.IsNullOrEmpty(www.error))
  514. {
  515. Atlas = www.assetBundle;
  516. }
  517. else
  518. {
  519. Debug.Log(www.error);
  520. }
  521. }
  522. public static IEnumerator LoadAtlas2()
  523. {
  524. WWW www = new WWW(GetStreamPath() + "atlas2");
  525. yield return www;
  526. if (string.IsNullOrEmpty(www.error))
  527. {
  528. Atlas2 = www.assetBundle;
  529. }
  530. else
  531. {
  532. Debug.Log(www.error);
  533. }
  534. }
  535. public static IEnumerator LoadAudio()
  536. {
  537. WWW www = new WWW(GetStreamPath() + "audio");
  538. yield return www;
  539. if (string.IsNullOrEmpty(www.error))
  540. {
  541. Audio = www.assetBundle;
  542. }
  543. else
  544. {
  545. Debug.Log(www.error);
  546. }
  547. }
  548. public static IEnumerator LoadDefaul()
  549. {
  550. WWW www = new WWW(GetStreamPath() + "default");
  551. yield return www;
  552. if (string.IsNullOrEmpty(www.error))
  553. {
  554. Defaul = www.assetBundle;
  555. }
  556. else
  557. {
  558. Debug.Log(www.error);
  559. }
  560. }
  561. public static IEnumerator LoadEffect()
  562. {
  563. WWW www = new WWW(GetStreamPath() + "effect");
  564. yield return www;
  565. if (string.IsNullOrEmpty(www.error))
  566. {
  567. Effect = www.assetBundle;
  568. }
  569. else
  570. {
  571. Debug.Log(www.error);
  572. }
  573. }
  574. public static IEnumerator LoadScene()
  575. {
  576. WWW www = new WWW(GetStreamPath() + "scene");
  577. yield return www;
  578. if (string.IsNullOrEmpty(www.error))
  579. {
  580. Scene = www.assetBundle;
  581. }
  582. else
  583. {
  584. Debug.Log(www.error);
  585. }
  586. }
  587. public static IEnumerator LoadDiscard()
  588. {
  589. WWW www = new WWW(GetStreamPath() + "discard");
  590. yield return www;
  591. if (string.IsNullOrEmpty(www.error))
  592. {
  593. Discard = www.assetBundle;
  594. }
  595. else
  596. {
  597. Debug.Log(www.error);
  598. }
  599. }
  600. public static IEnumerator LoadPlazaRoom()
  601. {
  602. WWW www = new WWW(GetStreamPath() + "plazaroom");
  603. yield return www;
  604. if (string.IsNullOrEmpty(www.error))
  605. {
  606. PlazaRoom = www.assetBundle;
  607. }
  608. else
  609. {
  610. Debug.Log(www.error);
  611. }
  612. }
  613. private static int CopyCount = 0;
  614. public static void CopyAssetBundles()
  615. {
  616. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  617. if (!Directory.Exists(persistentFolderPath))
  618. {
  619. Directory.CreateDirectory(persistentFolderPath);
  620. }
  621. string streamingFolder;
  622. if (Application.platform == RuntimePlatform.IPhonePlayer)
  623. {
  624. streamingFolder = "IOS";
  625. }
  626. else if (Application.platform == RuntimePlatform.Android)
  627. {
  628. streamingFolder = "Android";
  629. }
  630. else
  631. {
  632. streamingFolder = "Windows";
  633. }
  634. foreach (var assetBundleName in HotUpdateAssetBundleNames)
  635. {
  636. if (!File.Exists(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName))
  637. {
  638. CopyCount++;
  639. Initializer.Instance.StartCoroutine
  640. (
  641. LoadAssetBundleFromStream
  642. (
  643. streamingFolder,
  644. assetBundleName,
  645. www =>
  646. {
  647. File.WriteAllBytes(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName, www.bytes);
  648. CopyOneAssetBundleFinish();
  649. }
  650. )
  651. );
  652. }
  653. }
  654. }
  655. private static void CopyOneAssetBundleFinish()
  656. {
  657. CopyCount--;
  658. }
  659. public static IEnumerator LoadAssetBundleFromStream(string folder, string name, Action<WWW> callback)
  660. {
  661. WWW www = new WWW(GetStreamingUrlPath() + Path.DirectorySeparatorChar + "Bundle" + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + "HotUpdate" + Path.DirectorySeparatorChar + name);
  662. yield return www;
  663. if (string.IsNullOrEmpty(www.error))
  664. {
  665. callback.Invoke(www);
  666. }
  667. else
  668. {
  669. Debug.Log(www.error);
  670. }
  671. }
  672. public static int UpdateAmt;
  673. public static int UpdateFinishAmt;
  674. public static bool UpdateAssetBundles()
  675. {
  676. //Debug.Log(HttpManager.Md5);
  677. //Debug.Log(HttpManager.Md5Dictionnary);
  678. //Debug.Log(HttpManager.AssetbundleUrl);
  679. try
  680. {
  681. Initializer.DebugText.text = "U0";
  682. if (Initializer.Instance.DebugMode)
  683. {
  684. SkipUpdateForDebugMode();
  685. return false;
  686. }
  687. Initializer.DebugText.text = "U1";
  688. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  689. Initializer.DebugText.text = "U2";
  690. List<AssetBundleSet> assetBundleSets = AssetBundleUtility.GetAssetBundleSetsFromFolders
  691. (
  692. persistentFolderPath
  693. );
  694. Initializer.DebugText.text = "U3";
  695. string localMD5 = AssetBundleUtility.GetMD5OfAssetBundleSets(assetBundleSets);
  696. bool needUpdate;
  697. if (string.IsNullOrEmpty(HttpManager.Md5) || string.IsNullOrEmpty(HttpManager.Md5Dictionnary) || string.IsNullOrEmpty(HttpManager.AssetbundleUrl))
  698. {
  699. needUpdate = false;
  700. Debug.LogWarning($"NeedUpdate : {needUpdate} connection error");
  701. }
  702. else
  703. {
  704. //Debug.Log(localMD5);
  705. //Debug.Log(HttpManager.Md5);
  706. needUpdate = localMD5 != HttpManager.Md5;
  707. //Debug.LogWarning($"NeedUpdate : {needUpdate}");
  708. }
  709. if (Application.isEditor)
  710. {
  711. needUpdate = false;
  712. }
  713. AssetBundleUtility.OnDownloadOrUpdateFinish += FinishDownloadAndLoad;
  714. if (needUpdate)
  715. {
  716. Initializer.DebugText.text = "U4";
  717. UpdateAmt = AssetBundleUtility.UpdateAllAssetBundle
  718. (
  719. HttpManager.Md5Dictionnary,
  720. persistentFolderPath,
  721. assetBundleSets,
  722. DownloadAllAssetBundleSucceed,
  723. DownloadAllAssetBundleFailed,
  724. DownloadAssetBundleSucceed,
  725. DownloadAssetBundleFailed
  726. );
  727. UpdatePanel.Show();
  728. UpdatePanel.SetProgress(UpdateAmt, 0);
  729. }
  730. else
  731. {
  732. Initializer.DebugText.text = "U5";
  733. AssetBundleUtility.LoadAllAssetBundle
  734. (
  735. assetBundleSets,
  736. DownloadAllAssetBundleSucceed,
  737. DownloadAllAssetBundleFailed,
  738. DownloadAssetBundleSucceed,
  739. DownloadAssetBundleFailed
  740. );
  741. }
  742. return false;
  743. }
  744. catch (Exception)
  745. {
  746. Initializer.EnableDebugLab();
  747. return true;
  748. }
  749. }
  750. private static void FinishDownloadAndLoad()
  751. {
  752. try
  753. {
  754. Initializer.DebugText.text = "01";
  755. //NewDressroomConfigs = ConfigManager.GetDressRoomConfig(NewDressConfig.LoadAsset<TextAsset>(ResourceLabel.NewDressroomConfig));
  756. Initializer.DebugText.text = "02";
  757. TextAsset[] textAssets = NewDressSke.LoadAllAssets<TextAsset>();
  758. foreach (var textAsset in textAssets)
  759. {
  760. UnityFactory.factory.LoadDragonBonesData(textAsset);
  761. }
  762. Initializer.DebugText.text = "03";
  763. textAssets = NewDressTex.LoadAllAssets<TextAsset>();
  764. Texture2D[] textures = NewDressTex.LoadAllAssets<Texture2D>();
  765. for (int i = 0; i < textAssets.Length; i++)
  766. {
  767. ResourceManager.ObjectDictionary.Add(textures[i].name, textures[i]);
  768. UnityFactory.factory.LoadTextureAtlasData(textAssets[i], textures[i].name);
  769. }
  770. Initializer.DebugText.text = "04";
  771. Sprite[] sprites = NewDressTex.LoadAllAssets<Sprite>();
  772. for (int i = 0; i < sprites.Length; i++)
  773. {
  774. PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
  775. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  776. }
  777. Initializer.DebugText.text = "051";
  778. TextAsset language = Config.LoadAsset<TextAsset>(ResourceLabel.English);
  779. XmlDocument document = new XmlDocument();
  780. document.LoadXml(language.text);
  781. Language.AddLanguageDocument(CurrentLanguage.English, document);
  782. Initializer.DebugText.text = "061";
  783. language = Config.LoadAsset<TextAsset>(ResourceLabel.ChineseSimplified);
  784. document = new XmlDocument();
  785. document.LoadXml(language.text);
  786. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  787. Initializer.DebugText.text = "071";
  788. language = Config.LoadAsset<TextAsset>(ResourceLabel.ChineseTraditional);
  789. document = new XmlDocument();
  790. document.LoadXml(language.text);
  791. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  792. //Initializer.DebugText.text = "052";
  793. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewEnglish);
  794. //document = new XmlDocument();
  795. //document.LoadXml(language.text);
  796. //Language.AddLanguageDocument(CurrentLanguage.English, document);
  797. //Initializer.DebugText.text = "062";
  798. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseSimplified);
  799. //document = new XmlDocument();
  800. //document.LoadXml(language.text);
  801. //Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  802. //Initializer.DebugText.text = "072";
  803. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseTraditional);
  804. //document = new XmlDocument();
  805. //document.LoadXml(language.text);
  806. //Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  807. Initializer.DebugText.text = "08";
  808. //NewFlowerConfigs = ConfigManager.GetFlowerConfig(NewFlowerConfig.LoadAsset<TextAsset>(ResourceLabel.NewFlowerConfig));
  809. Initializer.DebugText.text = "09";
  810. sprites = NewFlowerTex.LoadAllAssets<Sprite>();
  811. for (int i = 0; i < sprites.Length; i++)
  812. {
  813. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  814. }
  815. UpdateComplete = true;
  816. DelayCall.Call(1f, UpdatePanel.Hide);
  817. }
  818. catch (Exception e)
  819. {
  820. Debug.Log(e);
  821. Initializer.DebugText.text += e.ToString();
  822. Initializer.EnableDebugLab();
  823. }
  824. }
  825. public static void DownloadAllAssetBundleSucceed()
  826. {
  827. //Debug.Log("succeed");
  828. }
  829. public static void DownloadAllAssetBundleFailed()
  830. {
  831. Debug.Log("failed");
  832. }
  833. public static void DownloadAssetBundleSucceed(AssetBundleSet assetBundleSet, bool isDownload)
  834. {
  835. //Debug.Log(assetBundleSet.AssetBundle.name);
  836. //if (assetBundleSet.Name == ResourceLabel.NewDressConfig)
  837. //{
  838. // NewDressConfig = assetBundleSet.AssetBundle;
  839. //}
  840. if (assetBundleSet.Name == ResourceLabel.NewDressSke)
  841. {
  842. NewDressSke = assetBundleSet.AssetBundle;
  843. }
  844. else if (assetBundleSet.Name == ResourceLabel.NewDressTex)
  845. {
  846. NewDressTex = assetBundleSet.AssetBundle;
  847. }
  848. else if (assetBundleSet.Name == ResourceLabel.Config)
  849. {
  850. Config = assetBundleSet.AssetBundle;
  851. }
  852. //else if (assetBundleSet.Name == ResourceLabel.NewLanguage)
  853. //{
  854. // NewLanguage = assetBundleSet.AssetBundle;
  855. //}
  856. //else if (assetBundleSet.Name == ResourceLabel.NewFlowerConfig)
  857. //{
  858. // NewFlowerConfig = assetBundleSet.AssetBundle;
  859. //}
  860. else if (assetBundleSet.Name == ResourceLabel.NewFlowerTex)
  861. {
  862. NewFlowerTex = assetBundleSet.AssetBundle;
  863. }
  864. if (isDownload)
  865. {
  866. UpdateFinishAmt++;
  867. UpdatePanel.SetProgress(UpdateAmt, UpdateFinishAmt);
  868. }
  869. }
  870. public static void DownloadAssetBundleFailed(AssetBundleSet assetBundleSet, string error)
  871. {
  872. Debug.Log(error);
  873. string path = assetBundleSet.PersistentPath;
  874. path = path.Replace("/", Path.DirectorySeparatorChar.ToString());
  875. path = path.Replace("\\", Path.DirectorySeparatorChar.ToString());
  876. path = path.Replace("\\\\", Path.DirectorySeparatorChar.ToString());
  877. path = "file://" + path;
  878. WWW www = new WWW(path);
  879. AssetBundleSet bundleSet = new AssetBundleSet();
  880. bundleSet.Name = assetBundleSet.Name;
  881. bundleSet.AssetBundle = www.assetBundle;
  882. DownloadAssetBundleSucceed(bundleSet, false);
  883. //string str = Language.GetStr(LanguageLabel.UI__AJ_UpdateFailed, Application.systemLanguage) + " " + error;
  884. //UpdatePanel.SetContent(str);
  885. //Initializer.DebugText.text = assetBundleSet.Name;
  886. //Initializer.DebugText.text += error;
  887. //Initializer.EnableDebugLab();
  888. }
  889. public static void SkipUpdateForDebugMode()
  890. {
  891. //NewDressroomConfigs = ConfigManager.GetDressRoomConfig(Instance.NewDressConfigList[0] as TextAsset);
  892. foreach (var textAsset in Instance.NewDressSkeList)
  893. {
  894. UnityFactory.factory.LoadDragonBonesData(textAsset as TextAsset);
  895. }
  896. for (int i = 0; i < Instance.NewDressTexList.Count; i++)
  897. {
  898. TextAsset textAsset = Instance.NewDressTexConfigList[i] as TextAsset;
  899. Texture2D texture = Instance.NewDressTexList[i] as Texture2D;
  900. ResourceManager.ObjectDictionary.Add(texture.name, texture);
  901. UnityFactory.factory.LoadTextureAtlasData(textAsset, texture.name);
  902. }
  903. for (int i = 0; i < Instance.NewDressSpriteList.Count; i++)
  904. {
  905. Sprite sprite = Instance.NewDressSpriteList[i] as Sprite;
  906. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  907. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  908. }
  909. for (int i = 0; i < Instance.ConfigList.Count; i++)
  910. {
  911. TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
  912. if (textAsset.name == ResourceLabel.English)
  913. {
  914. XmlDocument document = new XmlDocument();
  915. document.LoadXml(textAsset.text);
  916. Language.AddLanguageDocument(CurrentLanguage.English, document);
  917. }
  918. else if (textAsset.name == ResourceLabel.ChineseSimplified)
  919. {
  920. XmlDocument document = new XmlDocument();
  921. document.LoadXml(textAsset.text);
  922. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  923. }
  924. else if (textAsset.name == ResourceLabel.ChineseTraditional)
  925. {
  926. XmlDocument document = new XmlDocument();
  927. document.LoadXml(textAsset.text);
  928. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  929. }
  930. }
  931. for (int i = 0; i < Instance.DefaultList.Count; i++)
  932. {
  933. TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
  934. if (textAsset.name == ResourceLabel.English)
  935. {
  936. XmlDocument document = new XmlDocument();
  937. document.LoadXml(textAsset.text);
  938. Language.AddLanguageDocument(CurrentLanguage.English, document);
  939. }
  940. else if (textAsset.name == ResourceLabel.ChineseSimplified)
  941. {
  942. XmlDocument document = new XmlDocument();
  943. document.LoadXml(textAsset.text);
  944. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  945. }
  946. else if (textAsset.name == ResourceLabel.ChineseTraditional)
  947. {
  948. XmlDocument document = new XmlDocument();
  949. document.LoadXml(textAsset.text);
  950. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  951. }
  952. }
  953. //NewFlowerConfigs = ConfigManager.GetDressRoomConfig(Instance.NewFlowerConfigList[0] as TextAsset);
  954. foreach (var obj in Instance.NewFlowerSpriteList)
  955. {
  956. Sprite sprite = obj as Sprite;
  957. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  958. }
  959. UpdateComplete = true;
  960. }
  961. }