FightingResManager.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. namespace YLBattle
  6. {
  7. /// <summary>
  8. /// 战斗中龙骨资源管理
  9. /// </summary>
  10. public class FightingResManager : MonoSingleton<FightingResManager>
  11. {
  12. /// <summary>
  13. /// 龙骨资源等级
  14. /// [暂时只有引导和战斗用到此管理类加载。。。等级高的,则不可删除]
  15. /// </summary>
  16. public enum EDragonResLevel
  17. {
  18. None = 0,
  19. Monster = 1,
  20. Hero = 2,
  21. Guide = 3
  22. }
  23. /// <summary>
  24. ///模型列表
  25. /// </summary>
  26. private Dictionary<string, EDragonResLevel> existModelList = new Dictionary<string, EDragonResLevel>();
  27. /// <summary>
  28. /// 正在加载的bundle名称
  29. /// </summary>
  30. private string mCurtLoadBundleName = string.Empty;
  31. /// <summary>
  32. /// 获得龙骨物体(未激活Active=false)
  33. /// </summary>
  34. /// <param name="dragonID"></param>
  35. /// <returns></returns>
  36. public void GetDragonBone(string dragonID, EDragonResLevel level, Action ac)
  37. {
  38. if (this.existModelList.ContainsKey(dragonID))
  39. {
  40. ac();
  41. }
  42. else
  43. {
  44. this.LoadDragonBone(dragonID, level, (loadeddragonId) => {
  45. if (this.existModelList.ContainsKey(dragonID) != null)
  46. {
  47. ac();
  48. }
  49. });
  50. }
  51. }
  52. /// <summary>
  53. ///
  54. /// </summary>
  55. /// <param name="dragonID"></param>
  56. public void Clear()
  57. {
  58. this.existModelList.Clear();
  59. }
  60. /// <summary>
  61. ///
  62. /// </summary>
  63. /// <param name="sID"></param>
  64. internal void UnloadDragonBone(string sID)
  65. {
  66. DragonBonesManager.Instance.UnloadDragonBoneBundle(sID);
  67. }
  68. /// <summary>
  69. /// 加载(创建)龙骨~
  70. /// </summary>
  71. /// <param name="dragonID">角色龙骨名字</param>
  72. /// <param name="ac">事件</param>
  73. private void LoadDragonBone(string dragonID, EDragonResLevel level, Action<string> callBack)
  74. {
  75. /**
  76. * 如果UI已经加载,则克隆即可
  77. * 如果波次已经加载,则克隆即可~
  78. * 如果预加载和即时加载撞衫~,取值即可
  79. */
  80. if (this.existModelList.ContainsKey(dragonID))
  81. {
  82. if (this.existModelList[dragonID] < level)
  83. {
  84. this.existModelList[dragonID] = level;
  85. }
  86. if (callBack != null)
  87. {
  88. callBack(dragonID);
  89. }
  90. return;
  91. }
  92. //找找UI有没有加载过
  93. if (DragonBonesBGControler.Instance() != null)
  94. {
  95. bool compIsExist = DragonBonesBGControler.Instance().CheckFactoryIsExistSomeModelData(dragonID);
  96. if (compIsExist)
  97. {
  98. //更新一次 对龙骨数据的引用
  99. DragonBonesBGControler.Instance().AddDragonBoneDataUse(dragonID);
  100. if (existModelList.ContainsKey(dragonID) == false)
  101. {
  102. existModelList.Add(dragonID, level);
  103. }
  104. if (callBack != null)
  105. {
  106. callBack(dragonID);
  107. }
  108. return;
  109. }
  110. }
  111. ///没招了,自己来吧~
  112. #region 加载方式二:独立factory 只是去加载龙骨的数据
  113. DragonBonesManager.Instance.QueryAsset(dragonID, (model, textureAtlas) =>
  114. {
  115. if (model == null || textureAtlas == null)
  116. {
  117. if (callBack != null)
  118. {
  119. callBack(null);
  120. }
  121. }
  122. DragonBones.UnityFactory.factory.ParseDragonBonesData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mSkeletonJson.text), dragonID, 0.01f);
  123. DragonBones.UnityFactory.factory.ParseTextureAtlasData((Dictionary<string, object>)MiniJSON.Json.Deserialize(model.mTextureJson.text), textureAtlas, dragonID);
  124. if (existModelList.ContainsKey(dragonID) == false)
  125. {
  126. existModelList.Add(dragonID, level);
  127. }
  128. if (callBack != null)
  129. {
  130. callBack(dragonID);
  131. }
  132. });
  133. #endregion
  134. }
  135. /// <summary>
  136. /// 预加载龙骨动画
  137. /// </summary>
  138. /// <param name="preModelList"></param>
  139. /// <param name="ac"></param>
  140. public void PreLoadDragonBones(List<string> preModels, EDragonResLevel level, Action p = null)
  141. {
  142. progress = p;
  143. preLoads = preModels;
  144. LoadDragon(0);
  145. }
  146. /// <summary>
  147. /// 预加载橘色
  148. /// </summary>
  149. List<string> preLoads = new List<string>();
  150. Action progress = null;
  151. void LoadDragon(int index)
  152. {
  153. //UI_LoadingWindow.Instance().SetProgress(((int)(index * 1.0f / preLoads.Count * 100)), "加载角色");
  154. LoadDragonBone(preLoads[index], EDragonResLevel.Monster, (s) =>
  155. {
  156. index++;
  157. if (index <= preLoads.Count - 1)
  158. {
  159. LoadDragon(index);
  160. }
  161. else
  162. {
  163. UI_LoadingWindow.Instance().SetProgress(100);
  164. if (progress != null)
  165. {
  166. progress();
  167. }
  168. }
  169. });
  170. }
  171. }
  172. }