yyl
2026-05-08 ea4e25ceca21484cbb422b4ce49ec6bc1220441f
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
 
public class HeroCollectionCardCell : MonoBehaviour
{
    [SerializeField] Button heroCardBtn;
    [SerializeField] Image heroCardBG;
    [SerializeField] UIHeroController heroModel;
    [SerializeField] List<Image> starImgList;
    [SerializeField] Image countryImg;
    [SerializeField] Image jobImg;
    [SerializeField] Text nameText;
    [SerializeField] Image trainStateImg;
    [SerializeField] RedpointBehaviour redpoint;
    // [SerializeField] Button bookLVBtn;
    [SerializeField] GameObject unGetObj;
    [SerializeField] GameObject activeObj; // 可激活带流光效果材质
    [SerializeField] GameObject actLimitObj; // 活动限定
 
    private int displayVersion;
 
    public void Display(int index, int quality)
    {
        displayVersion++;
        int version = displayVersion;
 
        var heroID = HeroUIManager.Instance.heroCollectDict[quality][index];
        var heroConfig = HeroConfig.Get(heroID);
 
        this.gameObject.name = $"herocard_{heroID}";
 
        HB122_tagSCHeroInfo.tagSCHero colData;
        HeroUIManager.Instance.TryGetHeroBookInfo(heroID, out colData);
 
        LoadImageAsync(heroCardBG, "herocardbg" + heroConfig.Quality, version).Forget();
 
        //分为0未获得、1可激活、2常规、3突破升级、4、星升级、5已满级
        int funcState = HeroUIManager.Instance.GetHeroBookState(heroID, quality);
 
        activeObj.SetActive(funcState == 1);
        // bookLVBtn.SetActive(funcState > 1);
        unGetObj.SetActive(funcState == 0);
        actLimitObj.SetActive(heroConfig.IsActLimit == 1);
 
        LoadImageAsync(countryImg, HeroUIManager.Instance.GetCountryIconName(heroConfig.Country), version).Forget();
        LoadImageAsync(jobImg, HeroUIManager.Instance.GetJobIconName(heroConfig.Class), version).Forget();
 
        DelayedCreateSpine(heroConfig.SkinIDList[0], heroConfig.UIScale, version).Forget();
 
        redpoint.redpointId = MainRedDot.HeroCardCollectRedpoint * 10000000 + heroID;
 
        if (funcState == 3 || funcState == 4)
        {
            trainStateImg.SetActive(true);
            LoadImageAsync(trainStateImg, "herofuncstate4", version).Forget();
        }
        else
        {
            trainStateImg.SetActive(false);
        }
        nameText.text = heroConfig.Name;
 
        for (int i = 0; i < starImgList.Count; i++)
        {
            starImgList[i].SetActive(false);
        }
 
        heroCardBtn.AddListener(() =>
        {
            HeroUIManager.Instance.selectCollectHeroID = heroID;
            var state = HeroUIManager.Instance.GetHeroBookState(heroID, quality);
            if (state == 1 || state == 3 || state == 4)
            {
                UIManager.Instance.OpenWindowAsync<HeroCollectionLvUpWin>().Forget();
            }
            else
            {
                HeroUIManager.Instance.selectForPreviewHeroID = heroID;
                UIManager.Instance.OpenWindowAsync<HeroBestBaseWin>().Forget();
            }
        });
    }
 
    private async UniTaskVoid LoadImageAsync(Image image, string iconKey, int version)
    {
        var sprite = await UILoader.LoadSpriteAsync(iconKey);
        if (displayVersion != version) return;
        if (image != null && sprite != null)
            image.overrideSprite = sprite;
    }
 
    private async UniTaskVoid DelayedCreateSpine(int skinID, float scale, int version)
    {
        await UniTask.NextFrame();
        await UniTask.NextFrame();
        if (displayVersion != version) return;
        heroModel.Create(skinID, scale).Forget();
    }
}