public CraftingSlotContentItem GetMapItemById(int id) { CraftingSlotContentItem temp = null; contentItemDic.TryGetValue(id, out temp); return(temp); }
/// <summary> /// 填充合成槽 /// </summary> private void CreateSlotContent(int id) { CraftingSlotContentItem tempItem = m_Model.GetMapItemById(id); if (tempItem != null) { /// 重置合成槽 ResetSlot(); ResetSlotItem(); /// 改变合成目标UI Sprite temp = m_View.GetCraftingItemSpriteByName(tempItem.MapName); m_View.Right_Transform.GetComponent <CraftingController>().SetCraftingContentSprite(tempItem.MapId, temp, tempItem.HaveBar); materialsCount = tempItem.MaterialsCount; /// 改变合成槽UI for (int i = 0; i < slotNum; i++) { if (tempItem.MapContents[i] != "0") { Sprite target = m_View.GetSlotSpriteByName(tempItem.MapContents[i]); int itemId = int.Parse(tempItem.MapContents[i]); slotList[i].GetComponent <CraftingSlotController>().SetSlotItemUI(itemId, target); slotList[i].GetComponent <CanvasGroup>().blocksRaycasts = true; } else { slotList[i].GetComponent <CanvasGroup>().blocksRaycasts = false; } } } else { for (int i = 0; i < slotNum; i++) { slotList[i].GetComponent <CanvasGroup>().blocksRaycasts = false; } } }
/// <summary> /// 预加载合成槽的数据 /// </summary> /// <param name="name"></param> /// <returns></returns> private Dictionary <int, CraftingSlotContentItem> LoadContentItemDic(string name) { Dictionary <int, CraftingSlotContentItem> temp = new Dictionary <int, CraftingSlotContentItem>(); string str = Resources.Load <TextAsset>("Json/" + name).text; JsonData jsonData = JsonMapper.ToObject(str); for (int j = 0; j < jsonData.Count; j++) { JsonData jd = jsonData[j]["Type"]; for (int i = 0; i < jd.Count; i++) { int id = int.Parse(jd[i]["MapId"].ToString()); string content = jd[i]["MapContents"].ToString(); string[] contents = content.Split(','); int count = int.Parse(jd[i]["MaterialsCount"].ToString()); string mapName = jd[i]["MapName"].ToString(); int haveBar = int.Parse(jd[i]["HaveBar"].ToString()); CraftingSlotContentItem tempItem = new CraftingSlotContentItem(id, contents, count, mapName, haveBar); temp.Add(id, tempItem); } } return(temp); }