Bundle.cs 35 KB

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