少年修仙传客户端代码仓库
hch
2025-07-24 50e53441950268933694eeb5aad36147bbe1014d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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<ImageEx> stars = new List<ImageEx>();
 
        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;
        }
    }
}