lcy
23 小时以前 247c64258e0102a1028199f14866a1fd1c1a205f
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class HeroCountryComponent : MonoBehaviour
{
    [SerializeField] Image countryOnImg;    //上阵阵型激活国家
    [SerializeField] UIEffectPlayer countryEffect;
    [SerializeField] List<Image> OnCountImgs;    //上阵数量激活
 
    /// <summary>
    /// 上阵队伍中各个国家的武将数量
    /// </summary>
    public Dictionary<HeroCountry, int> GetCountryHeroCountByTeamType(List<TeamHero> teamHeroes)
    {
        Dictionary<HeroCountry, int> heroCountryCount = new Dictionary<HeroCountry, int>();
        if (teamHeroes == null)
        {
            return heroCountryCount;
        }
        for (int i = 0; i < teamHeroes.Count; i++)
        {
            if (teamHeroes[i] == null)
                continue;
            var country = teamHeroes[i].Country;
 
            if (!heroCountryCount.ContainsKey(country))
            {
                heroCountryCount.Add(country, 1);
            }
            else
            {
                heroCountryCount[country] += 1;
            }
 
        }
 
 
        return heroCountryCount;
    }
 
    /// <summary>
    /// 获得上阵中武将数量最大的国家和数量
    /// </summary>
    public Int2 GetMaxCountHeroCountry(List<TeamHero> teamType)
    {
        var countryCountDict = GetCountryHeroCountByTeamType(teamType);
        //找到最大的国家和数量
        HeroCountry country = HeroCountry.None;
        int maxValue = 0;
        foreach (var data in countryCountDict)
        {
            if (data.Value > maxValue)
            {
                country = data.Key;
                maxValue = data.Value;
            }
        }
        return new Int2((int)country, maxValue);
    }
 
    //上阵武将国家光环激活
    public void RefreshOnTeamCountry(List<TeamHero> teamType, bool playEffect = false)
    {
        Int2 result = GetMaxCountHeroCountry(teamType);
 
        var config = HeroLineupHaloConfig.GetConfig(result.x, result.y);
        if (config == null)
        {
            countryOnImg.SetSprite("heroTeamCountry0");
            for (int i = 0; i < OnCountImgs.Count; i++)
            {
                OnCountImgs[i].SetActive(false);
            }
        }
        else
        {
            countryOnImg.SetSprite("heroTeamCountry" + result.x);
            for (int i = 0; i < OnCountImgs.Count; i++)
            {
                if (i < result.y)
                {
                    OnCountImgs[i].SetActive(true);
                    OnCountImgs[i].SetSprite("heroTeamCountryPoint" + result.x);
                }
                else
                {
                    OnCountImgs[i].SetActive(false);
                }
            }
            if (playEffect)
                countryEffect.Play();
        }
 
    }
 
    //上阵武将国家光环激活
    public void RefreshOnTeamCountry(TeamType selectTeamType, bool playEffect = false)
    {
        Int2 result = HeroUIManager.Instance.GetMaxCountHeroCountry(selectTeamType, true);
 
        var config = HeroLineupHaloConfig.GetConfig(result.x, result.y);
        if (config == null)
        {
            countryOnImg.SetSprite("heroTeamCountry0");
            for (int i = 0; i < OnCountImgs.Count; i++)
            {
                OnCountImgs[i].SetActive(false);
            }
        }
        else
        {
            countryOnImg.SetSprite("heroTeamCountry" + result.x);
            for (int i = 0; i < OnCountImgs.Count; i++)
            {
                if (i < result.y)
                {
                    OnCountImgs[i].SetActive(true);
                    OnCountImgs[i].SetSprite("heroTeamCountryPoint" + result.x);
                }
                else
                {
                    OnCountImgs[i].SetActive(false);
                }
            }
            if (playEffect)
                countryEffect.Play();
        }
 
    }
}