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();
|
}
|
|
}
|
}
|