HeroUITools.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System.Collections.Generic;
  2. using Excel2Json;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using GameLogic.Bag;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. namespace Fort23.Mono
  9. {
  10. public static class HeroUITools
  11. {
  12. public static WidgetHero GetCloseHero(List<WidgetHero> widgetHeroes, WidgetHero widgetHero, bool isNext)
  13. {
  14. int idx = widgetHeroes.IndexOf(widgetHero);
  15. if (isNext && idx < widgetHeroes.Count - 1)
  16. {
  17. return widgetHeroes[idx + 1];
  18. }
  19. if (!isNext && idx > 0)
  20. {
  21. return widgetHeroes[idx - 1];
  22. }
  23. return null;
  24. }
  25. /// <summary>
  26. /// 获取技能参数
  27. /// </summary>
  28. /// <param name="skillConfig"></param>
  29. /// <returns></returns>
  30. public static object[] GetSkillParam(SkillConfig skillConfig)
  31. {
  32. object[] data = null;
  33. if (skillConfig.SkillType == 5)
  34. {
  35. data = new object[skillConfig.addPropertyValue.Length];
  36. for (int j = 0; j < skillConfig.addPropertyValue.Length; j++)
  37. {
  38. data[j] = skillConfig.addPropertyValue[j];
  39. }
  40. }
  41. else
  42. {
  43. data = new object[skillConfig.effectValue.Length];
  44. for (int j = 0; j < skillConfig.effectValue.Length; j++)
  45. {
  46. data[j] = skillConfig.effectValue[j];
  47. }
  48. }
  49. return data;
  50. }
  51. /// <summary>
  52. /// 更新对应职业的装备图标
  53. /// 该方法调用后,可以把装备了的职业装备, 显示到指定的UI(eqsUIObj)上
  54. /// </summary>
  55. /// <param name="zy">职业类型</param>
  56. /// <param name="eqsUIObj">装备的icon</param>
  57. public static async void UpdateZyEqIcon(int zy, List<object> eqsUIObj, int space = 12)
  58. {
  59. foreach (GameObject eqGo in eqsUIObj)
  60. {
  61. WidgetItem eqItem = await UIManager.Instance.
  62. CreateGComponentForObject<WidgetItem>(eqGo,
  63. null, root:eqGo.transform.parent.GetComponent<RectTransform>());
  64. // LogTool.Log(eqGo + "设置");
  65. eqItem.SetEmpty();
  66. }
  67. if (PlayerManager.Instance.eqController.zyEqDic.TryGetValue(zy, out Dictionary<int ,List<ItemInfo>> bwDic))
  68. {
  69. foreach (KeyValuePair<int,List<ItemInfo>> keyValuePair in bwDic)
  70. {
  71. //遍历每个部位下的全部装备
  72. foreach (ItemInfo eqInfo in keyValuePair.Value)
  73. {
  74. if (eqInfo.eqInfo.isEquip)
  75. {
  76. //这里是取部位,eqsUIObj里面的部位,是有序排列的
  77. GameObject eqGo = eqsUIObj[keyValuePair.Key - 1] as GameObject;
  78. WidgetItem eqItem = await UIManager.Instance.
  79. CreateGComponentForObject<WidgetItem>(eqGo, null, root:eqGo.transform.parent.GetComponent<RectTransform>());
  80. eqItem.InitWidget(eqInfo);
  81. }
  82. }
  83. }
  84. }
  85. SimpleLayout.Layout(eqsUIObj, LayoutType.Horizontal, space);
  86. }
  87. public static string GetEquipmentIconName(ItemInfo eqItem)
  88. {
  89. int q = 1;
  90. if (eqItem.eqInfo.quality > 3 && eqItem.eqInfo.quality <= 4)
  91. {
  92. q = 2;
  93. }
  94. else if (eqItem.eqInfo.quality > 4)
  95. {
  96. q = 3;
  97. }
  98. string eqIcon = "icon_eq_" +
  99. eqItem.eqInfo.basicEquipConfig.profession + "_" +
  100. eqItem.eqInfo.basicEquipConfig.Type + "_" +
  101. q;
  102. // switch (eqItem.eqInfo.basicEquipConfig.profession)
  103. return eqIcon;
  104. }
  105. /// <summary>
  106. /// 根据星级,显示不同的数量的星星和样子
  107. /// </summary>
  108. /// <param name="stars"></param>
  109. /// <param name="starGrade"></param>
  110. public static void SetStarShow(List<object> stars, int starGrade)
  111. {
  112. // 最大星级展示个数(6星,只显示一颗星星,换颜色)
  113. int maxShowStar = 5;
  114. // 计算 当前星级 应该用什么星星的表现
  115. int group = (starGrade - 1) / maxShowStar;
  116. int i = 1;
  117. int showCount = (starGrade - 1) % maxShowStar + 1;
  118. foreach (GameObject star in stars)
  119. {
  120. SetStarImg(group, star);
  121. // 根据星级显示星星
  122. if (showCount >= i)
  123. {
  124. star.SetActive(true);
  125. }
  126. else
  127. {
  128. star.SetActive(false);
  129. }
  130. i++;
  131. }
  132. SimpleLayout.Layout(stars, LayoutType.Horizontal);
  133. }
  134. private static void SetStarImg(int group, GameObject starObj)
  135. {
  136. MyImage image = starObj.GetComponent<MyImage>();
  137. // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
  138. switch (group)
  139. {
  140. case 0: // n = 1~5
  141. image.icon_name = "dec_star";
  142. break;
  143. case 1: // n = 6~10
  144. image.icon_name = "dec_star_2";
  145. break;
  146. default: // 其他情况
  147. LogTool.Error("超出设计表现");
  148. //image.icon_name = "dec_star";
  149. break;
  150. }
  151. }
  152. /// <summary>
  153. /// 修改指定 GameObject 和其所有子对象的 Layer
  154. /// </summary>
  155. /// <param name="obj">目标 GameObject</param>
  156. /// <param name="newLayer">新的 Layer 值</param>
  157. public static void ChangeLayerRecursively(GameObject obj, int newLayer)
  158. {
  159. if (obj == null || obj.layer == newLayer) return;
  160. // 修改当前对象的 Layer
  161. obj.layer = newLayer;
  162. // 遍历所有子对象,递归修改
  163. foreach (Transform child in obj.transform)
  164. {
  165. ChangeLayerRecursively(child.gameObject, newLayer);
  166. }
  167. }
  168. }
  169. }