From 00d02ca2acaa04b871988da3dc2d871f2230af70 Mon Sep 17 00:00:00 2001 From: kabix09 Date: Sun, 29 May 2022 21:54:28 +0200 Subject: [PATCH] Add chest Drag & Drop --- Assembly-CSharp.csproj | 7 +- Assets/Items/Pickaxe.asset | 12 +- Assets/Items/Pickaxe.asset.meta | 2 +- Assets/Prefarbs/Chest/DraggableItem.prefab | 77 ++++++++ .../Prefarbs/Chest/DraggableItem.prefab.meta | 7 + Assets/Prefarbs/Chest/chest_panel.prefab | 7 +- .../Prefarbs/Chest/chest_slot Variant.prefab | 146 +++++++++++++++ .../Chest/chest_slot Variant.prefab.meta | 7 + Assets/Prefarbs/Item.meta | 8 + .../item_slot.prefab} | 11 +- .../item_slot.prefab.meta} | 0 Assets/Scenes/SampleScene.unity | 18 +- Assets/Scripts/Chest/ChestPanelController.cs | 173 ++++++++++++++++-- Assets/Scripts/Chest/ChestSlot.cs | 20 ++ Assets/Scripts/Chest/ChestSlot.cs.meta | 11 ++ Assets/Scripts/DragDropItemManager.cs | 8 + Assets/Scripts/DragDropItemManager.cs.meta | 11 ++ Assets/Scripts/Equipment.meta | 8 + Assets/Scripts/Inventory/InventoryManager.cs | 4 +- Assets/Scripts/Inventory/InventorySlot.cs | 67 +------ .../Scripts/Inventory/InventorySlot.cs.meta | 2 +- Assets/Scripts/Item/EquippableItem.cs | 33 ++++ Assets/Scripts/Item/EquippableItem.cs.meta | 11 ++ Assets/Scripts/Item/ItemSlot.cs | 136 ++++++++++++++ Assets/Scripts/Item/ItemSlot.cs.meta | 11 ++ Assets/Scripts/Item/PickableController.cs | 2 +- Assets/Scripts/Objects' Scripts/Chest.cs | 18 +- 27 files changed, 715 insertions(+), 102 deletions(-) create mode 100644 Assets/Prefarbs/Chest/DraggableItem.prefab create mode 100644 Assets/Prefarbs/Chest/DraggableItem.prefab.meta create mode 100644 Assets/Prefarbs/Chest/chest_slot Variant.prefab create mode 100644 Assets/Prefarbs/Chest/chest_slot Variant.prefab.meta create mode 100644 Assets/Prefarbs/Item.meta rename Assets/Prefarbs/{Inventory UI/inventory_slot.prefab => Item/item_slot.prefab} (98%) rename Assets/Prefarbs/{Inventory UI/inventory_slot.prefab.meta => Item/item_slot.prefab.meta} (100%) create mode 100644 Assets/Scripts/Chest/ChestSlot.cs create mode 100644 Assets/Scripts/Chest/ChestSlot.cs.meta create mode 100644 Assets/Scripts/DragDropItemManager.cs create mode 100644 Assets/Scripts/DragDropItemManager.cs.meta create mode 100644 Assets/Scripts/Equipment.meta create mode 100644 Assets/Scripts/Item/EquippableItem.cs create mode 100644 Assets/Scripts/Item/EquippableItem.cs.meta create mode 100644 Assets/Scripts/Item/ItemSlot.cs create mode 100644 Assets/Scripts/Item/ItemSlot.cs.meta diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 97fd171a..9acba8fe 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -49,15 +49,20 @@ + + - + + + + diff --git a/Assets/Items/Pickaxe.asset b/Assets/Items/Pickaxe.asset index 5b701595..c99736e4 100644 --- a/Assets/Items/Pickaxe.asset +++ b/Assets/Items/Pickaxe.asset @@ -9,12 +9,18 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3d5bd84ad69269f4e8a3c4ec655119d5, type: 3} + m_Script: {fileID: 11500000, guid: 943bb4b7c1123c44fb1cbc048a56a954, type: 3} m_Name: Pickaxe m_EditorClassIdentifier: id: 0 - name: Pickaxe1 + name: Pickaxe description: Example pickaxe - level: 5 + level: 1 image: {fileID: 8959118705387878318, guid: 25e473b59d2d7534e803be0a2825e0f7, type: 3} itemModel: {fileID: 9081071845930167562, guid: 0bccd32818043074d9785f6d90ebdcb3, type: 3} + StrengthBonus: 0 + AgilityBonus: 0 + InteligenceBonus: 0 + VitalityBonus: 0 + isStackable: 0 + EquipmentType: 0 diff --git a/Assets/Items/Pickaxe.asset.meta b/Assets/Items/Pickaxe.asset.meta index 47a4dcf5..816aa7c2 100644 --- a/Assets/Items/Pickaxe.asset.meta +++ b/Assets/Items/Pickaxe.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: aaa7c520aded1bc42a26b7ce43484010 +guid: 5935777f7ac390a4187e03f34e7cafdd NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Prefarbs/Chest/DraggableItem.prefab b/Assets/Prefarbs/Chest/DraggableItem.prefab new file mode 100644 index 00000000..5721d7b2 --- /dev/null +++ b/Assets/Prefarbs/Chest/DraggableItem.prefab @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &8309540737472051965 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2656595206807813241} + - component: {fileID: 1530012061426163413} + - component: {fileID: 6570396142606985298} + m_Layer: 5 + m_Name: DraggableItem + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2656595206807813241 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8309540737472051965} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.4, y: 0.4, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 868.10376, y: 556.62885} + m_SizeDelta: {x: 60, y: 60} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!222 &1530012061426163413 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8309540737472051965} + m_CullTransparentMesh: 1 +--- !u!114 &6570396142606985298 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8309540737472051965} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 0 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 8959118705387878318, guid: 25e473b59d2d7534e803be0a2825e0f7, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 diff --git a/Assets/Prefarbs/Chest/DraggableItem.prefab.meta b/Assets/Prefarbs/Chest/DraggableItem.prefab.meta new file mode 100644 index 00000000..7e3e02f6 --- /dev/null +++ b/Assets/Prefarbs/Chest/DraggableItem.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1304511dd1dfefc449e87c3d904ab15f +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefarbs/Chest/chest_panel.prefab b/Assets/Prefarbs/Chest/chest_panel.prefab index fc60619c..141365d2 100644 --- a/Assets/Prefarbs/Chest/chest_panel.prefab +++ b/Assets/Prefarbs/Chest/chest_panel.prefab @@ -181,11 +181,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8d9e1061a8038f54a87269aa0bd2db04, type: 3} m_Name: m_EditorClassIdentifier: - blankChestSlot: {fileID: 2195907289659811253, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + chest: {fileID: 0} chestPanel: {fileID: 5331092056807707114} chestPanelCloseButton: {fileID: 5331092055143140112} - chest: {fileID: 0} - content: [] + blankChestSlot: {fileID: 7205046634468616427, guid: 5239ba2d7bc1aa64e90b3f8b87342137, type: 3} + draggableItem: {fileID: 6570396142606985298, guid: 1304511dd1dfefc449e87c3d904ab15f, type: 3} + _tmp: {fileID: 0} --- !u!1 &5331092055037629064 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefarbs/Chest/chest_slot Variant.prefab b/Assets/Prefarbs/Chest/chest_slot Variant.prefab new file mode 100644 index 00000000..d639bdeb --- /dev/null +++ b/Assets/Prefarbs/Chest/chest_slot Variant.prefab @@ -0,0 +1,146 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1001 &9044382224672951646 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_Pivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_Pivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_RootOrder + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchorMax.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchorMax.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchorMin.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchorMin.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_SizeDelta.x + value: 60 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_SizeDelta.y + value: 60 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchoredPosition.x + value: 55 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_AnchoredPosition.y + value: -55 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811252, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2195907289659811253, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + propertyPath: m_Name + value: chest_slot Variant + objectReference: {fileID: 0} + m_RemovedComponents: + - {fileID: 528788604, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + m_SourcePrefab: {fileID: 100100000, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} +--- !u!1 &7205046634468616427 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2195907289659811253, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + m_PrefabInstance: {fileID: 9044382224672951646} + m_PrefabAsset: {fileID: 0} +--- !u!114 &7205046633677332703 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 2195907289327283585, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + m_PrefabInstance: {fileID: 9044382224672951646} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &7205046633485490645 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 2195907290760729739, guid: 39c7a9aabb5a44f48a2e23af5fbf5e1f, type: 3} + m_PrefabInstance: {fileID: 9044382224672951646} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 0 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &8978507043308548768 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7205046634468616427} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2be16a7ceddcd2141ba1db1636539117, type: 3} + m_Name: + m_EditorClassIdentifier: + slotItemNumberText: {fileID: 7205046633485490645} + itemImage: {fileID: 7205046633677332703} + chestPanelController: {fileID: 5331092055018478729, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} + _number: 0 + _item: {fileID: 0} + countStackableItems: 0 + EquipmentType: 5 diff --git a/Assets/Prefarbs/Chest/chest_slot Variant.prefab.meta b/Assets/Prefarbs/Chest/chest_slot Variant.prefab.meta new file mode 100644 index 00000000..340b97db --- /dev/null +++ b/Assets/Prefarbs/Chest/chest_slot Variant.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 5239ba2d7bc1aa64e90b3f8b87342137 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefarbs/Item.meta b/Assets/Prefarbs/Item.meta new file mode 100644 index 00000000..8beebdb7 --- /dev/null +++ b/Assets/Prefarbs/Item.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ad5d982f550477a4b8b8be4ad2988ec2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab b/Assets/Prefarbs/Item/item_slot.prefab similarity index 98% rename from Assets/Prefarbs/Inventory UI/inventory_slot.prefab rename to Assets/Prefarbs/Item/item_slot.prefab index f0dcbafa..875439aa 100644 --- a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab +++ b/Assets/Prefarbs/Item/item_slot.prefab @@ -52,13 +52,13 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2195907289327283599} - m_Enabled: 0 + m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Color: {r: 1, g: 1, b: 1, a: 0} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 @@ -89,7 +89,7 @@ GameObject: - component: {fileID: 5542991846752721897} - component: {fileID: 528788604} m_Layer: 5 - m_Name: inventory_slot + m_Name: item_slot m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -211,10 +211,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: slotItemNumberText: {fileID: 2195907290760729739} - slotImage: {fileID: 2195907289327283585} - item: {fileID: 0} - countStackableItems: 0 + itemImage: {fileID: 2195907289327283585} chestPanelController: {fileID: 5331092055018478729, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} + countStackableItems: 0 --- !u!1 &2195907290760729737 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefarbs/Inventory UI/inventory_slot.prefab.meta b/Assets/Prefarbs/Item/item_slot.prefab.meta similarity index 100% rename from Assets/Prefarbs/Inventory UI/inventory_slot.prefab.meta rename to Assets/Prefarbs/Item/item_slot.prefab.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 1bac6589..36e820cb 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -793,7 +793,7 @@ MonoBehaviour: m_EditorClassIdentifier: chest: {fileID: 0} chestPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - itemsList: [] + developerList: [] --- !u!1 &163167163 GameObject: m_ObjectHideFlags: 0 @@ -1054,7 +1054,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 167690937} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: -22.1, y: 17.8, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -2592,7 +2592,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c261410eee3e5d640abd23159c28b3cc, type: 3} m_Name: m_EditorClassIdentifier: - item: {fileID: 11400000, guid: aaa7c520aded1bc42a26b7ce43484010, type: 2} + item: {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2} --- !u!50 &622865438 Rigidbody2D: serializedVersion: 4 @@ -12824,8 +12824,10 @@ MonoBehaviour: m_EditorClassIdentifier: chest: {fileID: 0} chestPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - itemsList: - - {fileID: 11400000, guid: aaa7c520aded1bc42a26b7ce43484010, type: 2} + developerList: + - {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2} + - {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2} + - {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2} --- !u!61 &926459326 BoxCollider2D: m_ObjectHideFlags: 0 @@ -13072,7 +13074,7 @@ MonoBehaviour: m_EditorClassIdentifier: chest: {fileID: 0} chestPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - itemsList: [] + developerList: [] --- !u!1 &1058265261 GameObject: m_ObjectHideFlags: 0 @@ -13496,7 +13498,7 @@ MonoBehaviour: m_EditorClassIdentifier: chest: {fileID: 0} chestPanel: {fileID: 5331092055018478733, guid: 2b46aee216d4b304f8aebcb303ebf4f4, type: 3} - itemsList: [] + developerList: [] --- !u!1 &1315339608 GameObject: m_ObjectHideFlags: 0 @@ -105408,7 +105410,7 @@ PrefabInstance: - target: {fileID: 9081071845930167553, guid: 0bccd32818043074d9785f6d90ebdcb3, type: 3} propertyPath: item value: - objectReference: {fileID: 11400000, guid: aaa7c520aded1bc42a26b7ce43484010, type: 2} + objectReference: {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2} - target: {fileID: 9081071845930167553, guid: 0bccd32818043074d9785f6d90ebdcb3, type: 3} propertyPath: item.itemModel value: diff --git a/Assets/Scripts/Chest/ChestPanelController.cs b/Assets/Scripts/Chest/ChestPanelController.cs index acc735d8..848bb71e 100644 --- a/Assets/Scripts/Chest/ChestPanelController.cs +++ b/Assets/Scripts/Chest/ChestPanelController.cs @@ -2,26 +2,37 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; +using UnityEngine.EventSystems; +using System; public class ChestPanelController : MonoBehaviour { - [Header("Inventory Information")] - [SerializeField] private GameObject blankChestSlot; + [Header("Chest Information")] + [SerializeField] private GameObject chest; // chest to which the panel belongs [SerializeField] private GameObject chestPanel; [SerializeField] private Button chestPanelCloseButton; + [Space] + [SerializeField] private GameObject blankChestSlot; + + [SerializeField] public Image draggableItem; + [SerializeField] private Image _tmp; + private ItemSlot draggedSlot; - [SerializeField] private GameObject chest; // chest to which the panel belongs [SerializeField] public const int MAX_SLOT_CUNT = 6*8; + [Space] + public List itemSlots = new List(); - public List content = new List(); + public event Action OnBeginDragEvent; + public event Action OnEndDragEvent; + public event Action OnDragEvent; + public event Action OnDropEvent; void Awake() { InitInventorySlots(); } - // Start is called before the first frame update void Start() { if(chestPanelCloseButton) @@ -30,7 +41,6 @@ public class ChestPanelController : MonoBehaviour } } - // Update is called once per frame void Update() { } @@ -51,27 +61,162 @@ public class ChestPanelController : MonoBehaviour { for(int i = 0; i < MAX_SLOT_CUNT; i++) { - InventorySlot newSlot = Instantiate(blankChestSlot, chestPanel.transform.position, Quaternion.identity).GetComponent(); + ChestSlot newSlot = Instantiate(blankChestSlot, chestPanel.transform.position, Quaternion.identity).GetComponent(); newSlot.transform.SetParent(chestPanel.transform); - newSlot.SetupInventorySlot(null, this); - content.Add(newSlot); + + newSlot.SetupInventorySlot(i, null, this); + + // Set new Slot instance + itemSlots.Add(newSlot); + + // Assign events + itemSlots[i].OnBeginDragEvent += BeginDrag; + itemSlots[i].OnEndDragEvent +=EndDrag; + itemSlots[i].OnDragEvent += Drag; + itemSlots[i].OnDropEvent += Drop; } } } - public void SetupChest(GameObject _chest, List _chestItems) + public void SetupChest(GameObject _chest, Dictionary _chestItems) { chest = _chest; SetPanelItems(_chestItems); } - private void SetPanelItems(List _itemsList) - { - for(int i=0; i < _itemsList.Count; i++) + private void SetPanelItems(Dictionary _itemsList) + { + foreach(int key in _itemsList.Keys) { - content[i].SetItem(_itemsList[i]); + itemSlots[key].SetItem(_itemsList[key]); + } + } + + public bool AddItem(Item _item) + { + for(int i = 0; i < itemSlots.Count; i++) + { + if(itemSlots[i].Item == null) + { + itemSlots[i].Item = _item; + return true; + } + } + return false; + } + + public bool RemoveItem(Item _item) + { + for(int i = 0; i < itemSlots.Count; i++) + { + if(itemSlots[i].Item == _item) + { + itemSlots[i].Item = null; + return true; + } + } + return false; + } + + public bool IsFull() + { + for(int i = 0; i < itemSlots.Count; i++) + { + if(itemSlots[i].Item == null) + { + return false; + } + } + return true; + } + + private void MakeDraggableItem(ItemSlot itemSlot) + { + if(_tmp) + { + _tmp.enabled = true; + + return; + } + + GameObject globalGUI = GameObject.FindGameObjectsWithTag("GUI")[0]; + + if(globalGUI) + { + _tmp = Instantiate(draggableItem, draggableItem.transform.position, Quaternion.identity, globalGUI.transform); + _tmp.transform.localPosition = chestPanel.transform.position; + _tmp.sprite = itemSlot.Item.Image; + _tmp.transform.position = Input.mousePosition; + _tmp.enabled = true; + } else { + Debug.Log("Can't find global GUI object!!!"); } } + + public void BeginDrag(ItemSlot itemSlot) + { + if(itemSlot.Item != null) + { + draggedSlot = itemSlot; + + MakeDraggableItem(itemSlot); + } + } + + public void EndDrag(ItemSlot itemSlot) + { + draggedSlot = null; + + DestroyImmediate(_tmp.gameObject, true); + } + + public void Drag(ItemSlot itemSlot) + { + _tmp.transform.position = Input.mousePosition; + } + + public void Drop(ItemSlot dropItemSlot) + { + if(dropItemSlot.CanReceiveItem(draggedSlot.Item) && draggedSlot.CanReceiveItem(dropItemSlot.Item)) + { + EquippableItem dragItem = draggedSlot.Item as EquippableItem; + EquippableItem dropItem = dropItemSlot.Item as EquippableItem; + + // for changing chest to evuuipment or onventory panel !!!! + + // if(draggedSlot is EquipmentSlot) + // { + // if(dragItem != null) dragItem.Unequip(this); + // if(dropItem != null) dropItem.Equip(this); + // } + + // if(dropItemSlot is EquipmentSlot) + // { + // if(dragItem != null) dragItem.Equip(this); + // if(dropItem != null) dropItem.Unequip(this); + // } + + Item draggedItem = draggedSlot.Item; // remember temporary currently dragged item + + draggedSlot.Item = dropItemSlot.Item; + dropItemSlot.Item = draggedItem; + + // update items position in chest slots + // - after close paned - items dont reset its positions + chest.GetComponent().SetItemOnPosition(draggedSlot.Number, draggedSlot.Item); + chest.GetComponent().SetItemOnPosition(dropItemSlot.Number, dropItemSlot.Item); + } + } + + // --------------------------- + // will work differently depending if its chest, inventory or equipment panel + // public void Equip(EquippableItem item) + // { + // if(RemoveItem(item)) + // { + // EquippableItem previousItem; + // } + // } } diff --git a/Assets/Scripts/Chest/ChestSlot.cs b/Assets/Scripts/Chest/ChestSlot.cs new file mode 100644 index 00000000..b3fab047 --- /dev/null +++ b/Assets/Scripts/Chest/ChestSlot.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class ChestSlot : ItemSlot +{ + public override bool CanReceiveItem(Item item) + { + return true; + + // // allow to put item only when slot is empty + // if(Item == null) + // return true; + + // EquippableItem equippableItem = item as EquippableItem; + // return equippableItem == null; + // // what when player try drop putted equipment fowart to chest + // // what when player try put item on unempty field + } +} diff --git a/Assets/Scripts/Chest/ChestSlot.cs.meta b/Assets/Scripts/Chest/ChestSlot.cs.meta new file mode 100644 index 00000000..1e357501 --- /dev/null +++ b/Assets/Scripts/Chest/ChestSlot.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2be16a7ceddcd2141ba1db1636539117 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DragDropItemManager.cs b/Assets/Scripts/DragDropItemManager.cs new file mode 100644 index 00000000..1db99778 --- /dev/null +++ b/Assets/Scripts/DragDropItemManager.cs @@ -0,0 +1,8 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DragDropItemManager : MonoBehaviour +{ + +} diff --git a/Assets/Scripts/DragDropItemManager.cs.meta b/Assets/Scripts/DragDropItemManager.cs.meta new file mode 100644 index 00000000..3822e27b --- /dev/null +++ b/Assets/Scripts/DragDropItemManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a6334ce379c25c458826dcd25b5e1ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Equipment.meta b/Assets/Scripts/Equipment.meta new file mode 100644 index 00000000..4720d441 --- /dev/null +++ b/Assets/Scripts/Equipment.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4e66e807c2717ee45923ec12b22309d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Inventory/InventoryManager.cs b/Assets/Scripts/Inventory/InventoryManager.cs index ae9d6ab4..e25f4ca9 100644 --- a/Assets/Scripts/Inventory/InventoryManager.cs +++ b/Assets/Scripts/Inventory/InventoryManager.cs @@ -8,7 +8,7 @@ public class InventoryManager : MonoBehaviour public static int MAX_ITEMS = 5; public static InventoryManager Instance; - public List items = new List(); + public List items = new List(); private void Awake() { @@ -21,7 +21,7 @@ public class InventoryManager : MonoBehaviour } } - public void AddToInventory(Item pickable) + public void AddToInventory(EquippableItem pickable) { if(this.items.Count <= MAX_ITEMS) { diff --git a/Assets/Scripts/Inventory/InventorySlot.cs b/Assets/Scripts/Inventory/InventorySlot.cs index 8b119c69..8f9e6541 100644 --- a/Assets/Scripts/Inventory/InventorySlot.cs +++ b/Assets/Scripts/Inventory/InventorySlot.cs @@ -1,71 +1,16 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using TMPro; -using UnityEngine.UI; -public class InventorySlot : MonoBehaviour +public class InventorySlot : ItemSlot { - [Header("UI Stuff to change")] - [SerializeField] private TextMeshProUGUI slotItemNumberText; - [SerializeField] private Image slotImage; - - [Header("Item variable")] - public Item item; - public int countStackableItems = 0; - - public ChestPanelController chestPanelController; - - public void SetupInventorySlot(Item _item, ChestPanelController _chestPanelController) + public override bool CanReceiveItem(Item item) { - chestPanelController = _chestPanelController; + if(Item == null) + return true; - if(_item) - { - SetItem(_item); - } + EquippableItem equippableItem = item as EquippableItem; + return equippableItem != null; } - public void SetItem(Item _item) - { - item = _item; - - ChangeEnableImageView(true); - - slotImage.sprite = _item.Image; - countStackableItems +=1; - - UpdateItemNumberHolder(); - } - - - private void ChangeEnableImageView(bool _flag) - { - slotImage.enabled = _flag; //!slotImage.enabled; - } - - private void ChangeNumberHeldView(bool _flag) - { - slotItemNumberText.enabled = _flag; - } - - private void UpdateItemNumberHolder() - { - slotItemNumberText.text = "" + countStackableItems; - } - - // Start is called before the first frame update - void Start() - { - if(!item) - { - ChangeEnableImageView(false); - ChangeNumberHeldView(false); - } - } - - // Update is called once per frame - void Update() - { - } } diff --git a/Assets/Scripts/Inventory/InventorySlot.cs.meta b/Assets/Scripts/Inventory/InventorySlot.cs.meta index e55da581..fa7dda49 100644 --- a/Assets/Scripts/Inventory/InventorySlot.cs.meta +++ b/Assets/Scripts/Inventory/InventorySlot.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c5c5b18730cf11a41b91bf9d4f6cb26e +guid: bd9cfc2a55740fd4ba1bb807d02b82cb MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Item/EquippableItem.cs b/Assets/Scripts/Item/EquippableItem.cs new file mode 100644 index 00000000..71bcd574 --- /dev/null +++ b/Assets/Scripts/Item/EquippableItem.cs @@ -0,0 +1,33 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum EquipmentType +{ + Helmet, + Chest, + Gloves, + Boots, + Weapon, + Other +} + +[CreateAssetMenu] +public class EquippableItem : Item +{ + public int StrengthBonus; + public int AgilityBonus; + public int InteligenceBonus; + public int VitalityBonus; + + [Space] + public bool isStackable = false; + + [Space] + public EquipmentType EquipmentType; + + public EquippableItem(string _name, string _description, int _level, GameObject _itemModel, Sprite _image) : base(_name, _description, _level, _itemModel, _image) + { + + } +} diff --git a/Assets/Scripts/Item/EquippableItem.cs.meta b/Assets/Scripts/Item/EquippableItem.cs.meta new file mode 100644 index 00000000..96c44311 --- /dev/null +++ b/Assets/Scripts/Item/EquippableItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 943bb4b7c1123c44fb1cbc048a56a954 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item/ItemSlot.cs b/Assets/Scripts/Item/ItemSlot.cs new file mode 100644 index 00000000..bc436f1d --- /dev/null +++ b/Assets/Scripts/Item/ItemSlot.cs @@ -0,0 +1,136 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using System; // for Action type + +public class ItemSlot : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler, IDropHandler +{ + [Header("UI Stuff to change")] + [SerializeField] private TextMeshProUGUI slotItemNumberText; + [SerializeField] private Image itemImage; + + public ChestPanelController chestPanelController; + + public event Action OnBeginDragEvent; + public event Action OnEndDragEvent; + public event Action OnDragEvent; + public event Action OnDropEvent; + + private Color normalColor = Color.white; + private Color disabledColor = new Color(1, 1, 1, 0); // transparency = 0 + + [Header("Slot variable")] + [SerializeField] + protected int _number; + public int Number { + get { return _number; } + set { + _number = value; + } + } + [SerializeField] + protected Item _item; + public Item Item { + get { return _item; } + set { + _item = value; + + if(_item == null) { + itemImage.color = disabledColor; + } else { + itemImage.sprite = _item.Image; + itemImage.color = normalColor; + } + } + } + public int countStackableItems = 0; + + + + public void SetupInventorySlot(int _number, Item _item, ChestPanelController _chestPanelController) + { + chestPanelController = _chestPanelController; + + Number = _number; + + if(_item) + { + SetItem(_item); + } + } + + public void SetItem(Item _item) // dont change slot numer after assign new item, numbers are bind during object init + { + Item = _item; + + ChangeEnableImageView(true); + + countStackableItems +=1; + + UpdateItemNumberHolder(); + } + + + private void ChangeEnableImageView(bool _flag) + { + itemImage.color = _flag ? normalColor : disabledColor; //!slotImage.enabled; + } + + private void ChangeNumberHeldView(bool _flag) + { + slotItemNumberText.enabled = _flag; + } + + private void UpdateItemNumberHolder() + { + slotItemNumberText.text = "" + countStackableItems; + } + + // Start is called before the first frame update + void Start() + { + if(!Item) + { + ChangeEnableImageView(false); + ChangeNumberHeldView(false); + } + } + + // Update is called once per frame + void Update() + { + } + + public virtual bool CanReceiveItem(Item item) + { + return true; + } + + // Events methods + public void OnBeginDrag(PointerEventData eventData) + { + if(OnBeginDragEvent != null) + OnBeginDragEvent(this); + } + + public void OnEndDrag(PointerEventData eventData) + { + if(OnEndDragEvent != null) + OnEndDragEvent(this); + } + + public void OnDrag(PointerEventData eventData) + { + if(OnDragEvent != null) + OnDragEvent(this); + } + + public void OnDrop(PointerEventData eventData) + { + if(OnDropEvent != null) + OnDropEvent(this); + } +} diff --git a/Assets/Scripts/Item/ItemSlot.cs.meta b/Assets/Scripts/Item/ItemSlot.cs.meta new file mode 100644 index 00000000..e55da581 --- /dev/null +++ b/Assets/Scripts/Item/ItemSlot.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5c5b18730cf11a41b91bf9d4f6cb26e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item/PickableController.cs b/Assets/Scripts/Item/PickableController.cs index d05c8530..28a0a9ab 100644 --- a/Assets/Scripts/Item/PickableController.cs +++ b/Assets/Scripts/Item/PickableController.cs @@ -5,7 +5,7 @@ using System; public class PickableController : MonoBehaviour { - public Item item; + public EquippableItem item; public void Start() { diff --git a/Assets/Scripts/Objects' Scripts/Chest.cs b/Assets/Scripts/Objects' Scripts/Chest.cs index 0324362d..5e224317 100644 --- a/Assets/Scripts/Objects' Scripts/Chest.cs +++ b/Assets/Scripts/Objects' Scripts/Chest.cs @@ -6,7 +6,10 @@ public class Chest : MonoBehaviour { [SerializeField] public GameObject chest; [SerializeField] public GameObject chestPanel; - [SerializeField] public List itemsList = new List(); + [SerializeField] public List developerList = new List(); // FOR DEVELOPER TESTE - remove later !!! + + [SerializeField] + public Dictionary itemsList = new Dictionary(); private GameObject dynamicPanel; // UI elemend created during script work @@ -17,6 +20,12 @@ public class Chest : MonoBehaviour void Start() { chest = gameObject; // set object on current GameObject + + // FOR DEVELOPER TESTE - remove later !!! + for(int i = 0; i < developerList.Count; i++) + { + SetItemOnPosition(i, developerList[i]); + } } // Update is called once per frame @@ -73,4 +82,11 @@ public class Chest : MonoBehaviour Destroy(dynamicPanel); // destroy object from scene isOpen = false; } + + // WARNING + // DANGER - functon override position which may be not free + public void SetItemOnPosition(int _keyPosition, Item _item) + { + itemsList[_keyPosition] = _item; + } }