From 97de31e9a015cf139f5293a22e1575a43dfb6733 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期五, 24 四月 2026 14:16:02 +0800
Subject: [PATCH] WEBGL ANDROID适配
---
Main/System/HeroUI/HeroCollectionCardCell.cs | 50 +++++++++++++++++++++++---------------------------
1 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/Main/System/HeroUI/HeroCollectionCardCell.cs b/Main/System/HeroUI/HeroCollectionCardCell.cs
index 9466d7f..b93702d 100644
--- a/Main/System/HeroUI/HeroCollectionCardCell.cs
+++ b/Main/System/HeroUI/HeroCollectionCardCell.cs
@@ -2,7 +2,6 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
-using System.Threading;
public class HeroCollectionCardCell : MonoBehaviour
{
@@ -20,9 +19,13 @@
[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);
@@ -30,7 +33,8 @@
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);
@@ -40,21 +44,17 @@
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
{
@@ -81,26 +81,22 @@
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甯э紝蹇�熸粴鍔ㄦ椂鍗$墖浼氳澶嶇敤锛孋TS鍙栨秷鍚庝笉浼氱户缁垱寤篠pine
- 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();
}
}
--
Gitblit v1.8.0