HeroUITools.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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, string poolName = "eq", float size = 1)
  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. List<ItemInfo> eqList = PlayerManager.Instance.eqController.equipZyEqDic[zy];
  68. // foreach (KeyValuePair<int, List<ItemInfo>> kv in PlayerManager.Instance.eqController.equipZyEqDic)
  69. // {
  70. for (int i=0; i < 5; i++)
  71. {
  72. bool empty = true;
  73. ItemInfo eqInfo = null;
  74. foreach (ItemInfo itemInfo in eqList)
  75. {
  76. if (itemInfo.eqInfo.basicEquipConfig.Type == i + 1)
  77. {
  78. empty = false;
  79. eqInfo = itemInfo;
  80. break;
  81. }
  82. }
  83. GameObject eqGo = eqsUIObj[0] as GameObject;
  84. WidgetItem eqItem = await UIManager.Instance.
  85. CreateGComponentForObject<WidgetItem>(eqGo, null, isInstance:true, poolName:poolName, root:eqGo.transform.parent.GetComponent<RectTransform>());
  86. eqItem.transform.localScale = new Vector3(size, size, size);
  87. if (empty)
  88. {
  89. LogTool.Log(zy + "---" + i + "空");
  90. eqItem.SetEmpty();
  91. }
  92. else
  93. {
  94. eqItem.InitWidget(eqInfo);
  95. }
  96. }
  97. // }
  98. // if (PlayerManager.Instance.eqController.zyEqDic.TryGetValue(zy, out Dictionary<int ,List<ItemInfo>> bwDic))
  99. // {
  100. // foreach (KeyValuePair<int,List<ItemInfo>> keyValuePair in bwDic)
  101. // {
  102. // //遍历每个部位下的全部装备
  103. // foreach (ItemInfo eqInfo in keyValuePair.Value)
  104. // {
  105. // if (eqInfo.eqInfo.isEquip)
  106. // {
  107. // //这里是取部位,eqsUIObj里面的部位,是有序排列的
  108. // GameObject eqGo = eqsUIObj[keyValuePair.Key - 1] as GameObject;
  109. // WidgetItem eqItem = await UIManager.Instance.
  110. // CreateGComponentForObject<WidgetItem>(eqGo, null, root:eqGo.transform.parent.GetComponent<RectTransform>());
  111. // eqItem.InitWidget(eqInfo);
  112. //
  113. // }
  114. // }
  115. // }
  116. // }
  117. // SimpleLayout.Layout(eqsUIObj, LayoutType.Horizontal, space);
  118. }
  119. public static string GetEquipmentIconName(ItemInfo eqItem)
  120. {
  121. int q = 1;
  122. if (eqItem.eqInfo.quality > 3 && eqItem.eqInfo.quality <= 4)
  123. {
  124. q = 2;
  125. }
  126. else if (eqItem.eqInfo.quality > 4)
  127. {
  128. q = 3;
  129. }
  130. string eqIcon = "icon_eq_" +
  131. eqItem.eqInfo.basicEquipConfig.profession + "_" +
  132. eqItem.eqInfo.basicEquipConfig.Type + "_" +
  133. q;
  134. // switch (eqItem.eqInfo.basicEquipConfig.profession)
  135. return eqIcon;
  136. }
  137. /// <summary>
  138. /// 根据星级,显示不同的数量的星星和样子
  139. /// </summary>
  140. /// <param name="stars"></param>
  141. /// <param name="starGrade"></param>
  142. public static void SetStarShow(List<object> stars, int starGrade)
  143. {
  144. // 最大星级展示个数(6星,只显示一颗星星,换颜色)
  145. int maxShowStar = 5;
  146. // 计算 当前星级 应该用什么星星的表现
  147. int group = (starGrade - 1) / maxShowStar;
  148. int i = 1;
  149. int showCount = (starGrade - 1) % maxShowStar + 1;
  150. foreach (GameObject star in stars)
  151. {
  152. SetStarImg(group, star);
  153. // 根据星级显示星星
  154. if (showCount >= i)
  155. {
  156. star.SetActive(true);
  157. }
  158. else
  159. {
  160. star.SetActive(false);
  161. }
  162. i++;
  163. }
  164. SimpleLayout.Layout(stars, LayoutType.Horizontal);
  165. }
  166. private static void SetStarImg(int group, GameObject starObj)
  167. {
  168. MyImage image = starObj.GetComponent<MyImage>();
  169. // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
  170. switch (group)
  171. {
  172. case 0: // n = 1~5
  173. image.icon_name = "dec_star";
  174. break;
  175. case 1: // n = 6~10
  176. image.icon_name = "dec_star_2";
  177. break;
  178. default: // 其他情况
  179. LogTool.Error("超出设计表现");
  180. //image.icon_name = "dec_star";
  181. break;
  182. }
  183. }
  184. /// <summary>
  185. /// 修改指定 GameObject 和其所有子对象的 Layer
  186. /// </summary>
  187. /// <param name="obj">目标 GameObject</param>
  188. /// <param name="newLayer">新的 Layer 值</param>
  189. public static void ChangeLayerRecursively(GameObject obj, int newLayer)
  190. {
  191. if (obj == null || obj.layer == newLayer) return;
  192. // 修改当前对象的 Layer
  193. obj.layer = newLayer;
  194. // 遍历所有子对象,递归修改
  195. foreach (Transform child in obj.transform)
  196. {
  197. ChangeLayerRecursively(child.gameObject, newLayer);
  198. }
  199. }
  200. }
  201. }