Bundle.cs 39 KB

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