HeroUITools.cs 1.7 KB

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