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
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class HeroPosHeadCell : MonoBehaviour
{
    [SerializeField] HeroHeadBaseCell heroHeadBaseCell;
    [SerializeField] Image jobImg;
    [SerializeField] Text nameText;
    [SerializeField] Transform selectRect;
 
    public void Display(int index)
    {
        var guid = HeroUIManager.Instance.heroOnTeamSortList[index];
        var hero = HeroManager.Instance.GetHero(guid);
        var team = TeamManager.Instance.GetTeam(HeroUIManager.Instance.selectTeamType);
        selectRect.SetActive(team.GetHero(guid) != null);
 
        heroHeadBaseCell.Init(hero.heroId, hero.SkinID, hero.heroStar, hero.awakeLevel, hero.heroLevel, () =>
        {
            Click(hero, index);
        });
        nameText.text = hero.breakLevel == 0 ? hero.heroConfig.Name : Language.Get("herocardbreaklv", hero.heroConfig.Name, hero.breakLevel);
        
        jobImg.SetSprite(HeroUIManager.Instance.GetJobIconName(hero.heroConfig.Class));
    }
 
    void Click(HeroInfo hero, int index)
    {
        //检查是否可上阵,查找上阵位置,显示勾选,飞入上阵位置
        var team = TeamManager.Instance.GetTeam(HeroUIManager.Instance.selectTeamType);
        int pos;
        if (selectRect.gameObject.activeSelf)
        {
            selectRect.SetActive(false);
            if (team.RemoveHero(hero, out pos))
            { 
                //通知刷新(下阵)
                HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { pos }, -1, Vector3.zero);
            }
            return;
        }
 
        team.AddHero(hero, out pos);
        if (pos != -1)
        {
            selectRect.SetActive(true);
            //通知刷新,上阵,图片飞入(上阵位置)
            HeroUIManager.Instance.NotifyOnTeamPosChangeEvent(new List<int>() { pos }, index, heroHeadBaseCell.transform.position);
        }
    }
}