using UnityEngine; using System.Collections; using System.Collections.Generic; using System; namespace YLBattle { /// /// 战斗中龙骨资源管理 /// public class FightingResManager : MonoSingleton { /// /// 龙骨资源等级 /// [暂时只有引导和战斗用到此管理类加载。。。等级高的,则不可删除] /// public enum EDragonResLevel { None = 0, Monster = 1, Hero = 2, Guide = 3 } /// ///模型列表 /// private Dictionary existModelList = new Dictionary(); /// /// 正在加载的bundle名称 /// private string mCurtLoadBundleName = string.Empty; /// /// 获得龙骨物体(未激活Active=false) /// /// /// public void GetDragonBone(string dragonID, EDragonResLevel level, Action ac) { if (this.existModelList.ContainsKey(dragonID)) { ac(); } else { this.LoadDragonBone(dragonID, level, (loadeddragonId) => { if (this.existModelList.ContainsKey(dragonID) != null) { ac(); } }); } } /// /// /// /// public void Clear() { this.existModelList.Clear(); } /// /// /// /// internal void UnloadDragonBone(string sID) { DragonBonesManager.Instance.UnloadDragonBoneBundle(sID); } /// /// 加载(创建)龙骨~ /// /// 角色龙骨名字 /// 事件 private void LoadDragonBone(string dragonID, EDragonResLevel level, Action callBack) { /** * 如果UI已经加载,则克隆即可 * 如果波次已经加载,则克隆即可~ * 如果预加载和即时加载撞衫~,取值即可 */ if (this.existModelList.ContainsKey(dragonID)) { if (this.existModelList[dragonID] < level) { this.existModelList[dragonID] = level; } if (callBack != null) { callBack(dragonID); } return; } //找找UI有没有加载过 if (DragonBonesBGControler.Instance() != null) { bool compIsExist = DragonBonesBGControler.Instance().CheckFactoryIsExistSomeModelData(dragonID); if (compIsExist) { //更新一次 对龙骨数据的引用 DragonBonesBGControler.Instance().AddDragonBoneDataUse(dragonID); if (existModelList.ContainsKey(dragonID) == false) { existModelList.Add(dragonID, level); } if (callBack != null) { callBack(dragonID); } return; } } ///没招了,自己来吧~ #region 加载方式二:独立factory 只是去加载龙骨的数据 DragonBonesManager.Instance.QueryAsset(dragonID, (model, textureAtlas) => { if (model == null || textureAtlas == null) { if (callBack != null) { callBack(null); } } DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), dragonID, 0.01f); DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, dragonID); if (existModelList.ContainsKey(dragonID) == false) { existModelList.Add(dragonID, level); } if (callBack != null) { callBack(dragonID); } }); #endregion } /// /// 预加载龙骨动画 /// /// /// public void PreLoadDragonBones(List preModels, EDragonResLevel level, Action p = null) { progress = p; preLoads = preModels; LoadDragon(0); } /// /// 预加载橘色 /// List preLoads = new List(); Action progress = null; void LoadDragon(int index) { //UI_LoadingWindow.Instance().SetProgress(((int)(index * 1.0f / preLoads.Count * 100)), "加载角色"); LoadDragonBone(preLoads[index], EDragonResLevel.Monster, (s) => { index++; if (index <= preLoads.Count - 1) { LoadDragon(index); } else { UI_LoadingWindow.Instance().SetProgress(100); if (progress != null) { progress(); } } }); } } }