using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Inventory : MonoBehaviour
{
public List<ItemInventory> items = new List<ItemInventory>();
public GameObject gameObjectShow;
public GameObject InventoryObject;
public int maxCount;
public DataBase data;
public void AddItem(int id, Item item, int count)
{
items[id].id = item.id;
items[id].count = count;
items[id].itemGameObject.GetComponent<Image>().sprite = item.image;
if(count > 1 && item.id != 0)
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = count.ToString();
}
else
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = "";
}
}
public void AddInventoryItem(int id, ItemInventory invItem)
{
items[id].id = invItem.id;
items[id].count = invItem.count;
items[id].itemGameObject.GetComponent<Image>().sprite = data.items[invItem.id].spr;
if (invItem.count > 1 && invItem.id != 0)
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = invItem.count.ToString();
}
else
{
items[id].itemGameObject.GetComponentInChildren<Text>().text = "";
}
}
public void AddGraphics()
{
for(int i = 0; i < maxCount; i++)
{
GameObject newItem = Instantiate(gameObjectShow, InventoryObject.transform) as GameObject;
newItem.name = i.ToString();
ItemInventory ii = new ItemInventory();
ii.itemGameObject = newItem;
RectTransform rt = newItem.GetComponent<RectTransform>();
rt.localPosition = new Vector3(0, 0, 0);
rt.localScale = new Vector3(1, 1, 1);
newItem.GetComponentInChildren<RectTransform>().localScale = new Vector3(1, 1, 1);
Button tempButton = newItem.GetComponent<Button>();
items.Add(ii);
}
}
}
[System.Serializable]
public class ItemInventory
{
public int id;
public GameObject itemGameObject;
public int count;
}