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; 
 | 
    [SerializeField] Image emptyLockImg; 
 | 
    [SerializeField] Image redPointImg; 
 | 
    [SerializeField] UIEffectPlayer unlockEffect; 
 | 
  
 | 
    void OnEnable() 
 | 
    { 
 | 
        AutoFightModel.Instance.OnFightEvent += OnSkillCast; 
 | 
    } 
 | 
  
 | 
    void OnDisable() 
 | 
    { 
 | 
        AutoFightModel.Instance.OnFightEvent -= OnSkillCast; 
 | 
    } 
 | 
  
 | 
    string guid; 
 | 
    int lockIndex; 
 | 
    public void Display(int index, List<TeamHero> heros) 
 | 
    { 
 | 
        TeamHero teamHero = null; 
 | 
        if (index < heros.Count) 
 | 
        { 
 | 
            teamHero = heros[index]; 
 | 
        } 
 | 
        guid = teamHero != null ? teamHero.guid : ""; 
 | 
        if (guid == "") 
 | 
        { 
 | 
            clickHeroBtn.SetActive(false); 
 | 
            clickEmptyBtn.SetActive(true); 
 | 
            clickEmptyBtn.AddListener(ClickEmpty); 
 | 
            emptyLockImg.SetActive(false); 
 | 
            redPointImg.SetActive(false); 
 | 
  
 | 
            int lockCnt = HeroUIManager.Instance.lockIndexList.Count; 
 | 
            //根据锁数量 倒序判断锁住 
 | 
            if (lockCnt > 0) 
 | 
            { 
 | 
                lockIndex = lockCnt - (TeamConst.MaxTeamHeroCount - 1 - index) - 1; 
 | 
                if (lockIndex >= 0 && lockIndex < lockCnt) 
 | 
                { 
 | 
                    emptyLockImg.SetActive(true); 
 | 
                    redPointImg.SetActive(HeroUIManager.Instance.CanUnLock(HeroUIManager.Instance.lockIndexList[lockIndex])); 
 | 
                } 
 | 
            } 
 | 
  
 | 
            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() 
 | 
    { 
 | 
        if (emptyLockImg.isActiveAndEnabled) 
 | 
        { 
 | 
            if (HeroUIManager.Instance.UnLockHeroCnt(lockIndex)) 
 | 
            { 
 | 
                unlockEffect.onComplete = () => 
 | 
                { 
 | 
                    HeroUIManager.Instance.OnUnLockHeroCountEvent?.Invoke(); 
 | 
                    SysNotifyMgr.Instance.ShowTip("HeroCountUnLock5", TeamConst.MaxTeamHeroCount - HeroUIManager.Instance.lockIndexList.Count); 
 | 
                }; 
 | 
                unlockEffect.Play(); 
 | 
            } 
 | 
            return; 
 | 
        } 
 | 
        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(); 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |