using System.Collections.Generic; using UnityEngine; namespace vnxbqy.UI { public class FairySiegeStarGroup : MonoBehaviour { readonly string StarGreyKey = "StarGrey"; readonly int StarGroupMaxCnt = 5; readonly string StarOrangeKey = "StarOrange"; readonly string StarRedKey = "StarRed"; readonly string StarYellowKey = "StarYellow"; //确保stars.Count一定要等于StarGroupMaxCnt [SerializeField] List stars = new List(); public void Display(int starRank) { var currentStage = GetCurrentStage(starRank); var currentStageCount = GetCurrentStageCount(starRank, currentStage); var prevStageRemaining = StarGroupMaxCnt - currentStageCount; //填充星星 for (var i = 0; i < stars.Count; i++) //当前阶段星星 if (i < currentStageCount) stars[i].SetSprite(GetCurrentStageKey(currentStage)); //前一阶段星星 else if (i < currentStageCount + prevStageRemaining) stars[i].SetSprite(GetPreviousStageKey(currentStage)); else stars[i].SetSprite(StarGreyKey); } private int GetCurrentStage(int starRank) { if (starRank <= 5) return 0; // 黄星阶段 if (starRank <= 10) return 1; // 橙星阶段 return 2; // 红星阶段 } private int GetCurrentStageCount(int starRank, int stage) { if (stage == 0) return starRank; if (stage == 1) return starRank - 5; if (stage == 2) return starRank - 10; return 0; } private string GetCurrentStageKey(int stage) { if (stage == 0) return StarYellowKey; if (stage == 1) return StarOrangeKey; if (stage == 2) return StarRedKey; return StarGreyKey; } private string GetPreviousStageKey(int currentStage) { if (currentStage == 1) return StarYellowKey; if (currentStage == 2) return StarOrangeKey; return StarGreyKey; } } }