Bundle.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using System.Collections;
  4. public class Bundle : MonoBehaviour
  5. {
  6. #region
  7. public static bool LoadComplete;
  8. public static Bundle Instance;
  9. public static AssetBundle UI;
  10. public static AssetBundle Skill;
  11. public static AssetBundle Config;
  12. public static AssetBundle Object;
  13. public static AssetBundle Shader;
  14. public static AssetBundle Garden;
  15. public static AssetBundle Character;
  16. public static AssetBundle TempUI;
  17. public static AssetBundle TempSkill;
  18. public static AssetBundle TempConfig;
  19. public static AssetBundle TempObject;
  20. public static AssetBundle TempShader;
  21. public static AssetBundle TempGarden;
  22. public static AssetBundle TempCharacter;
  23. #endregion
  24. public void Awake()
  25. {
  26. Instance = this;
  27. DontDestroyOnLoad(gameObject);
  28. LoadAll
  29. (
  30. () => LoadComplete = true
  31. );
  32. }
  33. public static string GetStreamPath()
  34. {
  35. return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";
  36. }
  37. public void LoadAll(UnityAction callback)
  38. {
  39. StartCoroutine(ILoadAll(callback));
  40. }
  41. public static IEnumerator ILoadAll(UnityAction callback)
  42. {
  43. yield return LoadUI();
  44. yield return LoadSkill();
  45. yield return LoadConfig();
  46. yield return LoadObject();
  47. yield return LoadShader();
  48. yield return LoadGarden();
  49. yield return LoadCharacter();
  50. if (callback != null)
  51. {
  52. callback.Invoke();
  53. }
  54. }
  55. public static IEnumerator LoadUI()
  56. {
  57. WWW www = new WWW(GetStreamPath() + "ui");
  58. yield return www;
  59. if (string.IsNullOrEmpty(www.error))
  60. {
  61. UI = www.assetBundle;
  62. }
  63. else
  64. {
  65. Debug.Log(www.error);
  66. }
  67. www = new WWW(GetStreamPath() + "uitemp");
  68. yield return www;
  69. if (string.IsNullOrEmpty(www.error))
  70. {
  71. TempUI = www.assetBundle;
  72. }
  73. }
  74. public static IEnumerator LoadSkill()
  75. {
  76. WWW www = new WWW(GetStreamPath() + "skill");
  77. yield return www;
  78. if (string.IsNullOrEmpty(www.error))
  79. {
  80. Skill = www.assetBundle;
  81. }
  82. else
  83. {
  84. Debug.Log(www.error);
  85. }
  86. www = new WWW(GetStreamPath() + "skilltemp");
  87. yield return www;
  88. if (string.IsNullOrEmpty(www.error))
  89. {
  90. TempSkill = www.assetBundle;
  91. }
  92. }
  93. public static IEnumerator LoadConfig()
  94. {
  95. WWW www = new WWW(GetStreamPath() + "config");
  96. yield return www;
  97. if (string.IsNullOrEmpty(www.error))
  98. {
  99. Config = www.assetBundle;
  100. }
  101. else
  102. {
  103. Debug.Log(www.error);
  104. }
  105. www = new WWW(GetStreamPath() + "configtemp");
  106. yield return www;
  107. if (string.IsNullOrEmpty(www.error))
  108. {
  109. TempConfig = www.assetBundle;
  110. }
  111. }
  112. public static IEnumerator LoadObject()
  113. {
  114. WWW www = new WWW(GetStreamPath() + "object");
  115. yield return www;
  116. if (string.IsNullOrEmpty(www.error))
  117. {
  118. Object = www.assetBundle;
  119. }
  120. else
  121. {
  122. Debug.Log(www.error);
  123. }
  124. www = new WWW(GetStreamPath() + "objecttemp");
  125. yield return www;
  126. if (string.IsNullOrEmpty(www.error))
  127. {
  128. TempObject = www.assetBundle;
  129. }
  130. }
  131. public static IEnumerator LoadShader()
  132. {
  133. WWW www = new WWW(GetStreamPath() + "shader");
  134. yield return www;
  135. if (string.IsNullOrEmpty(www.error))
  136. {
  137. Shader = www.assetBundle;
  138. }
  139. else
  140. {
  141. Debug.Log(www.error);
  142. }
  143. www = new WWW(GetStreamPath() + "shadertemp");
  144. yield return www;
  145. if (string.IsNullOrEmpty(www.error))
  146. {
  147. TempShader = www.assetBundle;
  148. }
  149. }
  150. public static IEnumerator LoadGarden()
  151. {
  152. WWW www = new WWW(GetStreamPath() + "garden");
  153. yield return www;
  154. if (string.IsNullOrEmpty(www.error))
  155. {
  156. Garden = www.assetBundle;
  157. }
  158. else
  159. {
  160. Debug.Log(www.error);
  161. }
  162. www = new WWW(GetStreamPath() + "gardentemp");
  163. yield return www;
  164. if (string.IsNullOrEmpty(www.error))
  165. {
  166. TempGarden = www.assetBundle;
  167. }
  168. }
  169. public static IEnumerator LoadCharacter()
  170. {
  171. WWW www = new WWW(GetStreamPath() + "character");
  172. yield return www;
  173. if (string.IsNullOrEmpty(www.error))
  174. {
  175. Character = www.assetBundle;
  176. }
  177. else
  178. {
  179. Debug.Log(www.error);
  180. }
  181. www = new WWW(GetStreamPath() + "charactertemp");
  182. yield return www;
  183. if (string.IsNullOrEmpty(www.error))
  184. {
  185. TempCharacter = www.assetBundle;
  186. }
  187. }
  188. }