调整 SpriteCache 的读取资源方式
将原来 UGF 事件回调风格的调用改成使用 UniTask 的异步操作
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -19,7 +20,7 @@ namespace SepCore.UI
|
||||
_index = index;
|
||||
}
|
||||
|
||||
public void OnInit(DisplayItemContext context, int index)
|
||||
public async UniTaskVoid OnInit(DisplayItemContext context, int index)
|
||||
{
|
||||
if (context == null) return;
|
||||
|
||||
@@ -28,8 +29,8 @@ namespace SepCore.UI
|
||||
|
||||
if (_iconArea != null)
|
||||
{
|
||||
string iconName = _context.IconAssetName;
|
||||
GameEntry.SpriteCache.GetSprite(iconName, sprite => { _iconArea.OnInit(sprite, context.Rarity); });
|
||||
var sprite = await GameEntry.SpriteCache.GetSprite(_context.IconAssetName);
|
||||
_iconArea.OnInit(sprite, context.Rarity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -32,16 +33,17 @@ namespace SepCore.UI
|
||||
if (_descriptionText != null) _descriptionText.text = context.Description;
|
||||
if (_iconArea != null) _iconArea.OnInit(context.Icon, context.ItemRarity);
|
||||
|
||||
LoadIcon(_context.IconAssetName);
|
||||
LoadIcon(_context.IconAssetName).Forget();
|
||||
}
|
||||
|
||||
private void LoadIcon(string iconAssetName)
|
||||
private async UniTaskVoid LoadIcon(string iconAssetName)
|
||||
{
|
||||
if (_iconArea == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(iconAssetName)) return;
|
||||
|
||||
GameEntry.SpriteCache.GetSprite(iconAssetName, sprite => _iconArea.SetIcon(sprite));
|
||||
var sprite = await GameEntry.SpriteCache.GetSprite(iconAssetName);
|
||||
_iconArea.SetIcon(sprite);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user