85 lines
2.2 KiB
C#
85 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 负责工具材料包管理
|
|
/// </summary>
|
|
public class PacksackBagMgr : BaseManager<PacksackBagMgr>
|
|
{
|
|
//包里用了哪些工器具
|
|
private readonly Dictionary<ItemInfo, List<ItemInfo>> toolAndMaterialDic = new Dictionary<ItemInfo, List<ItemInfo>>();
|
|
|
|
|
|
private PacksackBagMgr()
|
|
{
|
|
}
|
|
|
|
public Dictionary<ItemInfo, List<ItemInfo>> GetCurrentBagData()
|
|
{
|
|
return toolAndMaterialDic;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public void AddOneToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo))
|
|
{
|
|
toolAndMaterialDic[itemInfo].Add(itemInfo);
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Add(itemInfo, new List<ItemInfo>() { itemInfo });
|
|
}
|
|
}
|
|
|
|
public Dictionary<ItemInfo, List<ItemInfo>> GetItemsByE_TMDType(E_ToolOrDeviceOrMaterials tmdTpye)
|
|
{
|
|
Dictionary<ItemInfo, List<ItemInfo>> tempNew = new Dictionary<ItemInfo, List<ItemInfo>>();
|
|
|
|
var dicTemp = GetCurrentBagData();
|
|
foreach (var item in dicTemp.Keys)
|
|
{
|
|
if (item.toolOrDeviceOrMaterial == tmdTpye)
|
|
{
|
|
if (tempNew.ContainsKey(item))
|
|
{
|
|
tempNew[item].Add(item);
|
|
}
|
|
else
|
|
{
|
|
tempNew.Add(item, new List<ItemInfo>() { item });
|
|
}
|
|
}
|
|
|
|
}
|
|
return tempNew;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public bool RemoveOneToolOrMater(ItemInfo itemInfo, ref int count)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo))
|
|
{
|
|
if (toolAndMaterialDic[itemInfo].Count > 1)
|
|
{
|
|
toolAndMaterialDic[itemInfo].Remove(itemInfo);
|
|
count = toolAndMaterialDic[itemInfo].Count;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Remove(itemInfo);
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
} |