| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 | using System.Collections.Generic;using Fort23.UTool;using UnityEngine;using UnityEngine.UI;namespace Fort23.Mono{    public static class HeroUITools    {        /// <summary>        /// 根据星级,显示不同的数量的星星和样子        /// </summary>        /// <param name="stars"></param>        /// <param name="starGrade"></param>        public static void SetStarShow(List<object> stars, int starGrade)        {            // 最大星级展示个数(6星,只显示一颗星星,换颜色)            int maxShowStar = 5;            // 计算 当前星级 应该用什么星星的表现            int group = (starGrade - 1) / maxShowStar;            int i = 1;            int showCount = (starGrade - 1) % maxShowStar + 1;            foreach (GameObject star in stars)            {                SetStarImg(group, star);                // 根据星级显示星星                if (showCount >= i)                {                    star.SetActive(true);                }                else                {                    star.SetActive(false);                }                i++;            }        }                private static void SetStarImg(int group, GameObject starObj)        {            MyImage image = starObj.GetComponent<MyImage>();            // 执行对应的逻辑  (0)GradeIcon_Star_s_Yellow  (1)GradeIcon_Star_s_Premium            switch (group)            {                case 0: // n = 1~5                    image.icon_name = "dec_star";                    break;                case 1: // n = 6~10                    image.icon_name = "dec_star_2";                        break;                default: // 其他情况                    LogTool.Error("超出设计表现");                    //image.icon_name = "dec_star";                    break;            }        }            }}
 |