diff --git a/Assets/Scene.unity b/Assets/Scene.unity index a649a38..86b61b0 100644 --- a/Assets/Scene.unity +++ b/Assets/Scene.unity @@ -505,6 +505,141 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ee2fcb6d299019740bbede78bbc6a1d7, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &1404527750 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1404527751} + - component: {fileID: 1404527753} + - component: {fileID: 1404527752} + m_Layer: 0 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!224 &1404527751 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404527750} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1632946789} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 0} + m_AnchorMax: {x: 1, y: 0} + m_AnchoredPosition: {x: -25, y: 15} + m_SizeDelta: {x: 40, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1404527752 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404527750} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_text: 100 + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2100000, guid: 79459efec17a4d00a321bdcc27bbc385, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4294967295 + m_fontColor: {r: 1, g: 1, b: 1, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_StyleSheet: {fileID: 0} + m_TextStyleHashCode: -1183493901 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_fontSize: 18 + m_fontSizeBase: 20 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_HorizontalAlignment: 4 + m_VerticalAlignment: 512 + m_textAlignment: 65535 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_linkedTextComponent: {fileID: 0} + parentLinkedComponent: {fileID: 0} + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_IsTextObjectScaleStatic: 0 + m_VertexBufferAutoSizeReduction: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_hasFontAssetChanged: 0 + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1404527753 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1404527750} + m_CullTransparentMesh: 1 --- !u!1 &1618529780 GameObject: m_ObjectHideFlags: 0 @@ -551,6 +686,29 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1632946788 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1031884711933943707, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + m_PrefabInstance: {fileID: 4215392547039679762} + m_PrefabAsset: {fileID: 0} +--- !u!224 &1632946789 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 2917703646420147887, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + m_PrefabInstance: {fileID: 4215392547039679762} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1632946793 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1632946788} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8e3ae0ca7d3fa0f4cb5a877a7f8183ec, type: 3} + m_Name: + m_EditorClassIdentifier: + index: 0 --- !u!1 &1683721763 GameObject: m_ObjectHideFlags: 0 @@ -707,12 +865,28 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode - value: 1 + value: 3 objectReference: {fileID: 0} + - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Target + value: + objectReference: {fileID: 831773411} - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_CallState value: 2 objectReference: {fileID: 0} + - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName + value: buttonEvent + objectReference: {fileID: 0} + - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName + value: UI_Inventory, Assembly-CSharp + objectReference: {fileID: 0} + - target: {fileID: 2310262034725730047, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} + propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Arguments.m_ObjectArgumentAssemblyTypeName + value: UnityEngine.Object, UnityEngine + objectReference: {fileID: 0} - target: {fileID: 4215392545672552185, guid: ac29b266608f92b419b28a16d8ee7c1b, type: 3} propertyPath: m_IsActive value: 0 diff --git a/Assets/Scripts/ButtonEventHandler.cs b/Assets/Scripts/ButtonEventHandler.cs new file mode 100644 index 0000000..8e3f26e --- /dev/null +++ b/Assets/Scripts/ButtonEventHandler.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ButtonEventHandler : MonoBehaviour +{ + + [SerializeField] UI_Inventory inventory; + +} diff --git a/Assets/Scripts/ButtonEventHandler.cs.meta b/Assets/Scripts/ButtonEventHandler.cs.meta new file mode 100644 index 0000000..8f6bbcb --- /dev/null +++ b/Assets/Scripts/ButtonEventHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 005d6c21020af7e41813cdc4202c886f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Identity.cs b/Assets/Scripts/Identity.cs new file mode 100644 index 0000000..6566834 --- /dev/null +++ b/Assets/Scripts/Identity.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Identity : MonoBehaviour +{ + public int index; +} diff --git a/Assets/Scripts/Identity.cs.meta b/Assets/Scripts/Identity.cs.meta new file mode 100644 index 0000000..98d885e --- /dev/null +++ b/Assets/Scripts/Identity.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8e3ae0ca7d3fa0f4cb5a877a7f8183ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Inventory/Slot.cs b/Assets/Scripts/Inventory/Slot.cs index 4aa7c6f..2a5fe68 100644 --- a/Assets/Scripts/Inventory/Slot.cs +++ b/Assets/Scripts/Inventory/Slot.cs @@ -14,6 +14,7 @@ public class Slot /// [Methods] /// void addItem(int count = 1) /// void removeItem(int count = 1) + /// void clear() /// Item item; @@ -36,5 +37,18 @@ public class Slot { // removes any number of items from the slot will also go negative this.count -= count; - } + } + public void clear() + { + item = null; + count = 0; + } + public Slot copy() + { + Slot slot = new Slot(maxItems); + slot.count = count; + slot.ItemType = ItemType; + + return slot; + } } diff --git a/Assets/Scripts/Inventory/UI_Inventory.cs b/Assets/Scripts/Inventory/UI_Inventory.cs index a22e15c..2172cb8 100644 --- a/Assets/Scripts/Inventory/UI_Inventory.cs +++ b/Assets/Scripts/Inventory/UI_Inventory.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using TMPro; using UnityEngine; using UnityEngine.UI; @@ -8,13 +9,51 @@ public class UI_Inventory : MonoBehaviour Inventory playerInventory; public Transform inventoryContainer; public Transform itemSlotTemplate; + private RectTransform[] UIItemSlots; + private Button[] buttons; + private Slot pickedItem = new Slot(); + private RectTransform pickedItemSlot; private void Awake() { //itemSlotTemplate = inventoryContainer.Find("containerTemplate"); + pickedItemSlot = Instantiate(itemSlotTemplate, this.transform).GetComponent(); + } + + void pickItem(int index) + { + pickedItem = playerInventory.getInventory[index].copy(); + playerInventory.getInventory[index].clear(); + UIItemSlots[index].GetChild(0).Find("Icon").gameObject.SetActive(false); + } + void placeItem() + { + } public void buttonEvent(int index) { - Debug.Log("yeet"); + if (pickedItem.ItemType == null && playerInventory.getInventory[index].ItemType != null) + { + pickItem(index); + } + else + { + if (pickedItem.ItemType != null) + { + int rest = playerInventory.addItemAt(index, pickedItem.ItemType, pickedItem.Count); + if (rest == 0) + { + pickedItem.clear(); + } + else + { + pickedItem.Count = rest; + } + //placeItem(index); + } + + } + + //Debug.Log("button " + index + " has been pressed!"); } public void setInventory(Inventory inventory) { @@ -22,6 +61,27 @@ public class UI_Inventory : MonoBehaviour inventory.onItemChangedCallback += updateInventory; updateInventory(); } + private void Update() + { + //buttons[index] = itemSlotRectTransform.Find("Button").GetComponent