Bundle.cs 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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. List<Object> objects = new List<Object>();
  256. string assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture_0", Folder.Scene));
  257. objects.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath));
  258. assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture_1", Folder.Scene));
  259. objects.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath));
  260. for (int i = 0; i < objects.Count; i++)
  261. {
  262. Sprite sprite = objects[i] as Sprite;
  263. if (sprite != null)
  264. {
  265. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  266. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  267. }
  268. }
  269. #endif
  270. }
  271. else
  272. {
  273. #region MyRegion
  274. Sprite[] sprites = Atlas2.LoadAllAssets<Sprite>();
  275. for (int i = 0; i < sprites.Length; i++)
  276. {
  277. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  278. }
  279. sprites = Atlas.LoadAllAssets<Sprite>();
  280. for (int i = 0; i < sprites.Length; i++)
  281. {
  282. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  283. }
  284. sprites = Scene.LoadAssetWithSubAssets<Sprite>("FlowerItemAtlas1");
  285. for (int i = 0; i < sprites.Length; i++)
  286. {
  287. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  288. }
  289. List<Object> objects = new List<Object>();
  290. objects.AddRange(Scene.LoadAssetWithSubAssets("stand_texture_0", typeof(Sprite)));
  291. objects.AddRange(Scene.LoadAssetWithSubAssets("stand_texture_1", typeof(Sprite)));
  292. for (int i = 0; i < objects.Count; i++)
  293. {
  294. Sprite sprite = (Sprite) objects[i];
  295. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  296. ResourceManager.SpriteDictionary.UniqueAdd(sprite.name, sprite);
  297. }
  298. #endregion
  299. }
  300. }
  301. //public static void LoadAllDressBundleAssetsIntoDragonbone()
  302. //{
  303. // UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(DressLabel.Dress_ske, Folder.Dress));
  304. // foreach (var dressName in DressLabel.dressNames)
  305. // {
  306. // ResourceManager.Load<Texture2D>(dressName, Folder.Dress);
  307. // UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(dressName + "_tex", Folder.Dress), dressName);
  308. // }
  309. // Sprite[] sprites = Dress.LoadAllAssets<Sprite>();
  310. // if (Initializer.Instance.DebugMode)
  311. // {
  312. // for (int i = 0; i < Instance.DressList.Count; i++)
  313. // {
  314. // Sprite sprite = Instance.DressList[i] as Sprite;
  315. // if (sprite != null)
  316. // {
  317. // PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  318. // ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  319. // }
  320. // }
  321. // }
  322. // else
  323. // {
  324. // for (int i = 0; i < sprites.Length; i++)
  325. // {
  326. // PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
  327. // ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  328. // }
  329. // }
  330. //}
  331. public static AssetBundleRequest LoadAsync<T>(string goName, Folder folder)
  332. {
  333. if (folder == Folder.UI)
  334. {
  335. return UI.LoadAssetAsync<T>(goName);
  336. }
  337. else if (folder == Folder.Audio)
  338. {
  339. return Audio.LoadAssetAsync<T>(goName);
  340. }
  341. else if (folder == Folder.Default)
  342. {
  343. return Defaul.LoadAssetAsync<T>(goName);
  344. }
  345. else if (folder == Folder.Config)
  346. {
  347. return Config.LoadAssetAsync<T>(goName);
  348. }
  349. else if (folder == Folder.Effect)
  350. {
  351. return Effect.LoadAssetAsync<T>(goName);
  352. }
  353. else if (folder == Folder.Scene)
  354. {
  355. return Scene.LoadAssetAsync<T>(goName);
  356. }
  357. else if (folder == Folder.Atlas)
  358. {
  359. return Atlas.LoadAssetAsync<T>(goName);
  360. }
  361. else if (folder == Folder.Discard)
  362. {
  363. return Discard.LoadAssetAsync<T>(goName);
  364. }
  365. else
  366. {
  367. throw new Exception();
  368. }
  369. }
  370. public static AssetBundleRequest LoadAllAsync<T>(Folder folder)
  371. {
  372. if (folder == Folder.Atlas2)
  373. {
  374. return Atlas2.LoadAllAssetsAsync<T>();
  375. }
  376. else
  377. {
  378. throw new Exception();
  379. }
  380. }
  381. public static string GetStreamPath()
  382. {
  383. if (Application.isEditor)
  384. // return "file://" + System.Environment.CurrentDirectory.Replace("\\", "/"); // Use the build output folder directly.
  385. return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/"; //user local stream
  386. else if (Application.isWebPlayer)
  387. return System.IO.Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/StreamingAssets";
  388. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  389. return "file://" + Application.streamingAssetsPath + "/Bundle/IOS/";
  390. else if (Application.isMobilePlatform || Application.isConsolePlatform)
  391. return Application.streamingAssetsPath + "/Bundle/Android/";
  392. else // For standalone player.
  393. return "file://" + Application.streamingAssetsPath;
  394. //return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";
  395. }
  396. public static string GetPersistingPath()
  397. {
  398. if (Application.platform == RuntimePlatform.IPhonePlayer)
  399. return "file://" + Application.persistentDataPath;
  400. else if (Application.isMobilePlatform)
  401. return Application.streamingAssetsPath;
  402. else
  403. return "file://" + Application.persistentDataPath;
  404. }
  405. public static string GetStreamingUrlPath()
  406. {
  407. if (Application.platform == RuntimePlatform.IPhonePlayer)
  408. return "file://" + Application.streamingAssetsPath;
  409. else if (Application.isMobilePlatform)
  410. return Application.streamingAssetsPath;
  411. else
  412. return "file://" + Application.streamingAssetsPath;
  413. }
  414. public void LoadAll(UnityAction callback)
  415. {
  416. Initializer.Instance.StartCoroutine(ILoadAll(callback));
  417. }
  418. public static IEnumerator ILoadAll(UnityAction callback)
  419. {
  420. yield return LoadDefaul();
  421. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  422. {
  423. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PlayerConfig, Folder.Default, () =>
  424. {
  425. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  426. HttpManager.GetBuyPackLimitFlag();
  427. });
  428. }
  429. else
  430. {
  431. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  432. HttpManager.GetBuyPackLimitFlag();
  433. }
  434. //yield return LoadDiscard();
  435. yield return LoadUI();
  436. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  437. //{
  438. // ResourceManager.AddAsyncLoad(ResourceLabel.Canvas, 1, Folder.UI, ObjType.Canvas);
  439. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupA, 1, Folder.UI, ObjType.GroupA, true);
  440. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupB, 1, Folder.UI, ObjType.GroupB, true);
  441. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupC, 1, Folder.UI, ObjType.GroupC, true);
  442. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupE, 1, Folder.UI, ObjType.GroupE, true);
  443. // //ResourceManager.AddAsyncLoad(ResourceLabel.GroupD, 1, Folder.UI, ObjType.GroupD, true);
  444. // ResourceManager.AddAsyncLoad(ResourceLabel.EventSystem, 1, Folder.UI, ObjType.EventSystem);
  445. // ResourceManager.AddAsyncLoad(ResourceLabel.MainCamera, 1, Folder.UI, ObjType.MainCamera);
  446. // //ResourceManager.AddAsyncLoad("SkillItem", 31, Folder.UI, ObjType.SkillItem, true);
  447. // //ResourceManager.AddAsyncLoad("SignItem", 21, Folder.UI, ObjType.SignItem, true);
  448. // //ResourceManager.AddAsyncLoad("FlowerItem", 17, Folder.UI, ObjType.FlowerItem, true);
  449. // //ResourceManager.AddAsyncLoad("AchieveItem", 2, Folder.UI, ObjType.AchieveItem, true);
  450. //}
  451. yield return LoadScene();
  452. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  453. //{
  454. // ResourceManager.AddAsyncLoad(ResourceLabel.Flower, 9, Folder.Scene, ObjType.Flower);
  455. // ResourceManager.AddAsyncLoad(ResourceLabel.Page, 2, Folder.Scene, ObjType.SlotPage);
  456. // ResourceManager.AddAsyncLoad(ResourceLabel.Garden, 1, Folder.Scene, ObjType.Garden);
  457. // ResourceManager.AddAsyncLoad(ResourceLabel.DressRoom, 1, Folder.UI, ObjType.DressRoom);
  458. //}
  459. yield return LoadAudio();
  460. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  461. //{
  462. // ResourceManager.AddAsyncLoad(ResourceLabel.Music, 1, Folder.Audio, ObjType.Music);
  463. //}
  464. yield return LoadAtlas2();
  465. //if (!Logo.Complete && !Initializer.Instance.DebugMode)
  466. //{
  467. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SkillConfig, Folder.Config);
  468. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PackConfig, Folder.Config);
  469. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AbilityConfig, Folder.Config);
  470. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AchieveConfig, Folder.Config);
  471. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.VisitConfig, Folder.Config);
  472. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AwardConfig, Folder.Config);
  473. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.FlowerConfig, Folder.Config);
  474. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.OfflineConfig, Folder.Config);
  475. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SigninConfig, Folder.Config);
  476. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.DressroomConfig, Folder.Config);
  477. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.English, Folder.Config);
  478. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseSimplified, Folder.Config);
  479. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseTraditional, Folder.Config);
  480. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BtnClip, Folder.Audio);
  481. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.SkillClip, Folder.Audio);
  482. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.ErrorClip, Folder.Audio);
  483. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.DropClip, Folder.Audio);
  484. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CloseClip, Folder.Audio);
  485. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.FlowerClip, Folder.Audio);
  486. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BubbleClip, Folder.Audio);
  487. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CurrentClip, Folder.Audio);
  488. // ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.MiniEndClip, Folder.Audio);
  489. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandTex, Folder.Config);
  490. // ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandSke, Folder.Config);
  491. // ResourceManager.AddAsyncLoad<Texture2D>(ResourceLabel.StandTexture, Folder.Scene);
  492. //}
  493. yield return LoadAtlas();
  494. yield return LoadEffect();
  495. SpriteAsset.AddAllBundleSpriteInfo();
  496. if (callback != null)
  497. {
  498. callback.Invoke();
  499. }
  500. }
  501. public static IEnumerator LoadUI()
  502. {
  503. WWW www = new WWW(GetStreamPath() + "ui");
  504. yield return www;
  505. if (string.IsNullOrEmpty(www.error))
  506. {
  507. UI = www.assetBundle;
  508. }
  509. else
  510. {
  511. Debug.Log(www.error);
  512. }
  513. }
  514. public static IEnumerator LoadAtlas()
  515. {
  516. WWW www = new WWW(GetStreamPath() + "atlas");
  517. yield return www;
  518. if (string.IsNullOrEmpty(www.error))
  519. {
  520. Atlas = www.assetBundle;
  521. }
  522. else
  523. {
  524. Debug.Log(www.error);
  525. }
  526. }
  527. public static IEnumerator LoadAtlas2()
  528. {
  529. WWW www = new WWW(GetStreamPath() + "atlas2");
  530. yield return www;
  531. if (string.IsNullOrEmpty(www.error))
  532. {
  533. Atlas2 = www.assetBundle;
  534. }
  535. else
  536. {
  537. Debug.Log(www.error);
  538. }
  539. }
  540. public static IEnumerator LoadAudio()
  541. {
  542. WWW www = new WWW(GetStreamPath() + "audio");
  543. yield return www;
  544. if (string.IsNullOrEmpty(www.error))
  545. {
  546. Audio = www.assetBundle;
  547. }
  548. else
  549. {
  550. Debug.Log(www.error);
  551. }
  552. }
  553. public static IEnumerator LoadDefaul()
  554. {
  555. WWW www = new WWW(GetStreamPath() + "default");
  556. yield return www;
  557. if (string.IsNullOrEmpty(www.error))
  558. {
  559. Defaul = www.assetBundle;
  560. }
  561. else
  562. {
  563. Debug.Log(www.error);
  564. }
  565. }
  566. public static IEnumerator LoadEffect()
  567. {
  568. WWW www = new WWW(GetStreamPath() + "effect");
  569. yield return www;
  570. if (string.IsNullOrEmpty(www.error))
  571. {
  572. Effect = www.assetBundle;
  573. }
  574. else
  575. {
  576. Debug.Log(www.error);
  577. }
  578. }
  579. public static IEnumerator LoadScene()
  580. {
  581. WWW www = new WWW(GetStreamPath() + "scene");
  582. yield return www;
  583. if (string.IsNullOrEmpty(www.error))
  584. {
  585. Scene = www.assetBundle;
  586. }
  587. else
  588. {
  589. Debug.Log(www.error);
  590. }
  591. }
  592. public static IEnumerator LoadDiscard()
  593. {
  594. WWW www = new WWW(GetStreamPath() + "discard");
  595. yield return www;
  596. if (string.IsNullOrEmpty(www.error))
  597. {
  598. Discard = www.assetBundle;
  599. }
  600. else
  601. {
  602. Debug.Log(www.error);
  603. }
  604. }
  605. public static IEnumerator LoadPlazaRoom()
  606. {
  607. WWW www = new WWW(GetStreamPath() + "plazaroom");
  608. yield return www;
  609. if (string.IsNullOrEmpty(www.error))
  610. {
  611. PlazaRoom = www.assetBundle;
  612. }
  613. else
  614. {
  615. Debug.Log(www.error);
  616. }
  617. }
  618. private static int CopyCount = 0;
  619. public static void CopyAssetBundles()
  620. {
  621. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  622. if (!Directory.Exists(persistentFolderPath))
  623. {
  624. Directory.CreateDirectory(persistentFolderPath);
  625. }
  626. string streamingFolder;
  627. if (Application.platform == RuntimePlatform.IPhonePlayer)
  628. {
  629. streamingFolder = "IOS";
  630. }
  631. else if (Application.platform == RuntimePlatform.Android)
  632. {
  633. streamingFolder = "Android";
  634. }
  635. else
  636. {
  637. streamingFolder = "Windows";
  638. }
  639. foreach (var assetBundleName in HotUpdateAssetBundleNames)
  640. {
  641. if (!File.Exists(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName))
  642. {
  643. CopyCount++;
  644. Initializer.Instance.StartCoroutine
  645. (
  646. LoadAssetBundleFromStream
  647. (
  648. streamingFolder,
  649. assetBundleName,
  650. www =>
  651. {
  652. File.WriteAllBytes(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName, www.bytes);
  653. CopyOneAssetBundleFinish();
  654. }
  655. )
  656. );
  657. }
  658. }
  659. }
  660. private static void CopyOneAssetBundleFinish()
  661. {
  662. CopyCount--;
  663. }
  664. public static IEnumerator LoadAssetBundleFromStream(string folder, string name, Action<WWW> callback)
  665. {
  666. WWW www = new WWW(GetStreamingUrlPath() + Path.DirectorySeparatorChar + "Bundle" + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + "HotUpdate" + Path.DirectorySeparatorChar + name);
  667. yield return www;
  668. if (string.IsNullOrEmpty(www.error))
  669. {
  670. callback.Invoke(www);
  671. }
  672. else
  673. {
  674. Debug.Log(www.error);
  675. Initializer.DebugText.text = www.error;
  676. Initializer.DebugText.SetActive(true);
  677. Initializer.DebugText.enabled = true;
  678. }
  679. }
  680. public static int UpdateAmt;
  681. public static int UpdateFinishAmt;
  682. public static bool UpdateAssetBundles()
  683. {
  684. //Debug.Log(HttpManager.Md5);
  685. //Debug.Log(HttpManager.Md5Dictionnary);
  686. //Debug.Log(HttpManager.AssetbundleUrl);
  687. try
  688. {
  689. Initializer.DebugText.text = "U0";
  690. if (Initializer.Instance.DebugMode)
  691. {
  692. SkipUpdateForDebugMode();
  693. return false;
  694. }
  695. Initializer.DebugText.text = "U1";
  696. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  697. Initializer.DebugText.text = "U2";
  698. List<AssetBundleSet> assetBundleSets = AssetBundleUtility.GetAssetBundleSetsFromFolders
  699. (
  700. persistentFolderPath
  701. );
  702. Initializer.DebugText.text = "U3";
  703. string localMD5 = AssetBundleUtility.GetMD5OfAssetBundleSets(assetBundleSets);
  704. bool needUpdate;
  705. if (string.IsNullOrEmpty(HttpManager.Md5) || string.IsNullOrEmpty(HttpManager.Md5Dictionnary) || string.IsNullOrEmpty(HttpManager.AssetbundleUrl))
  706. {
  707. needUpdate = false;
  708. Debug.LogWarning($"NeedUpdate : {needUpdate} connection error");
  709. }
  710. else
  711. {
  712. //Debug.Log(localMD5);
  713. //Debug.Log(HttpManager.Md5);
  714. needUpdate = localMD5 != HttpManager.Md5;
  715. //Debug.LogWarning($"NeedUpdate : {needUpdate}");
  716. }
  717. if (Application.isEditor || Application.isMobilePlatform)
  718. {
  719. needUpdate = false;
  720. }
  721. AssetBundleUtility.OnDownloadOrUpdateFinish += FinishDownloadAndLoad;
  722. if (needUpdate)
  723. {
  724. Initializer.DebugText.text = "U4";
  725. UpdateAmt = AssetBundleUtility.UpdateAllAssetBundle
  726. (
  727. HttpManager.Md5Dictionnary,
  728. persistentFolderPath,
  729. assetBundleSets,
  730. DownloadAllAssetBundleSucceed,
  731. DownloadAllAssetBundleFailed,
  732. DownloadAssetBundleSucceed,
  733. DownloadAssetBundleFailed
  734. );
  735. UpdatePanel.Show();
  736. UpdatePanel.SetProgress(UpdateAmt, 0);
  737. }
  738. else
  739. {
  740. Initializer.DebugText.text = "U5";
  741. AssetBundleUtility.LoadAllAssetBundle
  742. (
  743. assetBundleSets,
  744. DownloadAllAssetBundleSucceed,
  745. DownloadAllAssetBundleFailed,
  746. DownloadAssetBundleSucceed,
  747. DownloadAssetBundleFailed
  748. );
  749. }
  750. return false;
  751. }
  752. catch (Exception)
  753. {
  754. Initializer.EnableDebugLab();
  755. return true;
  756. }
  757. }
  758. private static void FinishDownloadAndLoad()
  759. {
  760. try
  761. {
  762. Initializer.DebugText.text = "01";
  763. //NewDressroomConfigs = ConfigManager.GetDressRoomConfig(NewDressConfig.LoadAsset<TextAsset>(ResourceLabel.NewDressroomConfig));
  764. Initializer.DebugText.text = "02";
  765. TextAsset[] textAssets = NewDressSke.LoadAllAssets<TextAsset>();
  766. foreach (var textAsset in textAssets)
  767. {
  768. UnityFactory.factory.LoadDragonBonesData(textAsset);
  769. }
  770. Initializer.DebugText.text = "03";
  771. textAssets = NewDressTex.LoadAllAssets<TextAsset>();
  772. Texture2D[] textures = NewDressTex.LoadAllAssets<Texture2D>();
  773. for (int i = 0; i < textAssets.Length; i++)
  774. {
  775. ResourceManager.ObjectDictionary.Add(textures[i].name, textures[i]);
  776. UnityFactory.factory.LoadTextureAtlasData(textAssets[i], textures[i].name);
  777. }
  778. Initializer.DebugText.text = "04";
  779. Sprite[] sprites = NewDressTex.LoadAllAssets<Sprite>();
  780. for (int i = 0; i < sprites.Length; i++)
  781. {
  782. PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
  783. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  784. }
  785. Initializer.DebugText.text = "051";
  786. TextAsset language = Config.LoadAsset<TextAsset>(ResourceLabel.English);
  787. XmlDocument document = new XmlDocument();
  788. document.LoadXml(language.text);
  789. Language.AddLanguageDocument(CurrentLanguage.English, document);
  790. Initializer.DebugText.text = "061";
  791. language = Config.LoadAsset<TextAsset>(ResourceLabel.ChineseSimplified);
  792. document = new XmlDocument();
  793. document.LoadXml(language.text);
  794. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  795. Initializer.DebugText.text = "071";
  796. language = Config.LoadAsset<TextAsset>(ResourceLabel.ChineseTraditional);
  797. document = new XmlDocument();
  798. document.LoadXml(language.text);
  799. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  800. //Initializer.DebugText.text = "052";
  801. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewEnglish);
  802. //document = new XmlDocument();
  803. //document.LoadXml(language.text);
  804. //Language.AddLanguageDocument(CurrentLanguage.English, document);
  805. //Initializer.DebugText.text = "062";
  806. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseSimplified);
  807. //document = new XmlDocument();
  808. //document.LoadXml(language.text);
  809. //Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  810. //Initializer.DebugText.text = "072";
  811. //language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseTraditional);
  812. //document = new XmlDocument();
  813. //document.LoadXml(language.text);
  814. //Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  815. Initializer.DebugText.text = "08";
  816. //NewFlowerConfigs = ConfigManager.GetFlowerConfig(NewFlowerConfig.LoadAsset<TextAsset>(ResourceLabel.NewFlowerConfig));
  817. Initializer.DebugText.text = "09";
  818. sprites = NewFlowerTex.LoadAllAssets<Sprite>();
  819. for (int i = 0; i < sprites.Length; i++)
  820. {
  821. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  822. }
  823. UpdateComplete = true;
  824. DelayCall.Call(1f, UpdatePanel.Hide);
  825. }
  826. catch (Exception e)
  827. {
  828. Debug.Log(e);
  829. Initializer.DebugText.text += e.ToString();
  830. Initializer.EnableDebugLab();
  831. }
  832. }
  833. public static void DownloadAllAssetBundleSucceed()
  834. {
  835. //Debug.Log("succeed");
  836. }
  837. public static void DownloadAllAssetBundleFailed()
  838. {
  839. Debug.Log("failed");
  840. }
  841. public static void DownloadAssetBundleSucceed(AssetBundleSet assetBundleSet, bool isDownload)
  842. {
  843. //Debug.Log(assetBundleSet.AssetBundle.name);
  844. //if (assetBundleSet.Name == ResourceLabel.NewDressConfig)
  845. //{
  846. // NewDressConfig = assetBundleSet.AssetBundle;
  847. //}
  848. if (assetBundleSet.Name == ResourceLabel.NewDressSke)
  849. {
  850. NewDressSke = assetBundleSet.AssetBundle;
  851. }
  852. else if (assetBundleSet.Name == ResourceLabel.NewDressTex)
  853. {
  854. NewDressTex = assetBundleSet.AssetBundle;
  855. }
  856. else if (assetBundleSet.Name == ResourceLabel.Config)
  857. {
  858. Config = assetBundleSet.AssetBundle;
  859. }
  860. //else if (assetBundleSet.Name == ResourceLabel.NewLanguage)
  861. //{
  862. // NewLanguage = assetBundleSet.AssetBundle;
  863. //}
  864. //else if (assetBundleSet.Name == ResourceLabel.NewFlowerConfig)
  865. //{
  866. // NewFlowerConfig = assetBundleSet.AssetBundle;
  867. //}
  868. else if (assetBundleSet.Name == ResourceLabel.NewFlowerTex)
  869. {
  870. NewFlowerTex = assetBundleSet.AssetBundle;
  871. }
  872. if (isDownload)
  873. {
  874. UpdateFinishAmt++;
  875. UpdatePanel.SetProgress(UpdateAmt, UpdateFinishAmt);
  876. }
  877. }
  878. public static void DownloadAssetBundleFailed(AssetBundleSet assetBundleSet, string error)
  879. {
  880. Debug.Log(error);
  881. string path = assetBundleSet.PersistentPath;
  882. path = path.Replace("/", Path.DirectorySeparatorChar.ToString());
  883. path = path.Replace("\\", Path.DirectorySeparatorChar.ToString());
  884. path = path.Replace("\\\\", Path.DirectorySeparatorChar.ToString());
  885. path = "file://" + path;
  886. WWW www = new WWW(path);
  887. AssetBundleSet bundleSet = new AssetBundleSet();
  888. bundleSet.Name = assetBundleSet.Name;
  889. bundleSet.AssetBundle = www.assetBundle;
  890. DownloadAssetBundleSucceed(bundleSet, false);
  891. //string str = Language.GetStr(LanguageLabel.UI__AJ_UpdateFailed, Application.systemLanguage) + " " + error;
  892. //UpdatePanel.SetContent(str);
  893. //Initializer.DebugText.text = assetBundleSet.Name;
  894. //Initializer.DebugText.text += error;
  895. //Initializer.EnableDebugLab();
  896. }
  897. public static void SkipUpdateForDebugMode()
  898. {
  899. //NewDressroomConfigs = ConfigManager.GetDressRoomConfig(Instance.NewDressConfigList[0] as TextAsset);
  900. foreach (var textAsset in Instance.NewDressSkeList)
  901. {
  902. UnityFactory.factory.LoadDragonBonesData(textAsset as TextAsset);
  903. }
  904. for (int i = 0; i < Instance.NewDressTexList.Count; i++)
  905. {
  906. TextAsset textAsset = Instance.NewDressTexConfigList[i] as TextAsset;
  907. Texture2D texture = Instance.NewDressTexList[i] as Texture2D;
  908. ResourceManager.ObjectDictionary.Add(texture.name, texture);
  909. UnityFactory.factory.LoadTextureAtlasData(textAsset, texture.name);
  910. }
  911. for (int i = 0; i < Instance.NewDressSpriteList.Count; i++)
  912. {
  913. Sprite sprite = Instance.NewDressSpriteList[i] as Sprite;
  914. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  915. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  916. }
  917. for (int i = 0; i < Instance.ConfigList.Count; i++)
  918. {
  919. TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
  920. if (textAsset.name == ResourceLabel.English)
  921. {
  922. XmlDocument document = new XmlDocument();
  923. document.LoadXml(textAsset.text);
  924. Language.AddLanguageDocument(CurrentLanguage.English, document);
  925. }
  926. else if (textAsset.name == ResourceLabel.ChineseSimplified)
  927. {
  928. XmlDocument document = new XmlDocument();
  929. document.LoadXml(textAsset.text);
  930. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  931. }
  932. else if (textAsset.name == ResourceLabel.ChineseTraditional)
  933. {
  934. XmlDocument document = new XmlDocument();
  935. document.LoadXml(textAsset.text);
  936. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  937. }
  938. }
  939. for (int i = 0; i < Instance.DefaultList.Count; i++)
  940. {
  941. TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
  942. if (textAsset.name == ResourceLabel.English)
  943. {
  944. XmlDocument document = new XmlDocument();
  945. document.LoadXml(textAsset.text);
  946. Language.AddLanguageDocument(CurrentLanguage.English, document);
  947. }
  948. else if (textAsset.name == ResourceLabel.ChineseSimplified)
  949. {
  950. XmlDocument document = new XmlDocument();
  951. document.LoadXml(textAsset.text);
  952. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  953. }
  954. else if (textAsset.name == ResourceLabel.ChineseTraditional)
  955. {
  956. XmlDocument document = new XmlDocument();
  957. document.LoadXml(textAsset.text);
  958. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  959. }
  960. }
  961. //NewFlowerConfigs = ConfigManager.GetDressRoomConfig(Instance.NewFlowerConfigList[0] as TextAsset);
  962. foreach (var obj in Instance.NewFlowerSpriteList)
  963. {
  964. Sprite sprite = obj as Sprite;
  965. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  966. }
  967. UpdateComplete = true;
  968. }
  969. }