HeroUITools.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. /// 该方法调用后,可以把装备了的职业装备, 显示到指定的UI(eqsUIObj)上
  57. /// </summary>
  58. /// <param name="zy">职业类型</param>
  59. /// <param name="eqsUIObj">装备的icon</param>
  60. public static async void UpdateZyEqIcon(int zy, List<object> eqsUIObj, string poolName = "eq", float size = 1, Action action = null)
  61. {
  62. List<ItemInfo> eqList = PlayerManager.Instance.eqController.equipZyEqDic[zy];
  63. for (int i=0; i < 5; i++)
  64. {
  65. bool empty = true;
  66. ItemInfo eqInfo = null;
  67. foreach (ItemInfo itemInfo in eqList)
  68. {
  69. if (itemInfo.eqInfo.basicEquipConfig.Type == i + 1)
  70. {
  71. empty = false;
  72. eqInfo = itemInfo;
  73. break;
  74. }
  75. }
  76. GameObject eqGo = eqsUIObj[0] as GameObject;
  77. WidgetItem eqItem = await UIManager.Instance.
  78. CreateGComponentForObject<WidgetItem>(eqGo, null, isInstance:true, poolName:poolName, root:eqGo.transform.parent.GetComponent<RectTransform>());
  79. eqItem.transform.localScale = new Vector3(size, size, size);
  80. if (empty)
  81. {
  82. // LogTool.Log(zy + "---" + i + "空");
  83. eqItem.SetEmpty(action);
  84. }
  85. else
  86. {
  87. eqItem.InitWidget(eqInfo, action);
  88. }
  89. eqItem.numObj.SetActive(false);
  90. }
  91. }
  92. public static string GetEquipmentIconName(ItemInfo eqItem)
  93. {
  94. int q = 1;
  95. if (eqItem.eqInfo.quality > 3 && eqItem.eqInfo.quality <= 4)
  96. {
  97. q = 2;
  98. }
  99. else if (eqItem.eqInfo.quality > 4)
  100. {
  101. q = 3;
  102. }
  103. string eqIcon = "icon_eq_" +
  104. eqItem.eqInfo.basicEquipConfig.profession + "_" +
  105. eqItem.eqInfo.basicEquipConfig.Type + "_" +
  106. q;
  107. // switch (eqItem.eqInfo.basicEquipConfig.profession)
  108. return eqIcon;
  109. }
  110. /// <summary>
  111. /// 根据星级,显示不同的数量的星星和样子
  112. /// </summary>
  113. /// <param name="stars"></param>
  114. /// <param name="starGrade"></param>
  115. public static void SetStarShow(List<object> stars, int starGrade)
  116. {
  117. // 最大星级展示个数(6星,只显示一颗星星,换颜色)
  118. int maxShowStar = 5;
  119. // 计算 当前星级 应该用什么星星的表现
  120. int group = (starGrade - 1) / maxShowStar;
  121. int i = 1;
  122. int showCount = (starGrade - 1) % maxShowStar + 1;
  123. foreach (GameObject star in stars)
  124. {
  125. SetStarImg(group, star);
  126. // 根据星级显示星星
  127. if (showCount >= i)
  128. {
  129. star.SetActive(true);
  130. }
  131. else
  132. {
  133. star.SetActive(false);
  134. }
  135. i++;
  136. }
  137. SimpleLayout.Layout(stars, LayoutType.Horizontal);
  138. }
  139. private static void SetStarImg(int group, GameObject starObj)
  140. {
  141. MyImage image = starObj.GetComponent<MyImage>();
  142. // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
  143. switch (group)
  144. {
  145. case 0: // n = 1~5
  146. image.icon_name = "dec_star";
  147. break;
  148. case 1: // n = 6~10
  149. image.icon_name = "dec_star_2";
  150. break;
  151. default: // 其他情况
  152. LogTool.Error("超出设计表现");
  153. //image.icon_name = "dec_star";
  154. break;
  155. }
  156. }
  157. public static bool IsLvUpShowGuild(HeroInfo heroInfo)
  158. {
  159. long totalExp = heroInfo.powerUpConfig.levelUpExp;
  160. for (int i = 1; i < 10; i++)
  161. {
  162. HeroPowerUpConfig powerUpConfig =
  163. ConfigComponent.Instance.Get<HeroPowerUpConfig>(heroInfo.promoteConfig.ID + i);
  164. totalExp += powerUpConfig.levelUpExp;
  165. }
  166. if (BagController.Instance.IsEnough(GlobalParam.Item_HeroExp_ID, totalExp) &&
  167. heroInfo.level.Value - PlayerManager.Instance.heroController.mainLevel < 10)
  168. {
  169. return true;
  170. }
  171. return false;
  172. }
  173. /// <summary>
  174. /// 打开对应职业的装备面板
  175. /// </summary>
  176. /// <param name="zy">1战士;2法师;3牧师;4游侠</param>
  177. public static async void OpenSpecificProfessionEquipmentPanel(int zy, Action action = null)
  178. {
  179. SpecificProfessionEquipmentPanel specificProfessionEquipmentPanel
  180. = await UIManager.Instance.LoadAndOpenPanel<SpecificProfessionEquipmentPanel>(null);
  181. specificProfessionEquipmentPanel.InitPanel(zy, action);
  182. }
  183. /// <summary>
  184. /// 修改指定 GameObject 和其所有子对象的 Layer
  185. /// </summary>
  186. /// <param name="obj">目标 GameObject</param>
  187. /// <param name="newLayer">新的 Layer 值</param>
  188. public static void ChangeLayerRecursively(GameObject obj, int newLayer)
  189. {
  190. if (obj == null || obj.layer == newLayer) return;
  191. // 修改当前对象的 Layer
  192. obj.layer = newLayer;
  193. // 遍历所有子对象,递归修改
  194. foreach (Transform child in obj.transform)
  195. {
  196. ChangeLayerRecursively(child.gameObject, newLayer);
  197. }
  198. }
  199. public static string GetZyIcon(int zy)
  200. {
  201. string iconZhiYe = "";
  202. switch (zy)
  203. {
  204. case 1 :
  205. iconZhiYe = "icon_zy_Shield";
  206. break;
  207. case 2 :
  208. iconZhiYe = "icon_zy_Hat";
  209. break;
  210. case 3 :
  211. iconZhiYe = "icon_zy_Potion";
  212. break;
  213. case 4 :
  214. iconZhiYe = "icon_zy_Bow";
  215. break;
  216. }
  217. return iconZhiYe;
  218. }
  219. }
  220. }