添加图片素材读取流程
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Definition;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -17,6 +19,8 @@ namespace SepCore.UI
|
||||
[SerializeField] private FormatTextUI atkText;
|
||||
[SerializeField] private FormatTextUI matText;
|
||||
|
||||
private int _iconVersion = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 用存档角色填充格子;角色配置不存在时按空格子显示。
|
||||
/// </summary>
|
||||
@@ -36,7 +40,8 @@ namespace SepCore.UI
|
||||
speedText.Set(config.Speed);
|
||||
atkText.Set(config.Atk);
|
||||
matText.Set(config.Mat);
|
||||
HideIcon();
|
||||
_iconVersion++;
|
||||
ShowIconAsync(config.Icon_Ref, _iconVersion).Forget();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,6 +49,7 @@ namespace SepCore.UI
|
||||
/// </summary>
|
||||
public void SetEmpty()
|
||||
{
|
||||
_iconVersion++;
|
||||
characterName.text = string.Empty;
|
||||
hpText.Clear();
|
||||
mpText.Clear();
|
||||
@@ -63,5 +69,25 @@ namespace SepCore.UI
|
||||
icon.sprite = null;
|
||||
icon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载角色图标;iconVersion 用于防止复用格子时旧加载结果覆盖新内容。
|
||||
/// </summary>
|
||||
private async UniTaskVoid ShowIconAsync(SpriteConfig iconConfig, int iconVersion)
|
||||
{
|
||||
if (iconConfig == null || icon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = await SpriteLoader.LoadSpriteAsync(iconConfig);
|
||||
if (sprite == null || _iconVersion != iconVersion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
icon.sprite = sprite;
|
||||
icon.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user