public void StoreItem(int ID) { if (!ItemDictionary.ContainsKey(ID)) { return; } else { Item temp = ItemDictionary[ID]; if (temp != null) { if (ItemData.ContainItem(temp.Name)) { ItemData.AddItem(temp.Name); GridPanel.instance.GetExistItem(temp.Name).GetChild(0).GetChild(2).GetComponent <Text>().text = temp.Count.ToString(); ItemData.SaveData(temp.Name, temp); } else { Transform parent = GridPanel.instance.GetEmptyGrid(); if (parent == null) { ///TO: Debug.Log("背包装满!"); return; } else { CreateItem(temp, parent); } } } } }
void CreateItem(Item item, Transform parent) { GameObject newItem = Resources.Load("grid") as GameObject; if (item.Count != 1) { item.Count = 1; } if (newItem.GetComponent <UIItem>() != null) { newItem.GetComponent <UIItem>().SetName(item.Name); newItem.GetComponent <UIItem>().SetCount(item.Count.ToString()); newItem.GetComponent <UIItem>().SetImage(item.Picture); } GameObject.Instantiate(newItem, parent); ItemData.SaveData(item.Name, item); }