添加图片素材读取流程
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Base;
|
||||
using SepCore.Definition;
|
||||
using TMPro;
|
||||
@@ -26,6 +28,7 @@ namespace SepCore.UI
|
||||
private int _slotId = 0;
|
||||
private bool _filled = false;
|
||||
private bool _clickBound = false;
|
||||
private int _iconVersion = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 设置格子在固定网格中的索引,点击事件以此作为唯一标识。
|
||||
@@ -49,9 +52,10 @@ namespace SepCore.UI
|
||||
}
|
||||
|
||||
_filled = true;
|
||||
_iconVersion++;
|
||||
rarity.color = GetRarityColor(config.Rarity);
|
||||
quantityText.text = stack.count.ToString();
|
||||
HideIcon();
|
||||
ShowIconAsync(config.Icon_Ref, _iconVersion).Forget();
|
||||
BindClick();
|
||||
if (button != null)
|
||||
{
|
||||
@@ -65,6 +69,7 @@ namespace SepCore.UI
|
||||
public void SetEmpty()
|
||||
{
|
||||
_filled = false;
|
||||
_iconVersion++;
|
||||
rarity.color = RarityEmpty;
|
||||
quantityText.text = string.Empty;
|
||||
HideIcon();
|
||||
@@ -117,6 +122,26 @@ namespace SepCore.UI
|
||||
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);
|
||||
}
|
||||
|
||||
private static Color GetRarityColor(Rarity rarity)
|
||||
{
|
||||
switch (rarity)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.AsyncTask;
|
||||
using SepCore.Definition;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
@@ -10,11 +12,14 @@ namespace SepCore.UI
|
||||
/// </summary>
|
||||
public partial class ItemDetailsForm : UGuiForm
|
||||
{
|
||||
private int _iconVersion = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 按物品 ID 刷新详情界面;配置不存在时清空显示。
|
||||
/// </summary>
|
||||
public void Refresh(int itemId)
|
||||
{
|
||||
_iconVersion++;
|
||||
ItemDetailsView view = View;
|
||||
if (view == null)
|
||||
{
|
||||
@@ -79,6 +84,8 @@ namespace SepCore.UI
|
||||
{
|
||||
view.itemDetailIcon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
ShowIconAsync(config.Icon_Ref, _iconVersion).Forget();
|
||||
}
|
||||
|
||||
private static void ClearDetails(ItemDetailsView view)
|
||||
@@ -97,6 +104,31 @@ namespace SepCore.UI
|
||||
{
|
||||
view.itemDetailDescriptionText.text = string.Empty;
|
||||
}
|
||||
|
||||
if (view.itemDetailIcon != null)
|
||||
{
|
||||
view.itemDetailIcon.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载物品图标;iconVersion 用于防止连续刷新时旧加载结果覆盖新内容。
|
||||
/// </summary>
|
||||
private async UniTaskVoid ShowIconAsync(SpriteConfig iconConfig, int iconVersion)
|
||||
{
|
||||
if (iconConfig == null || View == null || View.itemDetailIcon == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite sprite = await SpriteLoader.LoadSpriteAsync(iconConfig);
|
||||
if (sprite == null || _iconVersion != iconVersion)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
View.itemDetailIcon.sprite = sprite;
|
||||
View.itemDetailIcon.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private static string GetItemTypeName(ItemType itemType)
|
||||
|
||||
Reference in New Issue
Block a user