using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class HeroCountryComponent : MonoBehaviour { [SerializeField] Image countryOnImg; //上阵阵型激活国家 [SerializeField] UIEffectPlayer countryEffect; [SerializeField] List OnCountImgs; //上阵数量激活 /// /// 上阵队伍中各个国家的武将数量 /// public Dictionary GetCountryHeroCountByTeamType(List teamHeroes) { Dictionary heroCountryCount = new Dictionary(); 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; } /// /// 获得上阵中武将数量最大的国家和数量 /// public Int2 GetMaxCountHeroCountry(List 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 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(); } } }