123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- 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 Effect;
- public static AssetBundle Audio;
- public static AssetBundle Scene;
- public static AssetBundle Config;
- #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 LoadConfig();
- if (!Logo.LogoComplete)
- {
- ManaReso.AddAsyncLoad("ability_config", Folder.Config);
- ManaReso.AddAsyncLoad("achieve_config", Folder.Config);
- ManaReso.AddAsyncLoad("award_config", Folder.Config);
- ManaReso.AddAsyncLoad("flower_config", Folder.Config);
- ManaReso.AddAsyncLoad("offline_config", Folder.Config);
- ManaReso.AddAsyncLoad("pack_config", Folder.Config);
- ManaReso.AddAsyncLoad("signin_config", Folder.Config);
- ManaReso.AddAsyncLoad("skill_config", Folder.Config);
- ManaReso.AddAsyncLoad("English", Folder.Config);
- ManaReso.AddAsyncLoad("ChineseSimplified", Folder.Config);
- ManaReso.AddAsyncLoad("ChineseTraditional", Folder.Config);
- }
- yield return LoadUI();
- if (!Logo.LogoComplete)
- {
- ManaReso.AddAsyncLoad<ObjRoot>("EventSystem", 1, Folder.UI, ObjType.EventSystem);
- ManaReso.AddAsyncLoad<ObjRoot>("MainCamera", 1, Folder.UI, ObjType.MainCamera);
- ManaReso.AddAsyncLoad<ObjRoot>("Canvas", 1, Folder.UI, ObjType.Canvas);
- }
- yield return LoadScene();
- if (!Logo.LogoComplete)
- {
- if (Data.GetPlayerBool("TutorialA") && Data.GetPlayerInt("TutorialIndexA") == 1)
- {
- ManaReso.AddAsyncPlayer("PlayerPink");
- ManaReso.AddAsyncPlayer("PlayerBlond");
- ManaReso.AddAsyncPlayer("PlayerBrown");
- }
- else
- {
- ManaReso.AddAsyncPlayer(Data.GetPlayerString("Player"));
- }
- ManaReso.AddAsyncLoad<Flower>("Flower", 9, Folder.Scene, ObjType.Flower);
- ManaReso.AddAsyncLoad<ObjRoot>("Page", 2, Folder.Scene, ObjType.Page);
- ManaReso.AddAsyncLoad<ObjRoot>("Garden", 1, Folder.Scene, ObjType.Garden);
- }
- yield return LoadAudio();
- if (!Logo.LogoComplete)
- {
- ManaReso.AddAsyncLoad<ObjRoot>("Music", 1, Folder.Audio, ObjType.Music);
- ManaReso.AddAsyncLoad("BtnClip", Folder.Audio);
- ManaReso.AddAsyncLoad("SkillClip", Folder.Audio);
- ManaReso.AddAsyncLoad("ErrorClip", Folder.Audio);
- ManaReso.AddAsyncLoad("DropClip", Folder.Audio);
- ManaReso.AddAsyncLoad("CloseClip", Folder.Audio);
- ManaReso.AddAsyncLoad("FlowerClip", Folder.Audio);
- ManaReso.AddAsyncLoad("BubbleClip", Folder.Audio);
- ManaReso.AddAsyncLoad("CurrentClip", Folder.Audio);
- ManaReso.AddAsyncLoad("MiniEndClip", Folder.Audio);
- }
- yield return LoadAtlas();
- yield return LoadEffect();
- 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 LoadAudio()
- {
- WWW www = new WWW(GetStreamPath() + "audio");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Audio = 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 LoadEffect()
- {
- WWW www = new WWW(GetStreamPath() + "effect");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Effect = 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);
- }
- }
- }
|