From 5ac0f1c82e73b637e67cce24e52e87908d34e8f1 Mon Sep 17 00:00:00 2001 From: Vladimir Koshevarov Date: Sun, 5 Mar 2023 14:01:39 +0200 Subject: [PATCH] put cola in basket --- Assets/Prefabs/Cola.prefab | 8 +++---- .../InteractableObjects/ColaFreezer.cs | 16 ++++++------- .../Items/ContainerItem.cs | 23 +++++++++++++++++++ .../InteractableObjects/Items/SellableItem.cs | 6 ++--- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Assets/Prefabs/Cola.prefab b/Assets/Prefabs/Cola.prefab index 9dd275df..b5049d0d 100644 --- a/Assets/Prefabs/Cola.prefab +++ b/Assets/Prefabs/Cola.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 2680879424619819010} - component: {fileID: 7774043156322841003} - component: {fileID: 2250778480304515286} - - component: {fileID: 1996526453472525189} + - component: {fileID: 2024399116333554914} m_Layer: 0 m_Name: Cola m_TagString: Untagged @@ -85,7 +85,7 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} ---- !u!114 &1996526453472525189 +--- !u!114 &2024399116333554914 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -94,7 +94,7 @@ MonoBehaviour: m_GameObject: {fileID: 7642835775543905443} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ef8197297f5651a4082c2562c95e5cd5, type: 3} + m_Script: {fileID: 11500000, guid: 329673eaf27345041afad67ebb166565, type: 3} m_Name: m_EditorClassIdentifier: - _foodObjectSO: {fileID: 11400000, guid: a4db4c329bb512349bf5373c80e7b84a, type: 2} + _sellableItemSO: {fileID: 11400000, guid: a4db4c329bb512349bf5373c80e7b84a, type: 2} diff --git a/Assets/Scripts/InteractableObjects/ColaFreezer.cs b/Assets/Scripts/InteractableObjects/ColaFreezer.cs index 710632a8..82c03a3e 100644 --- a/Assets/Scripts/InteractableObjects/ColaFreezer.cs +++ b/Assets/Scripts/InteractableObjects/ColaFreezer.cs @@ -8,14 +8,14 @@ public class ColaFreezer : BaseInteractableObject public override void Interact(Player player) { - //if (!player.IsHoldContainer()) - //{ - // //player.BuyObject(_sellableItemSO); - // // Spawn new object and set to player - // var transform = Instantiate(_sellableItemSO.prefab, _playerArrivePoint); - // var foodObject = transform.GetComponent(); - // player.SetFoodObject(foodObject); - //} + if (player.IsHoldContainerItem()) + { + var transform = Instantiate(_sellableItemSO.prefab, player.GetContainerItem().transform); + var sellableItem = transform.GetComponent(); + + var container = player.GetContainerItem(); + container.AddItem(sellableItem); + } } } diff --git a/Assets/Scripts/InteractableObjects/Items/ContainerItem.cs b/Assets/Scripts/InteractableObjects/Items/ContainerItem.cs index a953e19d..9ac383d5 100644 --- a/Assets/Scripts/InteractableObjects/Items/ContainerItem.cs +++ b/Assets/Scripts/InteractableObjects/Items/ContainerItem.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using UnityEngine; public class ContainerItem : MonoBehaviour @@ -5,8 +6,30 @@ public class ContainerItem : MonoBehaviour [SerializeField] private ContainerSO _containerSO; + + private List _items; + + private void Start() + { + _items = new List(); + } + public ContainerSO GetContainerObjectSO() { return _containerSO; } + + public void AddItem(SellableItem item) + { + if (_containerSO.CurrentItemsCount < _containerSO.MaxCapacity) + { + Debug.Log($"Player put to container a {item.GetSellableItemSO().objectName}"); + _items.Add(item); + _containerSO.CurrentItemsCount = _items.Count; + } + else + { + Debug.Log("Container is full"); + } + } } diff --git a/Assets/Scripts/InteractableObjects/Items/SellableItem.cs b/Assets/Scripts/InteractableObjects/Items/SellableItem.cs index 2016cca9..4f67ab2f 100644 --- a/Assets/Scripts/InteractableObjects/Items/SellableItem.cs +++ b/Assets/Scripts/InteractableObjects/Items/SellableItem.cs @@ -3,10 +3,10 @@ using UnityEngine; public class SellableItem : MonoBehaviour { [SerializeField] - private SellableItemSO _foodObjectSO; + private SellableItemSO _sellableItemSO; - public SellableItemSO GetFoodObjectSO() + public SellableItemSO GetSellableItemSO() { - return _foodObjectSO; + return _sellableItemSO; } }