Bundle.cs 35 KB

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