HeroUITools.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections.Generic;
  2. using Fort23.UTool;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace Fort23.Mono
  6. {
  7. public static class HeroUITools
  8. {
  9. /// <summary>
  10. /// 根据星级,显示不同的数量的星星和样子
  11. /// </summary>
  12. /// <param name="stars"></param>
  13. /// <param name="starGrade"></param>
  14. public static void SetStarShow(List<object> stars, int starGrade)
  15. {
  16. // 最大星级展示个数(6星,只显示一颗星星,换颜色)
  17. int maxShowStar = 5;
  18. // 计算 当前星级 应该用什么星星的表现
  19. int group = (starGrade - 1) / maxShowStar;
  20. int i = 1;
  21. int showCount = (starGrade - 1) % maxShowStar + 1;
  22. foreach (GameObject star in stars)
  23. {
  24. SetStarImg(group, star);
  25. // 根据星级显示星星
  26. if (showCount >= i)
  27. {
  28. star.SetActive(true);
  29. }
  30. else
  31. {
  32. star.SetActive(false);
  33. }
  34. i++;
  35. }
  36. }
  37. private static void SetStarImg(int group, GameObject starObj)
  38. {
  39. MyImage image = starObj.GetComponent<MyImage>();
  40. // 执行对应的逻辑 (0)GradeIcon_Star_s_Yellow (1)GradeIcon_Star_s_Premium
  41. switch (group)
  42. {
  43. case 0: // n = 1~5
  44. image.icon_name = "dec_star";
  45. break;
  46. case 1: // n = 6~10
  47. image.icon_name = "dec_star_2";
  48. break;
  49. default: // 其他情况
  50. LogTool.Error("超出设计表现");
  51. //image.icon_name = "dec_star";
  52. break;
  53. }
  54. }
  55. }
  56. }