1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030 |
- 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()
- {
- 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);
- string serverMD5 = "AE29F7EE00843A792D96CA02D6907FAA";
- bool needUpdate = localMD5 != serverMD5;
- //if (Application.isEditor)
- //{
- // needUpdate = false;
- //}
- //needUpdate = false;
- //Debug.LogWarning($"NeedUpdate : {needUpdate}");
- if (needUpdate)
- {
- Initializer.DebugText.text = "U4";
- UpdateAmt = AssetBundleUtility.UpdateAllAssetBundle
- (
- "new_dress_config|F5D72F9FDCFBB75E83A751FB180B9D4C|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_dress_config\r\nnew_dress_ske|531AE05FA301BBAD7B58B532BCD04CFD|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_dress_ske\r\nnew_dress_tex|3060DC78E5C9A8D58CF440C6C66035C4|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_dress_tex\r\nnew_flower_config|E1B8FB25188BAB5257427245A9FAED72|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_flower_config\r\nnew_flower_tex|3AE116480991657BBC2CCB7651D39948|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_flower_tex\r\nnew_language_config|86E969CA359D6514822E3A514C2C9F97|file://D:\\UnityProject\\Garden5\\Assets\\HotUpdate\\Windows\\new_language_config",
- 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)
- {
- 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;
- }
- }
|