HeroUITools.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. using System;
  2. using System.Collections.Generic;
  3. using Core.Utility;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using GameLogic.Bag;
  8. using GameLogic.Hero;
  9. using UnityEngine;
  10. using UnityEngine.UI;
  11. namespace Fort23.Mono
  12. {
  13. public static class HeroUITools
  14. {
  15. public static WidgetHero GetCloseHero(List<WidgetHero> widgetHeroes, WidgetHero widgetHero, bool isNext)
  16. {
  17. int idx = widgetHeroes.IndexOf(widgetHero);
  18. if (isNext && idx < widgetHeroes.Count - 1)
  19. {
  20. return widgetHeroes[idx + 1];
  21. }
  22. if (!isNext && idx > 0)
  23. {
  24. return widgetHeroes[idx - 1];
  25. }
  26. return null;
  27. }
  28. /// <summary>
  29. /// 获取技能参数
  30. /// </summary>
  31. /// <param name="skillConfig"></param>
  32. /// <returns></returns>
  33. public static object[] GetSkillParam(SkillConfig skillConfig)
  34. {
  35. object[] data = null;
  36. if (skillConfig.SkillType == 5)
  37. {
  38. data = new object[skillConfig.addPropertyValue.Length];
  39. for (int j = 0; j < skillConfig.addPropertyValue.Length; j++)
  40. {
  41. data[j] = skillConfig.addPropertyValue[j];
  42. }
  43. }
  44. else
  45. {
  46. data = new object[skillConfig.effectValue.Length];
  47. for (int j = 0; j < skillConfig.effectValue.Length; j++)
  48. {
  49. data[j] = skillConfig.effectValue[j];
  50. }
  51. }
  52. return data;
  53. }
  54. /// <summary>
  55. /// 是否显示职业装备的小红点
  56. /// </summary>
  57. /// <param name="zy"></param>
  58. /// <returns></returns>
  59. public static bool IsShowRedPointProEq(int zy)
  60. {
  61. if (PlayerManager.Instance.eqController.allBestEqDic != null)
  62. {
  63. if (PlayerManager.Instance.eqController.allBestEqDic.TryGetValue(zy, out var bestEq))
  64. {
  65. if (bestEq.Count > 0)
  66. {
  67. return true;
  68. }
  69. }
  70. }
  71. return false;
  72. }
  73. /// <summary>
  74. /// 更新对应职业的装备图标
  75. /// 该方法调用后,可以把装备了的职业装备, 显示到指定的UI(eqsUIObj)上
  76. /// </summary>
  77. /// <param name="zy">职业类型</param>
  78. /// <param name="eqsUIObj">装备的icon</param>
  79. public static async void UpdateZyEqIcon(int zy, List<object> eqsUIObj, string poolName = "eq", float size = 1, Action action = null)
  80. {
  81. List<ItemInfo> eqList = PlayerManager.Instance.eqController.equipZyEqDic[zy];
  82. for (int i=0; i < 5; i++)
  83. {
  84. bool empty = true;
  85. ItemInfo eqInfo = null;
  86. foreach (ItemInfo itemInfo in eqList)
  87. {
  88. if (itemInfo.eqInfo.basicEquipConfig.Type == i + 1)
  89. {
  90. empty = false;
  91. eqInfo = itemInfo;
  92. break;
  93. }
  94. }
  95. GameObject eqGo = eqsUIObj[0] as GameObject;
  96. WidgetItem eqItem = await UIManager.Instance.
  97. CreateGComponentForObject<WidgetItem>(eqGo, null, isInstance:true, poolName:poolName, root:eqGo.transform.parent.GetComponent<RectTransform>());
  98. eqItem.transform.localScale = new Vector3(size, size, size);
  99. if (empty)
  100. {
  101. // LogTool.Log(zy + "---" + i + "空");
  102. eqItem.SetEmpty(action);
  103. }
  104. else
  105. {
  106. eqItem.InitWidget(eqInfo, action);
  107. }
  108. eqItem.numObj.SetActive(false);
  109. }
  110. }
  111. public static string GetEquipmentIconName(ItemInfo eqItem)
  112. {
  113. int q = 1;
  114. if (eqItem.eqInfo.quality > 3 && eqItem.eqInfo.quality <= 4)
  115. {
  116. q = 2;
  117. }
  118. else if (eqItem.eqInfo.quality > 4)
  119. {
  120. q = 3;
  121. }
  122. string eqIcon = "icon_eq_" +
  123. eqItem.eqInfo.basicEquipConfig.profession + "_" +
  124. eqItem.eqInfo.basicEquipConfig.Type + "_" +
  125. q;
  126. // switch (eqItem.eqInfo.basicEquipConfig.profession)
  127. return eqIcon;
  128. }
  129. /// <summary>
  130. /// 根据星级,显示不同的数量的星星和样子
  131. /// </summary>
  132. /// <param name="stars"></param>
  133. /// <param name="starGrade"></param>
  134. public static void SetStarShow(List<object> stars, int starGrade)
  135. {
  136. // 最大星级展示个数(6星,只显示一颗星星,换颜色)
  137. int maxShowStar = 5;
  138. // 计算 当前星级 应该用什么星星的表现
  139. int group = (starGrade - 1) / maxShowStar;
  140. int i = 1;
  141. int showCount = (starGrade - 1) % maxShowStar + 1;
  142. foreach (GameObject star in stars)
  143. {
  144. SetStarImg(group, star);
  145. // 根据星级显示星星
  146. if (showCount >= i)
  147. {
  148. star.SetActive(true);
  149. }
  150. else
  151. {
  152. star.SetActive(false);
  153. }
  154. i++;
  155. }
  156. SimpleLayout.Layout(stars, LayoutType.Horizontal);
  157. }
  158. private static void SetStarImg(int group, GameObject starObj)
  159. {
  160. MyImage image = starObj.GetComponent<MyImage>();
  161. // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
  162. switch (group)
  163. {
  164. case 0: // n = 1~5
  165. image.icon_name = "dec_star";
  166. break;
  167. case 1: // n = 6~10
  168. image.icon_name = "dec_star_2";
  169. break;
  170. default: // 其他情况
  171. LogTool.Error("超出设计表现");
  172. //image.icon_name = "dec_star";
  173. break;
  174. }
  175. }
  176. /// <summary>
  177. /// 是否展示"去升级"的引导
  178. /// </summary>
  179. /// <param name="heroInfo"></param>
  180. /// <returns></returns>
  181. public static bool IsLvUpShowGuild(HeroInfo heroInfo)
  182. {
  183. long totalExp = heroInfo.powerUpConfig.levelUpExp;
  184. for (int i = 1; i < 10; i++)
  185. {
  186. HeroPowerUpConfig powerUpConfig =
  187. ConfigComponent.Instance.Get<HeroPowerUpConfig>(heroInfo.promoteConfig.ID + i);
  188. totalExp += powerUpConfig.levelUpExp;
  189. }
  190. if (BagController.Instance.IsEnough(GlobalParam.Item_HeroExp_ID, totalExp) &&
  191. heroInfo.level.Value - PlayerManager.Instance.heroController.mainLevel < 10)
  192. {
  193. return true;
  194. }
  195. return false;
  196. }
  197. /// <summary>
  198. /// 打开对应职业的装备面板
  199. /// </summary>
  200. /// <param name="zy">1战士;2法师;3牧师;4游侠</param>
  201. public static async void OpenSpecificProfessionEquipmentPanel(int zy, Action action = null)
  202. {
  203. SpecificProfessionEquipmentPanel specificProfessionEquipmentPanel
  204. = await UIManager.Instance.LoadAndOpenPanel<SpecificProfessionEquipmentPanel>(null);
  205. specificProfessionEquipmentPanel.InitPanel(zy, action);
  206. }
  207. /// <summary>
  208. /// 修改指定 GameObject 和其所有子对象的 Layer
  209. /// </summary>
  210. /// <param name="obj">目标 GameObject</param>
  211. /// <param name="newLayer">新的 Layer 值</param>
  212. public static void ChangeLayerRecursively(GameObject obj, int newLayer)
  213. {
  214. if (obj == null || obj.layer == newLayer) return;
  215. // 修改当前对象的 Layer
  216. obj.layer = newLayer;
  217. // 遍历所有子对象,递归修改
  218. foreach (Transform child in obj.transform)
  219. {
  220. ChangeLayerRecursively(child.gameObject, newLayer);
  221. }
  222. }
  223. public static string GetZyIcon(int zy)
  224. {
  225. string iconZhiYe = "";
  226. switch (zy)
  227. {
  228. case 1 :
  229. iconZhiYe = "icon_zy_Shield";
  230. break;
  231. case 2 :
  232. iconZhiYe = "icon_zy_Hat";
  233. break;
  234. case 3 :
  235. iconZhiYe = "icon_zy_Potion";
  236. break;
  237. case 4 :
  238. iconZhiYe = "icon_zy_Bow";
  239. break;
  240. }
  241. return iconZhiYe;
  242. }
  243. }
  244. }