123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using UnityEngine;
- using UnityEngine.Events;
- using System.Collections;
- public class Bundle : MonoBehaviour
- {
- #region
- public static bool LoadComplete;
- public static Bundle Instance;
- public static AssetBundle UI;
- public static AssetBundle Skill;
- public static AssetBundle Config;
- public static AssetBundle Object;
- public static AssetBundle Shader;
- public static AssetBundle Garden;
- public static AssetBundle Character;
- public static AssetBundle TempUI;
- public static AssetBundle TempSkill;
- public static AssetBundle TempConfig;
- public static AssetBundle TempObject;
- public static AssetBundle TempShader;
- public static AssetBundle TempGarden;
- public static AssetBundle TempCharacter;
- #endregion
- public void Awake()
- {
- Instance = this;
- DontDestroyOnLoad(gameObject);
- 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/Andriod/";
- 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();
- yield return LoadSkill();
- yield return LoadConfig();
- yield return LoadObject();
- yield return LoadShader();
- yield return LoadGarden();
- yield return LoadCharacter();
- 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);
- }
- www = new WWW(GetStreamPath() + "uitemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempUI = www.assetBundle;
- }
- }
- public static IEnumerator LoadSkill()
- {
- WWW www = new WWW(GetStreamPath() + "skill");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Skill = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- www = new WWW(GetStreamPath() + "skilltemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempSkill = www.assetBundle;
- }
- }
- 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);
- }
- www = new WWW(GetStreamPath() + "configtemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempConfig = www.assetBundle;
- }
- }
- public static IEnumerator LoadObject()
- {
- WWW www = new WWW(GetStreamPath() + "object");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Object = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- www = new WWW(GetStreamPath() + "objecttemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempObject = www.assetBundle;
- }
- }
- 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);
- }
- www = new WWW(GetStreamPath() + "shadertemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempShader = www.assetBundle;
- }
- }
- public static IEnumerator LoadGarden()
- {
- WWW www = new WWW(GetStreamPath() + "garden");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Garden = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- www = new WWW(GetStreamPath() + "gardentemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempGarden = www.assetBundle;
- }
- }
- public static IEnumerator LoadCharacter()
- {
- WWW www = new WWW(GetStreamPath() + "character");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Character = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- www = new WWW(GetStreamPath() + "charactertemp");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- TempCharacter = www.assetBundle;
- }
- }
- }
|