using System; using UnityEngine; using UnityEngine.Events; using System.Collections; using System.Diagnostics; using Debug = UnityEngine.Debug; public class Bundle : Regist { #region public static bool LoadComplete; public static Bundle Instance; public static AssetBundle UI; public static AssetBundle Atlas; public static AssetBundle Scene; public static AssetBundle Config; public static AssetBundle Shader; #endregion public override void RegistImmed() { if (RegistFlag) { return; } else { RegistFlag = true; } enabled = true; Instance = this; LoadAll ( () => LoadComplete = true ); } public static string GetStreamPath() { if (Application.isEditor) // return "file://" + System.Environment.CurrentDirectory.Replace("\\", "/"); // Use the build output folder directly. return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/";//user local stream else if (Application.isWebPlayer) return System.IO.Path.GetDirectoryName(Application.absoluteURL).Replace("\\", "/") + "/StreamingAssets"; else if (Application.platform == RuntimePlatform.IPhonePlayer) return "file://" + Application.streamingAssetsPath + "/Bundle/IOS/"; else if (Application.isMobilePlatform || Application.isConsolePlatform) return Application.streamingAssetsPath + "/Bundle/Android/"; else // For standalone player. return "file://" + Application.streamingAssetsPath; //return "file://" + Application.streamingAssetsPath + "/Bundle/Windows/"; } public void LoadAll(UnityAction callback) { StartCoroutine(ILoadAll(callback)); } public static IEnumerator ILoadAll(UnityAction callback) { yield return LoadUI(); if (!Logo.LogoComplete) { ManaReso.AddAsyncLoad("Canvas", Folder.UI, ObjType.Canvas); ManaReso.AddAsyncLoad("EventSystem", Folder.UI, ObjType.EventSystem); ManaReso.AddAsyncLoad("MainCamera", Folder.UI, ObjType.MainCamera); } yield return LoadScene(); if (!Logo.LogoComplete) { ManaReso.AddAsyncLoad("Flower", Folder.Scene, ObjType.Flower); ManaReso.AddAsyncLoad("Page", Folder.Scene, ObjType.Page); ManaReso.AddAsyncLoad("Garden", Folder.Scene, ObjType.Garden); ManaReso.AddAsyncLoad("MusicMini", Folder.Scene, ObjType.MusicMini); ManaReso.AddAsyncLoad("MusicTheme", Folder.Scene, ObjType.MusicTheme); } yield return LoadAtlas(); yield return LoadConfig(); yield return LoadShader(); if (callback != null) { callback.Invoke(); } } public static IEnumerator LoadUI() { WWW www = new WWW(GetStreamPath() + "ui"); yield return www; if (string.IsNullOrEmpty(www.error)) { UI = www.assetBundle; } else { Debug.Log(www.error); } } public static IEnumerator LoadAtlas() { WWW www = new WWW(GetStreamPath() + "atlas"); yield return www; if (string.IsNullOrEmpty(www.error)) { Atlas = www.assetBundle; } else { Debug.Log(www.error); } } public static IEnumerator LoadConfig() { WWW www = new WWW(GetStreamPath() + "config"); yield return www; if (string.IsNullOrEmpty(www.error)) { Config = www.assetBundle; } else { Debug.Log(www.error); } } public static IEnumerator LoadShader() { WWW www = new WWW(GetStreamPath() + "shader"); yield return www; if (string.IsNullOrEmpty(www.error)) { Shader = www.assetBundle; } else { Debug.Log(www.error); } } public static IEnumerator LoadScene() { WWW www = new WWW(GetStreamPath() + "scene"); yield return www; if (string.IsNullOrEmpty(www.error)) { Scene = www.assetBundle; } else { Debug.Log(www.error); } } }