主页与Task任务处理
This commit is contained in:
44
Assets/TcgEngine/Scripts/Data/TaskRewardData.cs
Normal file
44
Assets/TcgEngine/Scripts/Data/TaskRewardData.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user