12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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;
- }
- }
-
- /// <summary>
- /// 修改指定 GameObject 和其所有子对象的 Layer
- /// </summary>
- /// <param name="obj">目标 GameObject</param>
- /// <param name="newLayer">新的 Layer 值</param>
- public static void ChangeLayerRecursively(GameObject obj, int newLayer)
- {
- if (obj == null || obj.layer == newLayer) return;
- // 修改当前对象的 Layer
- obj.layer = newLayer;
- // 遍历所有子对象,递归修改
- foreach (Transform child in obj.transform)
- {
- ChangeLayerRecursively(child.gameObject, newLayer);
- }
- }
-
- }
- }
|