(client)feat:实现子弹定义以及生成,实现初始化动画,实现血条 (#43)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
47
Client/Assets/Scripts/Managers/ItemResourceManager.cs
Normal file
47
Client/Assets/Scripts/Managers/ItemResourceManager.cs
Normal file
@ -0,0 +1,47 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user