HeroUITools.cs 8.7 KB

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