public void SetItemsDataToListItems(ItemData[] newListItems) { for (int index = 0; index < newListItems.Length; index++) { if (newListItems[index] != null) { Item newItem = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + StringUtil.RemoveWhitespace(newListItems[index].name), typeof(Item));; listItems.Add(newItem); } } }
private void CreateItems(ItemData[] items) { foreach (var item in items) { if (item != null) { GameObject itemObject = (GameObject)Resources.Load($"{RouteUtil.GetPrefabsItems()}ItemPrefab", typeof(GameObject)); itemObject.transform.position = new Vector3(item.position[0], item.position[1], item.position[2]); Debug.Log(item.name); Item newItem = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + StringUtil.RemoveWhitespace(item.name), typeof(Item)); Debug.Log(newItem.icon); itemObject.GetComponent <PickupItem>().SetItem(newItem); itemObject.GetComponent <SpriteRenderer>().sprite = newItem.icon; Instantiate(itemObject); } } }
public void Load(InventoryData data) { for (int index = 0; index < data.items.Length; index++) { slots[index].amount = data.amounts[index]; if (slots[index].amount <= 0) { slots[index].item = null; } else { string itemName = StringUtil.RemoveWhitespace(data.items[index]); slots[index].item = (Item)Resources.Load(RouteUtil.GetPrefabsItems() + itemName, typeof(Item)); slots[index].SetIcon(); slots[index].ShowAmount(); slots[index].ShowIcon(true); } } }