using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 负责工具材料包管理 /// public class PacksackBagMgr : BaseManager { /// /// 背包里所有东西 /// private Dictionary> toolAndMaterialDic = new Dictionary>(); /// /// 已经穿戴 /// public Dictionary wearDic = new Dictionary(); private PacksackBagMgr() { } public Dictionary> GetCurrentBagData() { return toolAndMaterialDic; } /// /// 添加一个工器具或材料 /// /// public void AddOneToolOrMater(ItemInfo itemInfo) { if (toolAndMaterialDic.ContainsKey(itemInfo.toolName)) { toolAndMaterialDic[itemInfo.toolName].Add(itemInfo); } else { toolAndMaterialDic.Add(itemInfo.toolName, new List() { itemInfo }); } } public Dictionary> GetItemsByE_TMDType(E_ToolOrDeviceOrMaterials tmdTpye) { Dictionary> tempNew = new Dictionary>(); 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() { dicTemp[item][i] }); } } } } return tempNew; } /// /// 移除一个工器具或材料 /// /// 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); } } } /// /// 移除多个 /// /// public void RemoveAllToolOrMater(ItemInfo itemInfo) { if (toolAndMaterialDic.ContainsKey(itemInfo.toolName)) { toolAndMaterialDic.Remove(itemInfo.toolName); } } /// /// 清除背包数据 /// public void ClearAllData() { wearDic.Clear(); toolAndMaterialDic.Clear(); } /// /// 拿出背包所有东西 /// public void ClearAllToolAndDiveceAndMaterial() { foreach (var item in toolAndMaterialDic.Keys) { List temp = toolAndMaterialDic[item]; for (int j = 0; j < temp.Count; j++) { int indexJ = j; GameObject obj = GameObject.Instantiate(temp[indexJ].objPrefab); obj.name = temp[indexJ].toolName; obj.transform.position = temp[indexJ].selfPosInToolRoom; obj.GetComponent().itemInfo = temp[indexJ]; obj.GetComponent().GetInfo(); } } ClearAllData(); } /// /// 添加 穿戴 状态 0 去掉 1 穿上 /// /// /// 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); } } }