did i really spend less than an hour working on this game over the course of an entire week? yes!
This commit is contained in:
parent
b842289076
commit
4a80a6ed0f
10 changed files with 113 additions and 1 deletions
26
Assets/Scripts/Inventory/CraftableUIObject.cs
Normal file
26
Assets/Scripts/Inventory/CraftableUIObject.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CraftableUIObject : MonoBehaviour
|
||||
{
|
||||
public CraftingRequirementUIObject templateRequirementUI;
|
||||
public Transform requirementGrid;
|
||||
public TextMeshProUGUI itemNameText;
|
||||
public TextMeshProUGUI amountText;
|
||||
public Image itemIcon;
|
||||
public Button thisButton;
|
||||
|
||||
public void SetObject(Item itemToSet)
|
||||
{
|
||||
itemNameText.text = itemToSet.itemName; //it would be reset every time you open the inventory instead of updating only the amount but whatever it doesn't matter
|
||||
amountText.text = $"x{itemToSet.craftedAmount}";
|
||||
itemIcon.sprite = itemToSet.icon;
|
||||
thisButton.onClick.AddListener(() => CraftingSystem.instance.TryCraftingItem(itemToSet));
|
||||
foreach (InventoryManager.ItemAmount craftingRequirement in itemToSet.requiredMaterials)
|
||||
{
|
||||
CraftingRequirementUIObject newRequirementUI = Instantiate(templateRequirementUI, requirementGrid);
|
||||
newRequirementUI.SetObject(craftingRequirement.item, craftingRequirement.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Inventory/CraftableUIObject.cs.meta
Normal file
2
Assets/Scripts/Inventory/CraftableUIObject.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b47ad7db89fd76e5fadca9361869604b
|
||||
15
Assets/Scripts/Inventory/CraftingRequirementUIObject.cs
Normal file
15
Assets/Scripts/Inventory/CraftingRequirementUIObject.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CraftingRequirementUIObject : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI amountText;
|
||||
public Image itemIcon;
|
||||
|
||||
public void SetObject(Item itemToSet, int amount)
|
||||
{
|
||||
amountText.text = amount.ToString();
|
||||
itemIcon.sprite = itemToSet.icon;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09e8634b1083a0ce1a9877c5e26b29bf
|
||||
|
|
@ -1,8 +1,35 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class CraftingSystem : MonoBehaviour
|
||||
{
|
||||
#region Statication
|
||||
|
||||
public static CraftingSystem instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (instance != null && instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(this);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
public List<Item> knownCraftables = new();
|
||||
[Header("UI")]
|
||||
public Transform craftableUIGrid;
|
||||
public CraftableUIObject templateCraftButton;
|
||||
public void UpdateKnownCraftables(Item newCraftable)
|
||||
{
|
||||
knownCraftables.Add(newCraftable);
|
||||
CraftableUIObject newButton = Instantiate(templateCraftButton, craftableUIGrid);
|
||||
newButton.SetObject(newCraftable);
|
||||
}
|
||||
public bool TryCraftingItem(Item requestedItem)
|
||||
{
|
||||
List<InventoryManager.ItemAmount> missingItems = new();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ public class InventoryUIObject : MonoBehaviour
|
|||
|
||||
public void SetObject(Item itemToSet)
|
||||
{
|
||||
Debug.Log("here");
|
||||
itemNameText.text = itemToSet.itemName; //it would be reset every time you open the inventory instead of updating only the amount but whatever it doesn't matter
|
||||
amountText.text = $"x{InventoryManager.instance.CheckItemAmount(itemToSet)}";
|
||||
itemIcon.sprite = itemToSet.icon;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue