调整 SpriteCache 的读取资源方式

将原来 UGF 事件回调风格的调用改成使用 UniTask 的异步操作
This commit is contained in:
2026-06-16 17:08:06 +08:00
parent 117dd123de
commit 170ea690b2
8 changed files with 88 additions and 83 deletions
@@ -1,3 +1,4 @@
using Cysharp.Threading.Tasks;
using SepCore.CustomUtility;
using SepCore.DataTable;
using SepCore.Definition;
@@ -24,31 +25,37 @@ namespace SepCore.UI
ItemType = ItemType.None;
}
public GoodsItemContext(GoodsItemRawData rawData)
public static async UniTask<GoodsItemContext> CreateAsync(GoodsItemRawData rawData)
{
Price = rawData.Price;
Rarity = rawData.Rarity;
ItemType = rawData.ItemType;
if (ItemType == ItemType.None)
var context = new GoodsItemContext
{
Description = string.Empty;
Icon = null;
Title = string.Empty;
Price = rawData.Price,
Rarity = rawData.Rarity,
ItemType = rawData.ItemType
};
if (context.ItemType == ItemType.None)
{
context.Description = string.Empty;
context.Icon = null;
context.Title = string.Empty;
}
else if (ItemType == ItemType.Weapon)
else if (context.ItemType == ItemType.Weapon)
{
var weapon = (DRWeapon)rawData.DataRow;
Title = weapon.Title;
Description = ItemDescUtility.CreateWeaponDescription(weapon);
GameEntry.SpriteCache.GetSprite(weapon.IconAssetName, sprite => Icon = sprite);
context.Title = weapon.Title;
context.Description = ItemDescUtility.CreateWeaponDescription(weapon);
context.Icon = await GameEntry.SpriteCache.GetSprite(weapon.IconAssetName);
}
else
{
var prop = (DRProp)rawData.DataRow;
Title = prop.Title;
Description = ItemDescUtility.CreatePropDescription(prop.Modifiers);
GameEntry.SpriteCache.GetSprite(prop.IconAssetName, sprite => Icon = sprite);
context.Title = prop.Title;
context.Description = ItemDescUtility.CreatePropDescription(prop.Modifiers);
context.Icon = await GameEntry.SpriteCache.GetSprite(prop.IconAssetName);
}
return context;
}
}
}