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
8
.idea/.idea.ReisenTasker/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.ReisenTasker/.idea/indexLayout.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
22
Assets/Prefabs/CraftItemTest.asset
Normal file
22
Assets/Prefabs/CraftItemTest.asset
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a100b9e8279440fd88e58bae66ffb885, type: 3}
|
||||
m_Name: CraftItemTest
|
||||
m_EditorClassIdentifier: Assembly-CSharp::Item
|
||||
itemName: Brick
|
||||
description:
|
||||
icon: {fileID: 0}
|
||||
requiredMaterials:
|
||||
- item: {fileID: 11400000, guid: eaef781da6195e1a491978951b17d3b8, type: 2}
|
||||
amount: 1
|
||||
craftedAmount: 1
|
||||
value: 0
|
||||
8
Assets/Prefabs/CraftItemTest.asset.meta
Normal file
8
Assets/Prefabs/CraftItemTest.asset.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b5a9cd50157e32c4a92e98bd9a922076
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -15,3 +15,6 @@ MonoBehaviour:
|
|||
itemName: Water
|
||||
description: h2o
|
||||
icon: {fileID: 0}
|
||||
requiredMaterials: []
|
||||
craftedAmount: 1
|
||||
value: 0
|
||||
|
|
|
|||
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