using UnityEngine;
|
using UnityEngine.UI;
|
using System.Collections.Generic;
|
|
//主界面卡牌
|
public class HeroFightingCardCell : MonoBehaviour
|
{
|
|
[SerializeField] Button clickHeroBtn;
|
[SerializeField] Image qualityBG;
|
[SerializeField] Image heroIcon;
|
[SerializeField] Text lvText;
|
[SerializeField] Image countryImg;
|
[SerializeField] Transform starRect;
|
[SerializeField] List<Image> starsImg;
|
[SerializeField] UIEffectPlayer fightEffect;
|
[SerializeField] FillTween cdTween;
|
|
[SerializeField] Button clickEmptyBtn;
|
|
|
void OnEnable()
|
{
|
AutoFightModel.Instance.OnFightEvent += OnSkillCast;
|
}
|
|
void OnDisable()
|
{
|
AutoFightModel.Instance.OnFightEvent -= OnSkillCast;
|
}
|
|
string guid;
|
public void Display(int index)
|
{
|
var team = TeamManager.Instance.GetTeam(TeamType.Story);
|
var teamHero = team.GetServerHeroByIndex(index);
|
guid = teamHero != null ? teamHero.guid : "";
|
if (guid == "")
|
{
|
clickHeroBtn.SetActive(false);
|
clickEmptyBtn.SetActive(true);
|
clickEmptyBtn.AddListener(ClickEmpty);
|
return;
|
}
|
else
|
{
|
clickHeroBtn.SetActive(true);
|
clickEmptyBtn.SetActive(false);
|
}
|
|
var hero = HeroManager.Instance.GetHero(guid);
|
var heroID = hero.heroId;
|
var star = hero.heroStar;
|
clickHeroBtn.AddListener(ClickHero);
|
var heroConfig = HeroConfig.Get(heroID);
|
qualityBG.SetSprite("herocBG" + heroConfig.Quality);
|
|
var sprite = UILoader.LoadSprite("HeroHead", HeroSkinConfig.Get(hero.SkinID).RectangleIcon);
|
if (sprite == null)
|
{
|
// 内网未配置时
|
heroIcon.SetSprite("herohead_big_default");
|
}
|
else
|
{
|
heroIcon.overrideSprite = sprite;
|
}
|
|
if (star == 0)
|
{
|
starRect.SetActive(false);
|
}
|
else
|
{
|
starRect.SetActive(true);
|
for (int i = 0; i < starsImg.Count; i++)
|
{
|
if ((star - 1) % starsImg.Count >= i)
|
{
|
starsImg[i].SetActive(true);
|
starsImg[i].SetSprite("herostar" + (((star - 1) / starsImg.Count) + 1) * starsImg.Count);
|
}
|
else
|
{
|
starsImg[i].SetActive(false);
|
}
|
}
|
}
|
|
countryImg.SetSprite(HeroUIManager.Instance.GetCountryIconName(heroConfig.Country));
|
lvText.text = hero.heroLevel == 0 ? "" : Language.Get("L1094") + hero.heroLevel;
|
|
RefreshFightIng(false);
|
|
}
|
|
|
void ClickHero()
|
{
|
HeroUIManager.Instance.selectHeroListJob = 0;
|
HeroUIManager.Instance.selectHeroListCountry = 0;
|
HeroUIManager.Instance.SortHeroList();
|
HeroUIManager.Instance.selectHeroGuid = guid;
|
UIManager.Instance.OpenWindow<HeroTrainWin>();
|
}
|
|
void ClickEmpty()
|
{
|
UIManager.Instance.OpenWindow<HeroCallWin>();
|
}
|
void OnSkillCast(bool isfighting)
|
{
|
|
if (isfighting && !string.IsNullOrEmpty(guid) && guid == AutoFightModel.Instance.heroGuid)
|
{
|
RefreshFightIng(true);
|
}
|
|
}
|
|
void RefreshFightIng(bool isfighting)
|
{
|
if (isfighting)
|
{
|
fightEffect.Play();
|
cdTween.SetStartState();
|
cdTween.Play();
|
}
|
else
|
{
|
fightEffect.Stop();
|
cdTween.Stop();
|
cdTween.SetEndState();
|
}
|
}
|
|
}
|