Bundle.cs 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  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 GetPersistingPath()
  371. {
  372. if (Application.platform == RuntimePlatform.IPhonePlayer)
  373. return "file://" + Application.persistentDataPath;
  374. else if (Application.isMobilePlatform)
  375. return Application.streamingAssetsPath;
  376. else
  377. return "file://" + Application.persistentDataPath;
  378. }
  379. public static string GetStreamingUrlPath()
  380. {
  381. if (Application.platform == RuntimePlatform.IPhonePlayer)
  382. return "file://" + Application.streamingAssetsPath;
  383. else if (Application.isMobilePlatform)
  384. return Application.streamingAssetsPath;
  385. else
  386. return "file://" + Application.streamingAssetsPath;
  387. }
  388. public void LoadAll(UnityAction callback)
  389. {
  390. Initializer.Instance.StartCoroutine(ILoadAll(callback));
  391. }
  392. public static IEnumerator ILoadAll(UnityAction callback)
  393. {
  394. yield return LoadConfig();
  395. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  396. {
  397. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PlayerConfig, Folder.Config, () =>
  398. {
  399. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  400. HttpManager.GetBuyPackLimitFlag();
  401. });
  402. }
  403. else
  404. {
  405. ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
  406. HttpManager.GetBuyPackLimitFlag();
  407. }
  408. //yield return LoadDiscard();
  409. yield return LoadUI();
  410. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  411. {
  412. ResourceManager.AddAsyncLoad(ResourceLabel.Canvas, 1, Folder.UI, ObjType.Canvas);
  413. //ResourceManager.AddAsyncLoad(ResourceLabel.GroupA, 1, Folder.UI, ObjType.GroupA, true);
  414. //ResourceManager.AddAsyncLoad(ResourceLabel.GroupB, 1, Folder.UI, ObjType.GroupB, true);
  415. //ResourceManager.AddAsyncLoad(ResourceLabel.GroupC, 1, Folder.UI, ObjType.GroupC, true);
  416. //ResourceManager.AddAsyncLoad(ResourceLabel.GroupE, 1, Folder.UI, ObjType.GroupE, true);
  417. //ResourceManager.AddAsyncLoad(ResourceLabel.GroupD, 1, Folder.UI, ObjType.GroupD, true);
  418. ResourceManager.AddAsyncLoad(ResourceLabel.EventSystem, 1, Folder.UI, ObjType.EventSystem);
  419. ResourceManager.AddAsyncLoad(ResourceLabel.MainCamera, 1, Folder.UI, ObjType.MainCamera);
  420. //ResourceManager.AddAsyncLoad("SkillItem", 31, Folder.UI, ObjType.SkillItem, true);
  421. //ResourceManager.AddAsyncLoad("SignItem", 21, Folder.UI, ObjType.SignItem, true);
  422. //ResourceManager.AddAsyncLoad("FlowerItem", 17, Folder.UI, ObjType.FlowerItem, true);
  423. //ResourceManager.AddAsyncLoad("AchieveItem", 2, Folder.UI, ObjType.AchieveItem, true);
  424. }
  425. yield return LoadScene();
  426. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  427. {
  428. ResourceManager.AddAsyncLoad(ResourceLabel.Flower, 9, Folder.Scene, ObjType.Flower);
  429. ResourceManager.AddAsyncLoad(ResourceLabel.Page, 2, Folder.Scene, ObjType.SlotPage);
  430. ResourceManager.AddAsyncLoad(ResourceLabel.Garden, 1, Folder.Scene, ObjType.Garden);
  431. ResourceManager.AddAsyncLoad(ResourceLabel.DressRoom, 1, Folder.UI, ObjType.DressRoom);
  432. }
  433. yield return LoadAudio();
  434. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  435. {
  436. ResourceManager.AddAsyncLoad(ResourceLabel.Music, 1, Folder.Audio, ObjType.Music);
  437. }
  438. yield return LoadAtlas2();
  439. if (!Logo.Complete && !Initializer.Instance.DebugMode)
  440. {
  441. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SkillConfig, Folder.Config);
  442. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PackConfig, Folder.Config);
  443. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AbilityConfig, Folder.Config);
  444. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AchieveConfig, Folder.Config);
  445. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.VisitConfig, Folder.Config);
  446. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AwardConfig, Folder.Config);
  447. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.FlowerConfig, Folder.Config);
  448. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.OfflineConfig, Folder.Config);
  449. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SigninConfig, Folder.Config);
  450. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.DressroomConfig, Folder.Config);
  451. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.English, Folder.Config);
  452. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseSimplified, Folder.Config);
  453. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseTraditional, Folder.Config);
  454. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BtnClip, Folder.Audio);
  455. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.SkillClip, Folder.Audio);
  456. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.ErrorClip, Folder.Audio);
  457. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.DropClip, Folder.Audio);
  458. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CloseClip, Folder.Audio);
  459. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.FlowerClip, Folder.Audio);
  460. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BubbleClip, Folder.Audio);
  461. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CurrentClip, Folder.Audio);
  462. ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.MiniEndClip, Folder.Audio);
  463. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandTex, Folder.Config);
  464. ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandSke, Folder.Config);
  465. ResourceManager.AddAsyncLoad<Texture2D>(ResourceLabel.StandTexture, Folder.Scene);
  466. }
  467. yield return LoadAtlas();
  468. yield return LoadEffect();
  469. SpriteAsset.AddAllBundleSpriteInfo();
  470. if (callback != null)
  471. {
  472. callback.Invoke();
  473. }
  474. }
  475. public static IEnumerator LoadUI()
  476. {
  477. WWW www = new WWW(GetStreamPath() + "ui");
  478. yield return www;
  479. if (string.IsNullOrEmpty(www.error))
  480. {
  481. UI = www.assetBundle;
  482. }
  483. else
  484. {
  485. Debug.Log(www.error);
  486. }
  487. }
  488. public static IEnumerator LoadAtlas()
  489. {
  490. WWW www = new WWW(GetStreamPath() + "atlas");
  491. yield return www;
  492. if (string.IsNullOrEmpty(www.error))
  493. {
  494. Atlas = www.assetBundle;
  495. }
  496. else
  497. {
  498. Debug.Log(www.error);
  499. }
  500. }
  501. public static IEnumerator LoadAtlas2()
  502. {
  503. WWW www = new WWW(GetStreamPath() + "atlas2");
  504. yield return www;
  505. if (string.IsNullOrEmpty(www.error))
  506. {
  507. Atlas2 = www.assetBundle;
  508. }
  509. else
  510. {
  511. Debug.Log(www.error);
  512. }
  513. }
  514. public static IEnumerator LoadAudio()
  515. {
  516. WWW www = new WWW(GetStreamPath() + "audio");
  517. yield return www;
  518. if (string.IsNullOrEmpty(www.error))
  519. {
  520. Audio = www.assetBundle;
  521. }
  522. else
  523. {
  524. Debug.Log(www.error);
  525. }
  526. }
  527. public static IEnumerator LoadConfig()
  528. {
  529. WWW www = new WWW(GetStreamPath() + "config");
  530. yield return www;
  531. if (string.IsNullOrEmpty(www.error))
  532. {
  533. Config = www.assetBundle;
  534. }
  535. else
  536. {
  537. Debug.Log(www.error);
  538. }
  539. }
  540. public static IEnumerator LoadEffect()
  541. {
  542. WWW www = new WWW(GetStreamPath() + "effect");
  543. yield return www;
  544. if (string.IsNullOrEmpty(www.error))
  545. {
  546. Effect = www.assetBundle;
  547. }
  548. else
  549. {
  550. Debug.Log(www.error);
  551. }
  552. }
  553. public static IEnumerator LoadScene()
  554. {
  555. WWW www = new WWW(GetStreamPath() + "scene");
  556. yield return www;
  557. if (string.IsNullOrEmpty(www.error))
  558. {
  559. Scene = www.assetBundle;
  560. }
  561. else
  562. {
  563. Debug.Log(www.error);
  564. }
  565. }
  566. public static IEnumerator LoadDiscard()
  567. {
  568. WWW www = new WWW(GetStreamPath() + "discard");
  569. yield return www;
  570. if (string.IsNullOrEmpty(www.error))
  571. {
  572. Discard = www.assetBundle;
  573. }
  574. else
  575. {
  576. Debug.Log(www.error);
  577. }
  578. }
  579. public static IEnumerator LoadPlazaRoom()
  580. {
  581. WWW www = new WWW(GetStreamPath() + "plazaroom");
  582. yield return www;
  583. if (string.IsNullOrEmpty(www.error))
  584. {
  585. PlazaRoom = www.assetBundle;
  586. }
  587. else
  588. {
  589. Debug.Log(www.error);
  590. }
  591. }
  592. private static int CopyCount = 0;
  593. public static void CopyAssetBundles()
  594. {
  595. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  596. if (!Directory.Exists(persistentFolderPath))
  597. {
  598. Directory.CreateDirectory(persistentFolderPath);
  599. }
  600. string streamingFolder;
  601. if (Application.platform == RuntimePlatform.IPhonePlayer)
  602. {
  603. streamingFolder = "IOS";
  604. }
  605. else if (Application.platform == RuntimePlatform.Android)
  606. {
  607. streamingFolder = "Android";
  608. }
  609. else
  610. {
  611. streamingFolder = "Windows";
  612. }
  613. foreach (var assetBundleName in HotUpdateAssetBundleNames)
  614. {
  615. if (!File.Exists(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName))
  616. {
  617. CopyCount++;
  618. Initializer.Instance.StartCoroutine
  619. (
  620. LoadAssetBundleFromStream
  621. (
  622. streamingFolder,
  623. assetBundleName,
  624. www =>
  625. {
  626. File.WriteAllBytes(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName, www.bytes);
  627. CopyOneAssetBundleFinish();
  628. }
  629. )
  630. );
  631. }
  632. }
  633. }
  634. private static void CopyOneAssetBundleFinish()
  635. {
  636. CopyCount--;
  637. }
  638. public static IEnumerator LoadAssetBundleFromStream(string folder, string name, Action<WWW> callback)
  639. {
  640. WWW www = new WWW(GetStreamingUrlPath() + Path.DirectorySeparatorChar + "Bundle" + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + "HotUpdate" + Path.DirectorySeparatorChar + name);
  641. yield return www;
  642. if (string.IsNullOrEmpty(www.error))
  643. {
  644. callback.Invoke(www);
  645. }
  646. else
  647. {
  648. Debug.Log(www.error);
  649. }
  650. }
  651. public static int UpdateAmt;
  652. public static int UpdateFinishAmt;
  653. public static bool UpdateAssetBundles()
  654. {
  655. //Debug.Log(HttpManager.Md5);
  656. //Debug.Log(HttpManager.Md5Dictionnary);
  657. //Debug.Log(HttpManager.AssetbundleUrl);
  658. try
  659. {
  660. Initializer.DebugText.text = "U0";
  661. if (Initializer.Instance.DebugMode)
  662. {
  663. SkipUpdateForDebugMode();
  664. return false;
  665. }
  666. Initializer.DebugText.text = "U1";
  667. string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
  668. Initializer.DebugText.text = "U2";
  669. List<AssetBundleSet> assetBundleSets = AssetBundleUtility.GetAssetBundleSetsFromFolders
  670. (
  671. persistentFolderPath
  672. );
  673. Initializer.DebugText.text = "U3";
  674. string localMD5 = AssetBundleUtility.GetMD5OfAssetBundleSets(assetBundleSets);
  675. bool needUpdate;
  676. if (string.IsNullOrEmpty(HttpManager.Md5) || string.IsNullOrEmpty(HttpManager.Md5Dictionnary) || string.IsNullOrEmpty(HttpManager.AssetbundleUrl))
  677. {
  678. needUpdate = false;
  679. Debug.LogWarning($"NeedUpdate : {needUpdate} connection error");
  680. }
  681. else
  682. {
  683. //Debug.Log(localMD5);
  684. //Debug.Log(HttpManager.Md5);
  685. needUpdate = localMD5 != HttpManager.Md5;
  686. Debug.LogWarning($"NeedUpdate : {needUpdate}");
  687. }
  688. //if (Application.isEditor)
  689. //{
  690. // needUpdate = false;
  691. //}
  692. AssetBundleUtility.OnDownloadOrUpdateFinish += FinishDownloadAndLoad;
  693. if (needUpdate)
  694. {
  695. Initializer.DebugText.text = "U4";
  696. UpdateAmt = AssetBundleUtility.UpdateAllAssetBundle
  697. (
  698. HttpManager.Md5Dictionnary,
  699. persistentFolderPath,
  700. assetBundleSets,
  701. DownloadAllAssetBundleSucceed,
  702. DownloadAllAssetBundleFailed,
  703. DownloadAssetBundleSucceed,
  704. DownloadAssetBundleFailed
  705. );
  706. UpdatePanel.Show();
  707. UpdatePanel.SetProgress(UpdateAmt, 0);
  708. }
  709. else
  710. {
  711. Initializer.DebugText.text = "U5";
  712. AssetBundleUtility.LoadAllAssetBundle
  713. (
  714. assetBundleSets,
  715. DownloadAllAssetBundleSucceed,
  716. DownloadAllAssetBundleFailed,
  717. DownloadAssetBundleSucceed,
  718. DownloadAssetBundleFailed
  719. );
  720. }
  721. return false;
  722. }
  723. catch (Exception)
  724. {
  725. Initializer.EnableDebugLab();
  726. return true;
  727. }
  728. }
  729. private static void FinishDownloadAndLoad()
  730. {
  731. try
  732. {
  733. Initializer.DebugText.text = "01";
  734. NewDressroomConfigs = ConfigManager.GetDressRoomConfig(NewDressConfig.LoadAsset<TextAsset>(ResourceLabel.NewDressroomConfig));
  735. Initializer.DebugText.text = "02";
  736. TextAsset[] textAssets = NewDressSke.LoadAllAssets<TextAsset>();
  737. foreach (var textAsset in textAssets)
  738. {
  739. UnityFactory.factory.LoadDragonBonesData(textAsset);
  740. }
  741. Initializer.DebugText.text = "03";
  742. textAssets = NewDressTex.LoadAllAssets<TextAsset>();
  743. Texture2D[] textures = NewDressTex.LoadAllAssets<Texture2D>();
  744. for (int i = 0; i < textAssets.Length; i++)
  745. {
  746. ResourceManager.ObjectDictionary.Add(textures[i].name, textures[i]);
  747. UnityFactory.factory.LoadTextureAtlasData(textAssets[i], textures[i].name);
  748. }
  749. Initializer.DebugText.text = "04";
  750. Sprite[] sprites = NewDressTex.LoadAllAssets<Sprite>();
  751. for (int i = 0; i < sprites.Length; i++)
  752. {
  753. PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
  754. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  755. }
  756. Initializer.DebugText.text = "051";
  757. TextAsset language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.English);
  758. XmlDocument document = new XmlDocument();
  759. document.LoadXml(language.text);
  760. Language.AddLanguageDocument(CurrentLanguage.English, document);
  761. Initializer.DebugText.text = "061";
  762. language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.ChineseSimplified);
  763. document = new XmlDocument();
  764. document.LoadXml(language.text);
  765. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  766. Initializer.DebugText.text = "071";
  767. language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.ChineseTraditional);
  768. document = new XmlDocument();
  769. document.LoadXml(language.text);
  770. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  771. Initializer.DebugText.text = "052";
  772. language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewEnglish);
  773. document = new XmlDocument();
  774. document.LoadXml(language.text);
  775. Language.AddLanguageDocument(CurrentLanguage.English, document);
  776. Initializer.DebugText.text = "062";
  777. language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseSimplified);
  778. document = new XmlDocument();
  779. document.LoadXml(language.text);
  780. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  781. Initializer.DebugText.text = "072";
  782. language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseTraditional);
  783. document = new XmlDocument();
  784. document.LoadXml(language.text);
  785. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  786. Initializer.DebugText.text = "08";
  787. NewFlowerConfigs = ConfigManager.GetFlowerConfig(NewFlowerConfig.LoadAsset<TextAsset>(ResourceLabel.NewFlowerConfig));
  788. Initializer.DebugText.text = "09";
  789. sprites = NewFlowerTex.LoadAllAssets<Sprite>();
  790. for (int i = 0; i < sprites.Length; i++)
  791. {
  792. ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
  793. }
  794. UpdateComplete = true;
  795. DelayCall.Call(1f, UpdatePanel.Hide);
  796. }
  797. catch (Exception e)
  798. {
  799. Debug.Log(e);
  800. Initializer.DebugText.text += e.ToString();
  801. Initializer.EnableDebugLab();
  802. }
  803. }
  804. public static void DownloadAllAssetBundleSucceed()
  805. {
  806. Debug.Log("succeed");
  807. }
  808. public static void DownloadAllAssetBundleFailed()
  809. {
  810. Debug.Log("failed");
  811. }
  812. public static void DownloadAssetBundleSucceed(AssetBundleSet assetBundleSet, bool isDownload)
  813. {
  814. if (assetBundleSet.Name == ResourceLabel.NewDressConfig)
  815. {
  816. NewDressConfig = assetBundleSet.AssetBundle;
  817. }
  818. else if (assetBundleSet.Name == ResourceLabel.NewDressSke)
  819. {
  820. NewDressSke = assetBundleSet.AssetBundle;
  821. }
  822. else if (assetBundleSet.Name == ResourceLabel.NewDressTex)
  823. {
  824. NewDressTex = assetBundleSet.AssetBundle;
  825. }
  826. else if (assetBundleSet.Name == ResourceLabel.NewLanguage)
  827. {
  828. NewLanguage = assetBundleSet.AssetBundle;
  829. }
  830. else if (assetBundleSet.Name == ResourceLabel.NewFlowerConfig)
  831. {
  832. NewFlowerConfig = assetBundleSet.AssetBundle;
  833. }
  834. else if (assetBundleSet.Name == ResourceLabel.NewFlowerTex)
  835. {
  836. NewFlowerTex = assetBundleSet.AssetBundle;
  837. }
  838. if (isDownload)
  839. {
  840. UpdateFinishAmt++;
  841. UpdatePanel.SetProgress(UpdateAmt, UpdateFinishAmt);
  842. }
  843. }
  844. public static void DownloadAssetBundleFailed(AssetBundleSet assetBundleSet, string error)
  845. {
  846. Debug.Log(error);
  847. string path = assetBundleSet.PersistentPath;
  848. path = path.Replace("/", Path.DirectorySeparatorChar.ToString());
  849. path = path.Replace("\\", Path.DirectorySeparatorChar.ToString());
  850. path = path.Replace("\\\\", Path.DirectorySeparatorChar.ToString());
  851. path = "file://" + path;
  852. WWW www = new WWW(path);
  853. AssetBundleSet bundleSet = new AssetBundleSet();
  854. bundleSet.Name = assetBundleSet.Name;
  855. bundleSet.AssetBundle = www.assetBundle;
  856. DownloadAssetBundleSucceed(bundleSet, false);
  857. //string str = Language.GetStr(LanguageLabel.UI__AJ_UpdateFailed, Application.systemLanguage) + " " + error;
  858. //UpdatePanel.SetContent(str);
  859. //Initializer.DebugText.text = assetBundleSet.Name;
  860. //Initializer.DebugText.text += error;
  861. //Initializer.EnableDebugLab();
  862. }
  863. public static void SkipUpdateForDebugMode()
  864. {
  865. NewDressroomConfigs = ConfigManager.GetDressRoomConfig(Instance.NewDressConfigList[0] as TextAsset);
  866. foreach (var textAsset in Instance.NewDressSkeList)
  867. {
  868. UnityFactory.factory.LoadDragonBonesData(textAsset as TextAsset);
  869. }
  870. for (int i = 0; i < Instance.NewDressTexList.Count; i++)
  871. {
  872. TextAsset textAsset = Instance.NewDressTexConfigList[i] as TextAsset;
  873. Texture2D texture = Instance.NewDressTexList[i] as Texture2D;
  874. ResourceManager.ObjectDictionary.Add(texture.name, texture);
  875. UnityFactory.factory.LoadTextureAtlasData(textAsset, texture.name);
  876. }
  877. for (int i = 0; i < Instance.NewDressSpriteList.Count; i++)
  878. {
  879. Sprite sprite = Instance.NewDressSpriteList[i] as Sprite;
  880. PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
  881. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  882. }
  883. for (int i = 0; i < Instance.NewLanguageList.Count; i++)
  884. {
  885. TextAsset textAsset = Instance.NewLanguageList[i] as TextAsset;
  886. if (textAsset.name == ResourceLabel.NewEnglish)
  887. {
  888. XmlDocument document = new XmlDocument();
  889. document.LoadXml(textAsset.text);
  890. Language.AddLanguageDocument(CurrentLanguage.English, document);
  891. }
  892. else if (textAsset.name == ResourceLabel.NewChineseSimplified)
  893. {
  894. XmlDocument document = new XmlDocument();
  895. document.LoadXml(textAsset.text);
  896. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  897. }
  898. else if (textAsset.name == ResourceLabel.NewChineseTraditional)
  899. {
  900. XmlDocument document = new XmlDocument();
  901. document.LoadXml(textAsset.text);
  902. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  903. }
  904. else if (textAsset.name == ResourceLabel.English)
  905. {
  906. XmlDocument document = new XmlDocument();
  907. document.LoadXml(textAsset.text);
  908. Language.AddLanguageDocument(CurrentLanguage.English, document);
  909. }
  910. else if (textAsset.name == ResourceLabel.ChineseSimplified)
  911. {
  912. XmlDocument document = new XmlDocument();
  913. document.LoadXml(textAsset.text);
  914. Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
  915. }
  916. else if (textAsset.name == ResourceLabel.ChineseTraditional)
  917. {
  918. XmlDocument document = new XmlDocument();
  919. document.LoadXml(textAsset.text);
  920. Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
  921. }
  922. }
  923. NewFlowerConfigs = ConfigManager.GetDressRoomConfig(Instance.NewFlowerConfigList[0] as TextAsset);
  924. foreach (var obj in Instance.NewFlowerSpriteList)
  925. {
  926. Sprite sprite = obj as Sprite;
  927. ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
  928. }
  929. UpdateComplete = true;
  930. }
  931. }