123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044 |
- using System;
- using UnityEngine;
- using UnityEngine.Events;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Xml;
- using assetBundleUtility;
- using DragonBones;
- #if UNITY_EDITOR
- using UnityEditor;
- #endif
- using Debug = UnityEngine.Debug;
- using Object = UnityEngine.Object;
- public class Bundle : MonoBehaviour
- {
- #region
- public static bool CopyComplete
- {
- get { return CopyCount == 0; }
- }
- public static bool UpdateComplete;
- public static AssetBundle NewDressConfig;
- public static AssetBundle NewDressSke;
- public static AssetBundle NewDressTex;
- public static AssetBundle NewLanguage;
- public static AssetBundle NewFlowerConfig;
- public static AssetBundle NewFlowerTex;
- public static List<XmlAttributeCollection> NewDressroomConfigs = new List<XmlAttributeCollection>();
- public static List<XmlAttributeCollection> NewFlowerConfigs = new List<XmlAttributeCollection>();
- public static List<string> HotUpdateAssetBundleNames=new List<string>
- {
- ResourceLabel.NewDressConfig,
- ResourceLabel.NewDressSke,
- ResourceLabel.NewDressTex,
- ResourceLabel.NewLanguage,
- ResourceLabel.NewFlowerConfig,
- ResourceLabel.NewFlowerTex,
- };
- public List<Object> NewDressConfigList;
- public List<Object> NewDressSkeList;
- public List<Object> NewDressTexList;
- public List<Object> NewDressTexConfigList;
- public List<Object> NewDressSpriteList;
- public List<Object> NewLanguageList;
- public List<Object> NewFlowerConfigList;
- public List<Object> NewFlowerSpriteList;
- public static Bundle Instance;
- public static bool Complete;
- public static AssetBundle Atlas;
- public static AssetBundle Atlas2;
- public static AssetBundle UI;
- public static AssetBundle Effect;
- public static AssetBundle Audio;
- public static AssetBundle Scene;
- public static AssetBundle Config;
- public static AssetBundle Discard;
- public static AssetBundle PlazaRoom;
- public Texture2D AtlasTexture;
- public Texture2D ExpressionTexture;
- public List<Object> UiList;
- public List<Object> AtlasList;
- public List<Sprite> Atlas2List;
- public List<Object> EffectList;
- public List<Object> AudioList;
- public List<Object> SceneList;
- public List<Object> ConfigList;
- public List<Object> DiscardList;
- public List<Object> PlazaRoomList;
- #endregion
- public void Begin()
- {
- Instance = this;
- LoadAll
- (
- () => Complete = true
- );
- }
- public static T Load<T>(string goName, Folder folder) where T : Object
- {
- if (Initializer.Instance.DebugMode)
- {
- #region MyRegion
- if (folder == Folder.UI)
- {
- for (int i = 0; i < Instance.UiList.Count; i++)
- {
- if (Instance.UiList[i].name == goName)
- {
- return (T) Instance.UiList[i];
- }
- }
- }
- else if (folder == Folder.Audio)
- {
- for (int i = 0; i < Instance.AudioList.Count; i++)
- {
- if (Instance.AudioList[i].name == goName)
- {
- return (T) Instance.AudioList[i];
- }
- }
- }
- else if (folder == Folder.Config)
- {
- for (int i = 0; i < Instance.ConfigList.Count; i++)
- {
- if (Instance.ConfigList[i].name == goName)
- {
- return (T) Instance.ConfigList[i];
- }
- }
- }
- else if (folder == Folder.Effect)
- {
- for (int i = 0; i < Instance.EffectList.Count; i++)
- {
- if (Instance.EffectList[i].name == goName)
- {
- return (T) Instance.EffectList[i];
- }
- }
- }
- else if (folder == Folder.Scene)
- {
- if (goName == "Expression")
- {
- return (T) (Object) Sprite.Create(Instance.ExpressionTexture, new Rect(0, 0, Instance.AtlasTexture.width, Instance.AtlasTexture.height), new Vector2(0.5f, 0.5f));
- }
- for (int i = 0; i < Instance.SceneList.Count; i++)
- {
- if (Instance.SceneList[i].name == goName)
- {
- return (T) Instance.SceneList[i];
- }
- }
- }
- else if (folder == Folder.Discard)
- {
- for (int i = 0; i < Instance.DiscardList.Count; i++)
- {
- if (Instance.DiscardList[i].name == goName)
- {
- return (T) Instance.DiscardList[i];
- }
- }
- }
- else if (folder == Folder.Atlas)
- {
- if (goName == "Atlas")
- {
- return (T) (Object) Sprite.Create(Instance.AtlasTexture, new Rect(0, 0, Instance.AtlasTexture.width, Instance.AtlasTexture.height), new Vector2(0.5f, 0.5f));
- }
- for (int i = 0; i < Instance.AtlasList.Count; i++)
- {
- if (Instance.AtlasList[i].name == goName)
- {
- return (T) Instance.AtlasList[i];
- }
- }
- }
- else if (folder == Folder.PlazaRoom)
- {
- for (int i = 0; i < Instance.PlazaRoomList.Count; i++)
- {
- if (Instance.PlazaRoomList[i].name == goName)
- {
- return (T) Instance.PlazaRoomList[i];
- }
- }
- }
- //else if (folder == Folder.Dress)
- //{
- // for (int i = 0; i < Instance.DressList.Count; i++)
- // {
- // if (Instance.DressList[i].name == goName)
- // {
- // return (T)Instance.DressList[i];
- // }
- // }
- //}
- #endregion
- }
- else
- {
- #region MyRegion
- if (folder == Folder.UI)
- {
- return UI.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Audio)
- {
- return Audio.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Config)
- {
- return Config.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Effect)
- {
- return Effect.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Scene)
- {
- return Scene.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Atlas)
- {
- return Atlas.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Atlas2)
- {
- return Atlas2.LoadAsset<T>(goName);
- }
- else if (folder == Folder.Discard)
- {
- return Discard.LoadAsset<T>(goName);
- }
- else if (folder == Folder.PlazaRoom)
- {
- return PlazaRoom.LoadAsset<T>(goName);
- }
- #endregion
- }
- DebugManager.Log(goName + " " + folder);
- throw new Exception(goName + " " + folder);
- }
- public static void LoadAtlasSprites()
- {
- if (Initializer.Instance.DebugMode)
- {
- for (int i = 0; i < Instance.Atlas2List.Count; i++)
- {
- ResourceManager.ObjectDictionary.UniqueAdd(Instance.Atlas2List[i].name, Instance.Atlas2List[i]);
- }
- #if UNITY_EDITOR
- string assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture", Folder.Scene));
- Object[] objects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
- for (int i = 0; i < objects.Length; i++)
- {
- Sprite sprite = objects[i] as Sprite;
- if (sprite != null)
- {
- PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
- ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
- }
- }
- #endif
- }
- else
- {
- #region MyRegion
- Sprite[] sprites = Atlas2.LoadAllAssets<Sprite>();
- for (int i = 0; i < sprites.Length; i++)
- {
- ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- }
- sprites = Atlas.LoadAllAssets<Sprite>();
- for (int i = 0; i < sprites.Length; i++)
- {
- ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- }
- sprites = Scene.LoadAssetWithSubAssets<Sprite>("FlowerItemAtlas1");
- for (int i = 0; i < sprites.Length; i++)
- {
- ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- }
- Object[] objects = Scene.LoadAssetWithSubAssets("stand_texture", typeof(Sprite));
- for (int i = 0; i < objects.Length; i++)
- {
- Sprite sprite = (Sprite) objects[i];
- PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
- ResourceManager.SpriteDictionary.UniqueAdd(sprite.name, sprite);
- }
- #endregion
- }
- }
- //public static void LoadAllDressBundleAssetsIntoDragonbone()
- //{
- // UnityFactory.factory.LoadDragonBonesData(ResourceManager.Load<TextAsset>(DressLabel.Dress_ske, Folder.Dress));
- // foreach (var dressName in DressLabel.dressNames)
- // {
- // ResourceManager.Load<Texture2D>(dressName, Folder.Dress);
- // UnityFactory.factory.LoadTextureAtlasData(ResourceManager.Load<TextAsset>(dressName + "_tex", Folder.Dress), dressName);
- // }
- // Sprite[] sprites = Dress.LoadAllAssets<Sprite>();
- // if (Initializer.Instance.DebugMode)
- // {
- // for (int i = 0; i < Instance.DressList.Count; i++)
- // {
- // Sprite sprite = Instance.DressList[i] as Sprite;
- // if (sprite != null)
- // {
- // PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
- // ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
- // }
- // }
- // }
- // else
- // {
- // for (int i = 0; i < sprites.Length; i++)
- // {
- // PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
- // ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- // }
- // }
- //}
- public static AssetBundleRequest LoadAsync<T>(string goName, Folder folder)
- {
- if (folder == Folder.UI)
- {
- return UI.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Audio)
- {
- return Audio.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Config)
- {
- return Config.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Effect)
- {
- return Effect.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Scene)
- {
- return Scene.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Atlas)
- {
- return Atlas.LoadAssetAsync<T>(goName);
- }
- else if (folder == Folder.Discard)
- {
- return Discard.LoadAssetAsync<T>(goName);
- }
- else
- {
- throw new Exception();
- }
- }
- public static AssetBundleRequest LoadAllAsync<T>(Folder folder)
- {
- if (folder == Folder.Atlas2)
- {
- return Atlas2.LoadAllAssetsAsync<T>();
- }
- else
- {
- throw new Exception();
- }
- }
- 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 static string GetStreamingUrlPath()
- {
- if (Application.platform == RuntimePlatform.IPhonePlayer)
- return "file://" + Application.streamingAssetsPath;
- else if (Application.isMobilePlatform)
- return Application.streamingAssetsPath;
- else
- return "file://" + Application.streamingAssetsPath;
- }
- public void LoadAll(UnityAction callback)
- {
- Initializer.Instance.StartCoroutine(ILoadAll(callback));
- }
- public static IEnumerator ILoadAll(UnityAction callback)
- {
- yield return LoadConfig();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PlayerConfig, Folder.Config, () =>
- {
- ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
- HttpManager.GetBuyPackLimitFlag();
- });
- }
- else
- {
- ConfigManager.ConfigDocument = ConfigManager.ConfigDocument;
- HttpManager.GetBuyPackLimitFlag();
- }
- //yield return LoadDiscard();
- yield return LoadUI();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad(ResourceLabel.Canvas, 1, Folder.UI, ObjType.Canvas);
- //ResourceManager.AddAsyncLoad(ResourceLabel.GroupA, 1, Folder.UI, ObjType.GroupA, true);
- //ResourceManager.AddAsyncLoad(ResourceLabel.GroupB, 1, Folder.UI, ObjType.GroupB, true);
- //ResourceManager.AddAsyncLoad(ResourceLabel.GroupC, 1, Folder.UI, ObjType.GroupC, true);
- //ResourceManager.AddAsyncLoad(ResourceLabel.GroupE, 1, Folder.UI, ObjType.GroupE, true);
- //ResourceManager.AddAsyncLoad(ResourceLabel.GroupD, 1, Folder.UI, ObjType.GroupD, true);
- ResourceManager.AddAsyncLoad(ResourceLabel.EventSystem, 1, Folder.UI, ObjType.EventSystem);
- ResourceManager.AddAsyncLoad(ResourceLabel.MainCamera, 1, Folder.UI, ObjType.MainCamera);
- //ResourceManager.AddAsyncLoad("SkillItem", 31, Folder.UI, ObjType.SkillItem, true);
- //ResourceManager.AddAsyncLoad("SignItem", 21, Folder.UI, ObjType.SignItem, true);
- //ResourceManager.AddAsyncLoad("FlowerItem", 17, Folder.UI, ObjType.FlowerItem, true);
- //ResourceManager.AddAsyncLoad("AchieveItem", 2, Folder.UI, ObjType.AchieveItem, true);
- }
- yield return LoadScene();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad(ResourceLabel.Flower, 9, Folder.Scene, ObjType.Flower);
- ResourceManager.AddAsyncLoad(ResourceLabel.Page, 2, Folder.Scene, ObjType.SlotPage);
- ResourceManager.AddAsyncLoad(ResourceLabel.Garden, 1, Folder.Scene, ObjType.Garden);
- ResourceManager.AddAsyncLoad(ResourceLabel.DressRoom, 1, Folder.UI, ObjType.DressRoom);
- }
- yield return LoadAudio();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad(ResourceLabel.Music, 1, Folder.Audio, ObjType.Music);
- }
- yield return LoadAtlas2();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SkillConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PackConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AbilityConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AchieveConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.VisitConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.AwardConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.FlowerConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.OfflineConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.SigninConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.DressroomConfig, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.English, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseSimplified, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.ChineseTraditional, Folder.Config);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BtnClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.SkillClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.ErrorClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.DropClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CloseClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.FlowerClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.BubbleClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.CurrentClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<AudioClip>(ResourceLabel.MiniEndClip, Folder.Audio);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandTex, Folder.Config);
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.StandSke, Folder.Config);
- ResourceManager.AddAsyncLoad<Texture2D>(ResourceLabel.StandTexture, Folder.Scene);
- }
- yield return LoadAtlas();
- yield return LoadEffect();
- SpriteAsset.AddAllBundleSpriteInfo();
- 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 LoadAtlas2()
- {
- WWW www = new WWW(GetStreamPath() + "atlas2");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Atlas2 = 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);
- }
- }
- public static IEnumerator LoadDiscard()
- {
- WWW www = new WWW(GetStreamPath() + "discard");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Discard = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- }
- public static IEnumerator LoadPlazaRoom()
- {
- WWW www = new WWW(GetStreamPath() + "plazaroom");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- PlazaRoom = www.assetBundle;
- }
- else
- {
- Debug.Log(www.error);
- }
- }
- private static int CopyCount = 0;
- public static void CopyAssetBundles()
- {
- string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
- if (!Directory.Exists(persistentFolderPath))
- {
- Directory.CreateDirectory(persistentFolderPath);
- }
- string streamingFolder;
- if (Application.platform == RuntimePlatform.IPhonePlayer)
- {
- streamingFolder = "IOS";
- }
- else if (Application.platform == RuntimePlatform.Android)
- {
- streamingFolder = "Android";
- }
- else
- {
- streamingFolder = "Windows";
- }
- foreach (var assetBundleName in HotUpdateAssetBundleNames)
- {
- if (!File.Exists(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName))
- {
- CopyCount++;
- Initializer.Instance.StartCoroutine
- (
- LoadAssetBundle
- (
- streamingFolder,
- assetBundleName,
- www =>
- {
- File.WriteAllBytes(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName, www.bytes);
- CopyOneAssetBundleFinish();
- }
- )
- );
- }
- }
- }
- private static void CopyOneAssetBundleFinish()
- {
- CopyCount--;
- }
- public static IEnumerator LoadAssetBundle(string folder, string name, Action<WWW> callback)
- {
- WWW www = new WWW(GetStreamingUrlPath() + Path.DirectorySeparatorChar + "Bundle" + Path.DirectorySeparatorChar + folder + Path.DirectorySeparatorChar + "HotUpdate" + Path.DirectorySeparatorChar + name);
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- callback.Invoke(www);
- }
- else
- {
- Debug.Log(www.error);
- }
- }
- public static int UpdateAmt;
- public static int UpdateFinishAmt;
- public static bool UpdateAssetBundles()
- {
- //Debug.Log(HttpManager.Md5);
- //Debug.Log(HttpManager.Md5Dictionnary);
- //Debug.Log(HttpManager.AssetbundleUrl);
- try
- {
- Initializer.DebugText.text = "U0";
- if (Initializer.Instance.DebugMode)
- {
- SkipUpdateForDebugMode();
- return false;
- }
- Initializer.DebugText.text = "U1";
- string persistentFolderPath = $"{Application.persistentDataPath}{Path.DirectorySeparatorChar}HotUpdate";
- Initializer.DebugText.text = "U2";
- List<AssetBundleSet> assetBundleSets = AssetBundleUtility.GetAssetBundleSetsFromFolders
- (
- persistentFolderPath
- );
- Initializer.DebugText.text = "U3";
- string localMD5 = AssetBundleUtility.GetMD5OfAssetBundleSets(assetBundleSets);
- bool needUpdate;
- if (string.IsNullOrEmpty(HttpManager.Md5) || string.IsNullOrEmpty(HttpManager.Md5Dictionnary) || string.IsNullOrEmpty(HttpManager.AssetbundleUrl))
- {
- needUpdate = false;
- Debug.LogWarning($"NeedUpdate : {needUpdate} connection error");
- }
- else
- {
- Debug.Log(localMD5);
- Debug.Log(HttpManager.Md5);
- needUpdate = localMD5 != HttpManager.Md5;
- Debug.LogWarning($"NeedUpdate : {needUpdate}");
- }
- if (Application.isEditor)
- {
- needUpdate = false;
- }
- if (needUpdate)
- {
- Initializer.DebugText.text = "U4";
- UpdateAmt = AssetBundleUtility.UpdateAllAssetBundle
- (
- HttpManager.Md5Dictionnary,
- persistentFolderPath,
- assetBundleSets,
- DownloadAllAssetBundleSucceed,
- DownloadAllAssetBundleFailed,
- DownloadAssetBundleSucceed,
- DownloadAssetBundleFailed
- );
- UpdatePanel.Show();
- UpdatePanel.SetProgress(UpdateAmt, 0);
- }
- else
- {
- Initializer.DebugText.text = "U5";
- AssetBundleUtility.LoadAllAssetBundle
- (
- assetBundleSets,
- DownloadAllAssetBundleSucceed,
- DownloadAllAssetBundleFailed,
- DownloadAssetBundleSucceed,
- DownloadAssetBundleFailed
- );
- }
- return false;
- }
- catch (Exception)
- {
- Initializer.EnableDebugLab();
- return true;
- }
- }
- public static void DownloadAllAssetBundleSucceed()
- {
- try
- {
- Initializer.DebugText.text = "01";
- NewDressroomConfigs = ConfigManager.GetDressRoomConfig(NewDressConfig.LoadAsset<TextAsset>(ResourceLabel.NewDressroomConfig));
- Initializer.DebugText.text = "02";
- TextAsset[] textAssets = NewDressSke.LoadAllAssets<TextAsset>();
- foreach (var textAsset in textAssets)
- {
- UnityFactory.factory.LoadDragonBonesData(textAsset);
- }
- Initializer.DebugText.text = "03";
- textAssets = NewDressTex.LoadAllAssets<TextAsset>();
- Texture2D[] textures = NewDressTex.LoadAllAssets<Texture2D>();
- for (int i = 0; i < textAssets.Length; i++)
- {
- ResourceManager.ObjectDictionary.Add(textures[i].name, textures[i]);
- UnityFactory.factory.LoadTextureAtlasData(textAssets[i], textures[i].name);
- }
- Initializer.DebugText.text = "04";
- Sprite[] sprites = NewDressTex.LoadAllAssets<Sprite>();
- for (int i = 0; i < sprites.Length; i++)
- {
- PlayerManager.CloseSpriteDictionary.Add(sprites[i].name, sprites[i]);
- ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- }
- Initializer.DebugText.text = "051";
- TextAsset language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.English);
- XmlDocument document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.English, document);
- Initializer.DebugText.text = "061";
- language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.ChineseSimplified);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
- Initializer.DebugText.text = "071";
- language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.ChineseTraditional);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
- Initializer.DebugText.text = "052";
- language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewEnglish);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.English, document);
- Initializer.DebugText.text = "062";
- language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseSimplified);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
- Initializer.DebugText.text = "072";
- language = NewLanguage.LoadAsset<TextAsset>(ResourceLabel.NewChineseTraditional);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
- Initializer.DebugText.text = "08";
- NewFlowerConfigs = ConfigManager.GetFlowerConfig(NewFlowerConfig.LoadAsset<TextAsset>(ResourceLabel.NewFlowerConfig));
- Initializer.DebugText.text = "09";
- sprites = NewFlowerTex.LoadAllAssets<Sprite>();
- for (int i = 0; i < sprites.Length; i++)
- {
- ResourceManager.ObjectDictionary.UniqueAdd(sprites[i].name, sprites[i]);
- }
- UpdateComplete = true;
- DelayCall.Call(1f, UpdatePanel.Hide);
- }
- catch (Exception e)
- {
- Debug.Log(e);
- Initializer.DebugText.text += e.ToString();
- Initializer.EnableDebugLab();
- }
- }
- public static void DownloadAllAssetBundleFailed()
- {
- Debug.Log("failed");
- }
- public static void DownloadAssetBundleSucceed(AssetBundleSet assetBundleSet, bool isDownload)
- {
- if (assetBundleSet.Name == ResourceLabel.NewDressConfig)
- {
- NewDressConfig = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewDressSke)
- {
- NewDressSke = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewDressTex)
- {
- NewDressTex = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewLanguage)
- {
- NewLanguage = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewFlowerConfig)
- {
- NewFlowerConfig = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewFlowerTex)
- {
- NewFlowerTex = assetBundleSet.AssetBundle;
- }
- if (isDownload)
- {
- UpdateFinishAmt++;
- UpdatePanel.SetProgress(UpdateAmt, UpdateFinishAmt);
- }
- }
- public static void DownloadAssetBundleFailed(AssetBundleSet assetBundleSet, string error)
- {
- string str = Language.GetStr(LanguageLabel.UI__AJ_UpdateFailed, Application.systemLanguage) + " " + error;
- UpdatePanel.SetContent(str);
- //Debug.Log(error);
- //Initializer.DebugText.text = assetBundleSet.Name;
- //Initializer.DebugText.text += error;
- //Initializer.EnableDebugLab();
- }
- public static void SkipUpdateForDebugMode()
- {
- NewDressroomConfigs = ConfigManager.GetDressRoomConfig(Instance.NewDressConfigList[0] as TextAsset);
- foreach (var textAsset in Instance.NewDressSkeList)
- {
- UnityFactory.factory.LoadDragonBonesData(textAsset as TextAsset);
- }
- for (int i = 0; i < Instance.NewDressTexList.Count; i++)
- {
- TextAsset textAsset = Instance.NewDressTexConfigList[i] as TextAsset;
- Texture2D texture = Instance.NewDressTexList[i] as Texture2D;
- ResourceManager.ObjectDictionary.Add(texture.name, texture);
- UnityFactory.factory.LoadTextureAtlasData(textAsset, texture.name);
- }
- for (int i = 0; i < Instance.NewDressSpriteList.Count; i++)
- {
- Sprite sprite = Instance.NewDressSpriteList[i] as Sprite;
- PlayerManager.CloseSpriteDictionary.Add(sprite.name, sprite);
- ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
- }
- for (int i = 0; i < Instance.NewLanguageList.Count; i++)
- {
- TextAsset textAsset = Instance.NewLanguageList[i] as TextAsset;
- if (textAsset.name == ResourceLabel.NewEnglish)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.English, document);
- }
- else if (textAsset.name == ResourceLabel.NewChineseSimplified)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
- }
- else if (textAsset.name == ResourceLabel.NewChineseTraditional)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
- }
- else if (textAsset.name == ResourceLabel.English)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.English, document);
- }
- else if (textAsset.name == ResourceLabel.ChineseSimplified)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
- }
- else if (textAsset.name == ResourceLabel.ChineseTraditional)
- {
- XmlDocument document = new XmlDocument();
- document.LoadXml(textAsset.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseTraditional, document);
- }
- }
- NewFlowerConfigs = ConfigManager.GetDressRoomConfig(Instance.NewFlowerConfigList[0] as TextAsset);
- foreach (var obj in Instance.NewFlowerSpriteList)
- {
- Sprite sprite = obj as Sprite;
- ResourceManager.ObjectDictionary.UniqueAdd(sprite.name, sprite);
- }
- UpdateComplete = true;
- }
- }
|