HeroUITools.cs 6.0 KB

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