Bundle.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using System.Collections;
  5. using System.Diagnostics;
  6. using Debug = UnityEngine.Debug;
  7. public class Bundle : Regist
  8. {
  9. #region
  10. public static bool LoadComplete;
  11. public static Bundle Instance;
  12. public static AssetBundle UI;
  13. public static AssetBundle Atlas;
  14. public static AssetBundle Effect;
  15. public static AssetBundle Audio;
  16. public static AssetBundle Scene;
  17. public static AssetBundle Config;
  18. #endregion
  19. public override void RegistImmed()
  20. {
  21. if (RegistFlag)
  22. {
  23. return;
  24. }
  25. else
  26. {
  27. RegistFlag = true;
  28. }
  29. enabled = true;
  30. Instance = this;
  31. LoadAll
  32. (
  33. () => LoadComplete = true
  34. );
  35. }
  36. public static string GetStreamPath()
  37. {
  38. if (Application.isEditor)
  39. // return "file://" + System.Environment.CurrentDirectory.Replace("\\", "/"); // Use the build output folder directly.
  40. return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";//user local stream
  41. else if (Application.isWebPlayer)
  42. return System.IO.Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/StreamingAssets";
  43. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  44. return "file://" + Application.streamingAssetsPath + "/Bundle/IOS/";
  45. else if (Application.isMobilePlatform || Application.isConsolePlatform)
  46. return Application.streamingAssetsPath + "/Bundle/Android/";
  47. else // For standalone player.
  48. return "file://" + Application.streamingAssetsPath;
  49. //return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";
  50. }
  51. public void LoadAll(UnityAction callback)
  52. {
  53. StartCoroutine(ILoadAll(callback));
  54. }
  55. public static IEnumerator ILoadAll(UnityAction callback)
  56. {
  57. yield return LoadConfig();
  58. if (!Logo.LogoComplete)
  59. {
  60. ManaReso.AddAsyncLoad("ability_config", Folder.Config);
  61. ManaReso.AddAsyncLoad("achieve_config", Folder.Config);
  62. ManaReso.AddAsyncLoad("award_config", Folder.Config);
  63. ManaReso.AddAsyncLoad("flower_config", Folder.Config);
  64. ManaReso.AddAsyncLoad("offline_config", Folder.Config);
  65. ManaReso.AddAsyncLoad("pack_config", Folder.Config);
  66. ManaReso.AddAsyncLoad("signin_config", Folder.Config);
  67. ManaReso.AddAsyncLoad("skill_config", Folder.Config);
  68. ManaReso.AddAsyncLoad("English", Folder.Config);
  69. ManaReso.AddAsyncLoad("ChineseSimplified", Folder.Config);
  70. ManaReso.AddAsyncLoad("ChineseTraditional", Folder.Config);
  71. }
  72. yield return LoadUI();
  73. if (!Logo.LogoComplete)
  74. {
  75. ManaReso.AddAsyncLoad<ObjRoot>("EventSystem", 1, Folder.UI, ObjType.EventSystem);
  76. ManaReso.AddAsyncLoad<ObjRoot>("MainCamera", 1, Folder.UI, ObjType.MainCamera);
  77. ManaReso.AddAsyncLoad<ObjRoot>("Canvas", 1, Folder.UI, ObjType.Canvas);
  78. }
  79. yield return LoadScene();
  80. if (!Logo.LogoComplete)
  81. {
  82. if (Data.GetPlayerBool("TutorialA") && Data.GetPlayerInt("TutorialIndexA") == 1)
  83. {
  84. ManaReso.AddAsyncPlayer("PlayerPink");
  85. ManaReso.AddAsyncPlayer("PlayerBlond");
  86. ManaReso.AddAsyncPlayer("PlayerBrown");
  87. }
  88. else
  89. {
  90. ManaReso.AddAsyncPlayer(Data.GetPlayerString("Player"));
  91. }
  92. ManaReso.AddAsyncLoad<Flower>("Flower", 9, Folder.Scene, ObjType.Flower);
  93. ManaReso.AddAsyncLoad<ObjRoot>("Page", 2, Folder.Scene, ObjType.Page);
  94. ManaReso.AddAsyncLoad<ObjRoot>("Garden", 1, Folder.Scene, ObjType.Garden);
  95. }
  96. yield return LoadAudio();
  97. if (!Logo.LogoComplete)
  98. {
  99. ManaReso.AddAsyncLoad<ObjRoot>("Music", 1, Folder.Audio, ObjType.Music);
  100. ManaReso.AddAsyncLoad("BtnClip", Folder.Audio);
  101. ManaReso.AddAsyncLoad("SkillClip", Folder.Audio);
  102. ManaReso.AddAsyncLoad("ErrorClip", Folder.Audio);
  103. ManaReso.AddAsyncLoad("DropClip", Folder.Audio);
  104. ManaReso.AddAsyncLoad("CloseClip", Folder.Audio);
  105. ManaReso.AddAsyncLoad("FlowerClip", Folder.Audio);
  106. ManaReso.AddAsyncLoad("BubbleClip", Folder.Audio);
  107. ManaReso.AddAsyncLoad("CurrentClip", Folder.Audio);
  108. ManaReso.AddAsyncLoad("MiniEndClip", Folder.Audio);
  109. }
  110. yield return LoadAtlas();
  111. yield return LoadEffect();
  112. if (callback != null)
  113. {
  114. callback.Invoke();
  115. }
  116. }
  117. public static IEnumerator LoadUI()
  118. {
  119. WWW www = new WWW(GetStreamPath() + "ui");
  120. yield return www;
  121. if (string.IsNullOrEmpty(www.error))
  122. {
  123. UI = www.assetBundle;
  124. }
  125. else
  126. {
  127. Debug.Log(www.error);
  128. }
  129. }
  130. public static IEnumerator LoadAtlas()
  131. {
  132. WWW www = new WWW(GetStreamPath() + "atlas");
  133. yield return www;
  134. if (string.IsNullOrEmpty(www.error))
  135. {
  136. Atlas = www.assetBundle;
  137. }
  138. else
  139. {
  140. Debug.Log(www.error);
  141. }
  142. }
  143. public static IEnumerator LoadAudio()
  144. {
  145. WWW www = new WWW(GetStreamPath() + "audio");
  146. yield return www;
  147. if (string.IsNullOrEmpty(www.error))
  148. {
  149. Audio = www.assetBundle;
  150. }
  151. else
  152. {
  153. Debug.Log(www.error);
  154. }
  155. }
  156. public static IEnumerator LoadConfig()
  157. {
  158. WWW www = new WWW(GetStreamPath() + "config");
  159. yield return www;
  160. if (string.IsNullOrEmpty(www.error))
  161. {
  162. Config = www.assetBundle;
  163. }
  164. else
  165. {
  166. Debug.Log(www.error);
  167. }
  168. }
  169. public static IEnumerator LoadEffect()
  170. {
  171. WWW www = new WWW(GetStreamPath() + "effect");
  172. yield return www;
  173. if (string.IsNullOrEmpty(www.error))
  174. {
  175. Effect = www.assetBundle;
  176. }
  177. else
  178. {
  179. Debug.Log(www.error);
  180. }
  181. }
  182. public static IEnumerator LoadScene()
  183. {
  184. WWW www = new WWW(GetStreamPath() + "scene");
  185. yield return www;
  186. if (string.IsNullOrEmpty(www.error))
  187. {
  188. Scene = www.assetBundle;
  189. }
  190. else
  191. {
  192. Debug.Log(www.error);
  193. }
  194. }
  195. }