165 lines
4.6 KiB
C#
165 lines
4.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 负责工具材料包管理
|
|
/// </summary>
|
|
public class PacksackBagMgr : BaseManager<PacksackBagMgr>
|
|
{
|
|
/// <summary>
|
|
/// 背包里所有东西
|
|
/// </summary>
|
|
public Dictionary<string, List<ItemInfo>> toolAndMaterialDic = new Dictionary<string, List<ItemInfo>>();
|
|
/// <summary>
|
|
/// 已经穿戴
|
|
/// </summary>
|
|
public Dictionary<string, ItemInfo> wearDic = new Dictionary<string, ItemInfo>();
|
|
|
|
private PacksackBagMgr()
|
|
{
|
|
}
|
|
|
|
public Dictionary<string, List<ItemInfo>> GetCurrentBagData()
|
|
{
|
|
return toolAndMaterialDic;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public void AddOneToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
|
|
{
|
|
toolAndMaterialDic[itemInfo.toolName].Add(itemInfo);
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Add(itemInfo.toolName, new List<ItemInfo>() { itemInfo });
|
|
}
|
|
}
|
|
|
|
public Dictionary<string, List<ItemInfo>> GetItemsByE_TMDType(E_ToolOrDeviceOrMaterials tmdTpye)
|
|
{
|
|
Dictionary<string, List<ItemInfo>> tempNew = new Dictionary<string, List<ItemInfo>>();
|
|
|
|
D_ToolAndMaterialData dTMD = GameManager.ToolAndmaterialMgr.GetToolOrMaterialOrDeviceInfoByObjName("手机");
|
|
ItemInfo itemInfo = new ItemInfo();
|
|
if (dTMD != null)
|
|
{
|
|
itemInfo.toolId = dTMD.id;
|
|
itemInfo.triggerID = dTMD.id;
|
|
itemInfo.toolName = dTMD.objName;
|
|
itemInfo.toolOrDeviceOrMaterial = (E_ToolOrDeviceOrMaterials)dTMD.type;
|
|
itemInfo.objPrefab = Resources.Load<GameObject>("Prefabs/Objects/Tools/手机");
|
|
itemInfo.selfPosInToolRoom = new Vector3(0,0,0);
|
|
tempNew.Add("手机", new List<ItemInfo>() { itemInfo });
|
|
}
|
|
|
|
|
|
var dicTemp = toolAndMaterialDic;
|
|
foreach (var item in dicTemp.Keys)
|
|
{
|
|
for (int i = 0; i < dicTemp[item].Count; i++)
|
|
{
|
|
if (dicTemp[item][i].toolOrDeviceOrMaterial == tmdTpye)
|
|
{
|
|
|
|
if (tempNew.ContainsKey(dicTemp[item][i].toolName))
|
|
{
|
|
tempNew[dicTemp[item][i].toolName].Add(dicTemp[item][i]);
|
|
}
|
|
else
|
|
{
|
|
tempNew.Add(dicTemp[item][i].toolName, new List<ItemInfo>() { dicTemp[item][i] });
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return tempNew;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 移除一个工器具或材料
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
public void RemoveOneToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
|
|
{
|
|
if (toolAndMaterialDic[itemInfo.toolName].Count > 1)
|
|
{
|
|
toolAndMaterialDic[itemInfo.toolName].Remove(itemInfo);
|
|
}
|
|
else
|
|
{
|
|
toolAndMaterialDic.Remove(itemInfo.toolName);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 移除多个
|
|
/// </summary>
|
|
/// <param name="itemInfo"></param>
|
|
public void RemoveAllToolOrMater(ItemInfo itemInfo)
|
|
{
|
|
if (toolAndMaterialDic.ContainsKey(itemInfo.toolName))
|
|
{
|
|
toolAndMaterialDic.Remove(itemInfo.toolName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清除背包数据
|
|
/// </summary>
|
|
public void ClearAllData()
|
|
{
|
|
wearDic.Clear();
|
|
toolAndMaterialDic.Clear();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 拿出背包所有东西
|
|
/// </summary>
|
|
public void ClearAllToolAndDiveceAndMaterial()
|
|
{
|
|
ClearAllData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加 穿戴 状态 0 去掉 1 穿上
|
|
/// </summary>
|
|
/// <param name="itemInfo"></param>
|
|
/// <param name="state"></param>
|
|
public void WearItemState(ItemInfo itemInfo, bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
if (!wearDic.ContainsKey(itemInfo.toolName))
|
|
wearDic.Add(itemInfo.toolName, itemInfo);
|
|
}
|
|
else
|
|
{
|
|
if (wearDic.ContainsKey(itemInfo.toolName))
|
|
wearDic.Remove(itemInfo.toolName);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 已经穿上
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsWeared(HashSet<string> wears)
|
|
{
|
|
HashSet<string> keys = new HashSet<string>(wearDic.Keys);
|
|
foreach (var str in keys)
|
|
{
|
|
wears.RemoveWhere(key => str.Contains(key));
|
|
}
|
|
return wears.Count == 0;
|
|
}
|
|
|
|
} |