Merged
This commit is contained in:
@@ -15,15 +15,31 @@ public class InventoryItem : ScriptableObject
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public class InventoryEntry{
|
||||
public class InventoryEntry
|
||||
{
|
||||
public string Item;
|
||||
public int Count;
|
||||
public InventoryEntry(string item, int count){
|
||||
public InventoryEntry(string item, int count)
|
||||
{
|
||||
Item = item;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Inventory{
|
||||
|
||||
public static class Inventory
|
||||
{
|
||||
public static InventoryItem GetInventoryItem(string itemName)
|
||||
{
|
||||
Object[] shopItems = Resources.LoadAll("ScriptableObjects/ShopItems");
|
||||
Debug.Log("Searching thru " + shopItems.Length + " SOs");
|
||||
foreach (Object itemObj in shopItems)
|
||||
{
|
||||
InventoryItem item = itemObj as InventoryItem;
|
||||
if (item.itemName == itemName)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ public class SellMenu : MonoBehaviour
|
||||
public int gemsAmount;
|
||||
public int oxygenAmount;
|
||||
public int metalAmount;
|
||||
public Image selectedItemImg;
|
||||
void Start()
|
||||
{
|
||||
Refresh();
|
||||
@@ -50,9 +51,17 @@ public class SellMenu : MonoBehaviour
|
||||
|
||||
for(int i =0; i < inventorySlots.Length; i++){
|
||||
if(i < DBmanager.Inventory.Count){
|
||||
inventorySlots[i].GetComponent<Image>().sprite =emptySlotImage;
|
||||
InventoryItem itemData = Inventory.GetInventoryItem(DBmanager.Inventory[i].Item);
|
||||
if(itemData==null){
|
||||
Debug.LogError("Couldn't find data for " + DBmanager.Inventory[i].Item);
|
||||
}
|
||||
inventorySlots[i].transform.GetChild(0).GetComponent<Image>().sprite = itemData.image;
|
||||
inventorySlots[i].interactable=true;
|
||||
inventorySlots[i].onClick.RemoveAllListeners();
|
||||
inventorySlots[i].onClick.AddListener(()=>{selectInventoryItem(itemData);});
|
||||
}else{
|
||||
inventorySlots[i].GetComponent<Image>().sprite = emptySlotImage;
|
||||
inventorySlots[i].transform.GetChild(0).GetComponent<Image>().sprite = emptySlotImage;
|
||||
inventorySlots[i].interactable=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,4 +81,7 @@ public class SellMenu : MonoBehaviour
|
||||
// selected
|
||||
Refresh();
|
||||
}
|
||||
public void selectInventoryItem(InventoryItem item){
|
||||
selectedItemImg.sprite = item.image;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user