12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112 |
- 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.Config,
- //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 Defaul;
- 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> DefaultList;
- 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];
- }
- }
- }
- if (folder == Folder.Default)
- {
- for (int i = 0; i < Instance.DefaultList.Count; i++)
- {
- if (Instance.DefaultList[i].name == goName)
- {
- return (T)Instance.DefaultList[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.Default)
- {
- return Defaul.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
- List<Object> objects = new List<Object>();
- string assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture_0", Folder.Scene));
- objects.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath));
- assetPath = AssetDatabase.GetAssetPath(ResourceManager.Load<Texture2D>("stand_texture_1", Folder.Scene));
- objects.AddRange(AssetDatabase.LoadAllAssetsAtPath(assetPath));
- for (int i = 0; i < objects.Count; 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]);
- }
- List<Object> objects = new List<Object>();
- objects.AddRange(Scene.LoadAssetWithSubAssets("stand_texture_0", typeof(Sprite)));
- objects.AddRange(Scene.LoadAssetWithSubAssets("stand_texture_1", typeof(Sprite)));
- for (int i = 0; i < objects.Count; 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.Default)
- {
- return Defaul.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 GetPersistingPath()
- {
- if (Application.platform == RuntimePlatform.IPhonePlayer)
- return "file://" + Application.persistentDataPath;
- else if (Application.isMobilePlatform)
- return Application.streamingAssetsPath;
- else
- return "file://" + Application.persistentDataPath;
- }
- 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 LoadDefaul();
- if (!Logo.Complete && !Initializer.Instance.DebugMode)
- {
- ResourceManager.AddAsyncLoad<TextAsset>(ResourceLabel.PlayerConfig, Folder.Default, () =>
- {
- 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 LoadDefaul()
- {
- WWW www = new WWW(GetStreamPath() + "default");
- yield return www;
- if (string.IsNullOrEmpty(www.error))
- {
- Defaul = 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
- (
- LoadAssetBundleFromStream
- (
- streamingFolder,
- assetBundleName,
- www =>
- {
- File.WriteAllBytes(persistentFolderPath + Path.DirectorySeparatorChar + assetBundleName, www.bytes);
- CopyOneAssetBundleFinish();
- }
- )
- );
- }
- }
- }
- private static void CopyOneAssetBundleFinish()
- {
- CopyCount--;
- }
- public static IEnumerator LoadAssetBundleFromStream(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);
- Initializer.DebugText.text = www.error;
- Initializer.DebugText.SetActive(true);
- Initializer.DebugText.enabled = true;
- }
- }
- 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 || Application.isMobilePlatform)
- {
- needUpdate = false;
- }
- AssetBundleUtility.OnDownloadOrUpdateFinish += FinishDownloadAndLoad;
- 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;
- }
- }
- private static void FinishDownloadAndLoad()
- {
- 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 = Config.LoadAsset<TextAsset>(ResourceLabel.English);
- XmlDocument document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.English, document);
- Initializer.DebugText.text = "061";
- language = Config.LoadAsset<TextAsset>(ResourceLabel.ChineseSimplified);
- document = new XmlDocument();
- document.LoadXml(language.text);
- Language.AddLanguageDocument(CurrentLanguage.ChineseSimplified, document);
- Initializer.DebugText.text = "071";
- language = Config.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 DownloadAllAssetBundleSucceed()
- {
- //Debug.Log("succeed");
- }
- public static void DownloadAllAssetBundleFailed()
- {
- Debug.Log("failed");
- }
- public static void DownloadAssetBundleSucceed(AssetBundleSet assetBundleSet, bool isDownload)
- {
- //Debug.Log(assetBundleSet.AssetBundle.name);
- //if (assetBundleSet.Name == ResourceLabel.NewDressConfig)
- //{
- // NewDressConfig = assetBundleSet.AssetBundle;
- //}
- if (assetBundleSet.Name == ResourceLabel.NewDressSke)
- {
- NewDressSke = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.NewDressTex)
- {
- NewDressTex = assetBundleSet.AssetBundle;
- }
- else if (assetBundleSet.Name == ResourceLabel.Config)
- {
- Config = 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)
- {
- Debug.Log(error);
- string path = assetBundleSet.PersistentPath;
- path = path.Replace("/", Path.DirectorySeparatorChar.ToString());
- path = path.Replace("\\", Path.DirectorySeparatorChar.ToString());
- path = path.Replace("\\\\", Path.DirectorySeparatorChar.ToString());
- path = "file://" + path;
- WWW www = new WWW(path);
- AssetBundleSet bundleSet = new AssetBundleSet();
- bundleSet.Name = assetBundleSet.Name;
- bundleSet.AssetBundle = www.assetBundle;
- DownloadAssetBundleSucceed(bundleSet, false);
- //string str = Language.GetStr(LanguageLabel.UI__AJ_UpdateFailed, Application.systemLanguage) + " " + error;
- //UpdatePanel.SetContent(str);
- //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.ConfigList.Count; i++)
- {
- TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
- 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);
- }
- }
- for (int i = 0; i < Instance.DefaultList.Count; i++)
- {
- TextAsset textAsset = Instance.ConfigList[i] as TextAsset;
- 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;
- }
- }
|