44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TcgEngine.UI;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
|
|
[System.Serializable]
|
|
public class PrizeIconEntry
|
|
{
|
|
public TaskRewardType type;
|
|
public Sprite icon;
|
|
}
|
|
|
|
[CreateAssetMenu(fileName = "NewTaskRewardData", menuName = "TcgEngine/TaskRewardData")]
|
|
public class TaskRewardData : ScriptableObject
|
|
{
|
|
public PrizeIconEntry[] entries;
|
|
|
|
private Dictionary<TaskRewardType, Sprite> iconDict = new Dictionary<TaskRewardType, Sprite>();
|
|
|
|
public void Init()
|
|
{
|
|
iconDict.Clear();
|
|
foreach (var entry in entries)
|
|
{
|
|
Debug.Log($"录入: {entry.type} => {entry.icon?.name}");
|
|
iconDict[entry.type] = entry.icon;
|
|
}
|
|
}
|
|
|
|
public Sprite GetIcon(TaskRewardType type)
|
|
{
|
|
if (iconDict.Count == 0) Init();
|
|
|
|
if (iconDict.TryGetValue(type, out Sprite sprite))
|
|
return sprite;
|
|
|
|
Debug.LogWarning($"未找到 {type} 的图标,请检查 TaskRewardData 的 entries 配置");
|
|
return null;
|
|
}
|
|
|
|
}
|
|
} |