Add chest Drag & Drop

This commit is contained in:
kabix09 2022-05-29 21:54:28 +02:00
parent 1d436aa16f
commit 00d02ca2ac
27 changed files with 715 additions and 102 deletions

View File

@ -49,15 +49,20 @@
<ItemGroup>
<Compile Include="Assets\Scripts\SettingsButton.cs" />
<Compile Include="Assets\Scripts\Enemies&apos; Scprits\Enemy.cs" />
<Compile Include="Assets\Scripts\DragDropItemManager.cs" />
<Compile Include="Assets\Scripts\Inventory\InventorySlot.cs" />
<Compile Include="Assets\Scripts\QuitGame.cs" />
<Compile Include="Assets\Scripts\Inventory\InventoryManager.cs" />
<Compile Include="Assets\Scripts\Dialogue.cs" />
<Compile Include="Assets\Scripts\Inventory\InventorySlot.cs" />
<Compile Include="Assets\Scripts\Item\ItemSlot.cs" />
<Compile Include="Assets\Scripts\Item\Item.cs" />
<Compile Include="Assets\Scripts\Chest\ChestSlot.cs" />
<Compile Include="Assets\Scripts\CamerFollow.cs" />
<Compile Include="Assets\Scripts\Equipment\EquipmentSlot.cs" />
<Compile Include="Assets\Scripts\SaveSoundSettings.cs" />
<Compile Include="Assets\Scripts\MenuGUI.cs" />
<Compile Include="Assets\Scripts\FloatValue.cs" />
<Compile Include="Assets\Scripts\Item\EquippableItem.cs" />
<Compile Include="Assets\breakable.cs" />
<Compile Include="Assets\Scripts\Enemies&apos; Scprits\FollowingEnemy.cs" />
<Compile Include="Assets\Scripts\Item\PickableController.cs" />

View File

@ -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

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: aaa7c520aded1bc42a26b7ce43484010
guid: 5935777f7ac390a4187e03f34e7cafdd
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

View File

@ -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

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1304511dd1dfefc449e87c3d904ab15f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5239ba2d7bc1aa64e90b3f8b87342137
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ad5d982f550477a4b8b8be4ad2988ec2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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

View File

@ -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:

View File

@ -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<ChestSlot> itemSlots = new List<ChestSlot>();
public List<InventorySlot> content = new List<InventorySlot>();
public event Action<ItemSlot> OnBeginDragEvent;
public event Action<ItemSlot> OnEndDragEvent;
public event Action<ItemSlot> OnDragEvent;
public event Action<ItemSlot> 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<InventorySlot>();
ChestSlot newSlot = Instantiate(blankChestSlot, chestPanel.transform.position, Quaternion.identity).GetComponent<ChestSlot>();
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<Item> _chestItems)
public void SetupChest(GameObject _chest, Dictionary<int, Item> _chestItems)
{
chest = _chest;
SetPanelItems(_chestItems);
}
private void SetPanelItems(List<Item> _itemsList)
{
for(int i=0; i < _itemsList.Count; i++)
private void SetPanelItems(Dictionary<int, Item> _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<Chest>().SetItemOnPosition(draggedSlot.Number, draggedSlot.Item);
chest.GetComponent<Chest>().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;
// }
// }
}

View File

@ -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
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2be16a7ceddcd2141ba1db1636539117
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragDropItemManager : MonoBehaviour
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a6334ce379c25c458826dcd25b5e1ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4e66e807c2717ee45923ec12b22309d0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,7 +8,7 @@ public class InventoryManager : MonoBehaviour
public static int MAX_ITEMS = 5;
public static InventoryManager Instance;
public List<Item> items = new List<Item>();
public List<EquippableItem> items = new List<EquippableItem>();
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)
{

View File

@ -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()
{
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: c5c5b18730cf11a41b91bf9d4f6cb26e
guid: bd9cfc2a55740fd4ba1bb807d02b82cb
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -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)
{
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 943bb4b7c1123c44fb1cbc048a56a954
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -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<ItemSlot> OnBeginDragEvent;
public event Action<ItemSlot> OnEndDragEvent;
public event Action<ItemSlot> OnDragEvent;
public event Action<ItemSlot> 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);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5c5b18730cf11a41b91bf9d4f6cb26e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,7 +5,7 @@ using System;
public class PickableController : MonoBehaviour
{
public Item item;
public EquippableItem item;
public void Start()
{

View File

@ -6,7 +6,10 @@ public class Chest : MonoBehaviour
{
[SerializeField] public GameObject chest;
[SerializeField] public GameObject chestPanel;
[SerializeField] public List<Item> itemsList = new List<Item>();
[SerializeField] public List<Item> developerList = new List<Item>(); // FOR DEVELOPER TESTE - remove later !!!
[SerializeField]
public Dictionary<int, Item> itemsList = new Dictionary<int, Item>();
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;
}
}