123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- namespace YLBattle
- {
- /// <summary>
- /// 战斗中龙骨资源管理
- /// </summary>
- public class FightingResManager : MonoSingleton<FightingResManager>
- {
- /// <summary>
- /// 龙骨资源等级
- /// [暂时只有引导和战斗用到此管理类加载。。。等级高的,则不可删除]
- /// </summary>
- public enum EDragonResLevel
- {
- None = 0,
- Monster = 1,
- Hero = 2,
- Guide = 3
- }
- /// <summary>
- ///模型列表
- /// </summary>
- private Dictionary<string, EDragonResLevel> existModelList = new Dictionary<string, EDragonResLevel>();
- /// <summary>
- /// 正在加载的bundle名称
- /// </summary>
- private string mCurtLoadBundleName = string.Empty;
- /// <summary>
- /// 获得龙骨物体(未激活Active=false)
- /// </summary>
- /// <param name="dragonID"></param>
- /// <returns></returns>
- 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();
- }
- });
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="dragonID"></param>
- public void Clear()
- {
- this.existModelList.Clear();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="sID"></param>
- internal void UnloadDragonBone(string sID)
- {
- DragonBonesManager.Instance.UnloadDragonBoneBundle(sID);
- }
- /// <summary>
- /// 加载(创建)龙骨~
- /// </summary>
- /// <param name="dragonID">角色龙骨名字</param>
- /// <param name="ac">事件</param>
- private void LoadDragonBone(string dragonID, EDragonResLevel level, Action<string> 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<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), dragonID, 0.01f);
- DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, dragonID);
- if (existModelList.ContainsKey(dragonID) == false)
- {
- existModelList.Add(dragonID, level);
- }
- if (callBack != null)
- {
- callBack(dragonID);
- }
- });
- #endregion
- }
- /// <summary>
- /// 预加载龙骨动画
- /// </summary>
- /// <param name="preModelList"></param>
- /// <param name="ac"></param>
- public void PreLoadDragonBones(List<string> preModels, EDragonResLevel level, Action p = null)
- {
- progress = p;
- preLoads = preModels;
- LoadDragon(0);
- }
- /// <summary>
- /// 预加载橘色
- /// </summary>
- List<string> preLoads = new List<string>();
- 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();
- }
- }
- });
- }
- }
- }
|