47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Data;
|
|
using Item;
|
|
|
|
namespace Managers
|
|
{
|
|
public class ItemResourceManager:Utils.Singleton<ItemResourceManager>
|
|
{
|
|
//定义名,物品
|
|
public Dictionary<string,Item.ItemResource> items;
|
|
|
|
|
|
public void Init()
|
|
{
|
|
var itemDefs = Managers.DefineManager.Instance.QueryDefinesByType<ItemDef>();
|
|
if(itemDefs==null||itemDefs.Length==0)
|
|
return;
|
|
foreach (var itemDef in itemDefs)
|
|
{
|
|
var item=new Item.ItemResource();
|
|
item.name = itemDef.label;
|
|
item.description = itemDef.description;
|
|
|
|
item.icon = Managers.PackagesImageManager.Instance.GetSprite(itemDef.texture);
|
|
}
|
|
}
|
|
|
|
public ItemResource GetItem(string defName)
|
|
{
|
|
return items.GetValueOrDefault(defName,null);
|
|
}
|
|
// <summary>
|
|
/// 按物品名称查找物品
|
|
/// </summary>
|
|
/// <param name="itemName">要查找的物品名称</param>
|
|
/// <returns>找到的物品对象,如果未找到则返回 null</returns>
|
|
public ItemResource FindItemByName(string itemName)
|
|
{
|
|
if (string.IsNullOrEmpty(itemName))
|
|
{
|
|
return null;
|
|
}
|
|
return items.Values.FirstOrDefault(item => item.name == itemName);
|
|
}
|
|
}
|
|
} |