| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using System.Collections.Generic; |
| | | using System.Threading; |
| | | |
| | | public class HeroCollectionCardCell : MonoBehaviour |
| | | { |
| | |
| | | [SerializeField] GameObject activeObj; // 可激活带流光效果材质 |
| | | [SerializeField] GameObject actLimitObj; // 活动限定 |
| | | |
| | | private CancellationTokenSource displayCts; |
| | | 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); |
| | | |
| | |
| | | |
| | | HB122_tagSCHeroInfo.tagSCHero colData; |
| | | HeroUIManager.Instance.TryGetHeroBookInfo(heroID, out colData); |
| | | heroCardBG.SetSprite("herocardbg" + heroConfig.Quality); |
| | | |
| | | LoadImageAsync(heroCardBG, "herocardbg" + heroConfig.Quality, version).Forget(); |
| | | |
| | | //分为0未获得、1可激活、2常规、3突破升级、4、星升级、5已满级 |
| | | int funcState = HeroUIManager.Instance.GetHeroBookState(heroID, quality); |
| | |
| | | unGetObj.SetActive(funcState == 0); |
| | | actLimitObj.SetActive(heroConfig.IsActLimit == 1); |
| | | |
| | | countryImg.SetSprite(HeroUIManager.Instance.GetCountryIconName(heroConfig.Country)); |
| | | jobImg.SetSprite(HeroUIManager.Instance.GetJobIconName(heroConfig.Class)); |
| | | LoadImageAsync(countryImg, HeroUIManager.Instance.GetCountryIconName(heroConfig.Country), version).Forget(); |
| | | LoadImageAsync(jobImg, HeroUIManager.Instance.GetJobIconName(heroConfig.Class), version).Forget(); |
| | | |
| | | // 去抖加载:快速滚动时延迟2帧再创建Spine,如果卡片在延迟内被复用则取消旧加载 |
| | | displayCts?.Cancel(); |
| | | displayCts?.Dispose(); |
| | | displayCts = new CancellationTokenSource(); |
| | | DelayedCreateSpine(heroConfig.SkinIDList[0], heroConfig.UIScale, displayCts.Token).Forget(); |
| | | DelayedCreateSpine(heroConfig.SkinIDList[0], heroConfig.UIScale, version).Forget(); |
| | | |
| | | redpoint.redpointId = MainRedDot.HeroCardCollectRedpoint * 10000000 + heroID; |
| | | |
| | | if (funcState == 3 || funcState == 4) |
| | | { |
| | | trainStateImg.SetActive(true); |
| | | trainStateImg.SetSprite("herofuncstate4"); |
| | | LoadImageAsync(trainStateImg, "herofuncstate4", version).Forget(); |
| | | } |
| | | else |
| | | { |
| | |
| | | UIManager.Instance.OpenWindowAsync<HeroBestBaseWin>().Forget(); |
| | | } |
| | | }); |
| | | |
| | | // bookLVBtn.AddListener(() => |
| | | // { |
| | | // HeroUIManager.Instance.selectCollectHeroID = heroID; |
| | | // UIManager.Instance.OpenWindow<HeroCollectionLvUpWin>(); |
| | | // }); |
| | | } |
| | | |
| | | private async UniTaskVoid DelayedCreateSpine(int skinID, float scale, CancellationToken ct) |
| | | private async UniTaskVoid LoadImageAsync(Image image, string iconKey, int version) |
| | | { |
| | | // 延迟2帧,快速滚动时卡片会被复用,CTS取消后不会继续创建Spine |
| | | await UniTask.NextFrame(ct); |
| | | await UniTask.NextFrame(ct); |
| | | 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(); |
| | | } |
| | | |
| | | void OnDestroy() |
| | | { |
| | | displayCts?.Cancel(); |
| | | displayCts?.Dispose(); |
| | | } |
| | | } |
| | | |