1
This commit is contained in:
@@ -28,6 +28,7 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
public Button btn_RenShu;
|
||||
public Button btn_HuiQi;
|
||||
public Button btn_SheZhi;
|
||||
public Button btn_GuiZe;
|
||||
public Button btn_StartGame;
|
||||
public Image img_DengDaiZhong;
|
||||
public ChessGameRoom roomData;
|
||||
@@ -46,6 +47,35 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
|
||||
private Coroutine waitCountdown;
|
||||
|
||||
/// <summary>
|
||||
/// 加载头像精灵(优先使用缓存,否则异步下载)
|
||||
/// </summary>
|
||||
public static void LoadAvatar(Image target, string avatarUrl, System.Action<Sprite> onLoaded = null)
|
||||
{
|
||||
if (target == null) return;
|
||||
var sprite = GameManager.Instance.GetAvatarSprite(avatarUrl);
|
||||
if (sprite != null)
|
||||
{
|
||||
target.sprite = sprite;
|
||||
onLoaded?.Invoke(sprite);
|
||||
return;
|
||||
}
|
||||
// 缓存未命中,通过 DownSprite 协程异步加载
|
||||
GameManager.Instance.StartCoroutine(LoadAvatarCoroutine(target, avatarUrl, onLoaded));
|
||||
}
|
||||
|
||||
private static IEnumerator LoadAvatarCoroutine(Image target, string avatarUrl, System.Action<Sprite> onLoaded)
|
||||
{
|
||||
// 构造一个临时的 UserBaseInfo 对象来复用 DownSprite 逻辑
|
||||
var tempInfo = new UserBaseInfo { avatarUrl = avatarUrl };
|
||||
yield return tempInfo.DownSprite(sprite =>
|
||||
{
|
||||
if (sprite != null && target != null)
|
||||
target.sprite = sprite;
|
||||
onLoaded?.Invoke(sprite);
|
||||
});
|
||||
}
|
||||
|
||||
public static string FormatGold(long gold)
|
||||
{
|
||||
if (gold >= 100000000)
|
||||
@@ -143,19 +173,13 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
{
|
||||
tmp_Name_Bottom.text ="ID:" + item.userId;
|
||||
tmp_CoinCount_Bottom.text = FormatGold(item.gold);
|
||||
StartCoroutine(item.DownTexture2d((t2d) =>
|
||||
{
|
||||
img_Title_Bottom.sprite = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), new Vector2(0.5f, 0.5f));
|
||||
}));
|
||||
LoadAvatar(img_Title_Bottom, item.userAvatar);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_Name_Top.text ="ID:" + item.userId;
|
||||
tmp_CoinCount_Top.text = FormatGold(item.gold);
|
||||
StartCoroutine(item.DownTexture2d((t2d) =>
|
||||
{
|
||||
img_Title_Top.sprite = Sprite.Create(t2d, new Rect(0, 0, t2d.width, t2d.height), new Vector2(0.5f, 0.5f));
|
||||
}));
|
||||
LoadAvatar(img_Title_Top, item.userAvatar);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,6 +191,10 @@ public class ChineseChessMainPanel : GameMainPanel_Base
|
||||
{
|
||||
UIManager.Instance.Close(UIPanel.MainGamePanelZGXQ);
|
||||
});
|
||||
btn_GuiZe.onClick.AddListener(() =>
|
||||
{
|
||||
subUIManager.ShowAsync(UIPanel.ZGXQIntroduce);
|
||||
});
|
||||
}
|
||||
protected override void OnShow(object args = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user