Player put items in basket with UI indication
This commit is contained in:
@@ -14,7 +14,7 @@ public class Fridge : BaseInteractableObject
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
|
||||
_actionsMenu.Show(_containerSO.Name, $"Max items:{_containerSO.MaxCapacity} current items: {_containerSO.CurrentItemsCount}");
|
||||
//_actionsMenu.Show(_containerSO.Name, $"Max items:{_containerSO.MaxCapacity} current items: {_containerSO.CurrentItemsCount}");
|
||||
//if (player.IsHoldContainer())
|
||||
//{
|
||||
// if (_foodObjects.Count < _containerSO.MaxCapacity)
|
||||
|
||||
@@ -7,11 +7,11 @@ public class ContainerItem : MonoBehaviour
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
|
||||
private List<SellableItem> _items;
|
||||
private List<SellableItemSO> _items;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_items = new List<SellableItem>();
|
||||
_items = new List<SellableItemSO>();
|
||||
}
|
||||
|
||||
public ContainerSO GetContainerObjectSO()
|
||||
@@ -19,17 +19,21 @@ public class ContainerItem : MonoBehaviour
|
||||
return _containerSO;
|
||||
}
|
||||
|
||||
public void AddItem(SellableItem item)
|
||||
public void AddItem(SellableItemSO item)
|
||||
{
|
||||
if (_containerSO.CurrentItemsCount < _containerSO.MaxCapacity)
|
||||
if (_items.Count < _containerSO.MaxCapacity)
|
||||
{
|
||||
Debug.Log($"Player put to container a {item.GetSellableItemSO().objectName}");
|
||||
Debug.Log($"Player put to container a {item.ItemName}");
|
||||
_items.Add(item);
|
||||
_containerSO.CurrentItemsCount = _items.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Container is full");
|
||||
}
|
||||
}
|
||||
|
||||
public List<SellableItemSO> GetItems()
|
||||
{
|
||||
return _items;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ShopingContainer : BaseInteractableObject
|
||||
public class ShopingBasket : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
+3
-4
@@ -1,7 +1,7 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class ColaFreezer : BaseInteractableObject
|
||||
public class StoreContainer : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private SellableItemSO _sellableItemSO;
|
||||
@@ -10,11 +10,10 @@ public class ColaFreezer : BaseInteractableObject
|
||||
{
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var transform = Instantiate(_sellableItemSO.prefab, player.GetContainerItem().transform);
|
||||
var sellableItem = transform.GetComponent<SellableItem>();
|
||||
var clone = Instantiate(_sellableItemSO);
|
||||
|
||||
var container = player.GetContainerItem();
|
||||
container.AddItem(sellableItem);
|
||||
container.AddItem(clone);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: aec77d0318a147746a02df3c98dc1b76, type: 3}
|
||||
m_Name: Cola
|
||||
m_EditorClassIdentifier:
|
||||
prefab: {fileID: 2680879424619819010, guid: 48940f42625c11541b2ebe92e86b6314, type: 3}
|
||||
objectName: Cola
|
||||
objectPrice: 10
|
||||
Prefab: {fileID: 0}
|
||||
ItemName: Cola
|
||||
Price: 10
|
||||
Icon: {fileID: 21300000, guid: 61282d9e9f6bd4d43aa75f43bbe7ab6c, type: 3}
|
||||
|
||||
@@ -5,6 +5,5 @@ public class ContainerSO : ScriptableObject
|
||||
{
|
||||
public string Name;
|
||||
public int MaxCapacity;
|
||||
public int CurrentItemsCount;
|
||||
public Transform prefab;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@ using UnityEngine;
|
||||
[CreateAssetMenu()]
|
||||
public class SellableItemSO : ScriptableObject
|
||||
{
|
||||
public Transform prefab;
|
||||
public string objectName;
|
||||
public float objectPrice;
|
||||
public Transform Prefab;
|
||||
public string ItemName;
|
||||
public float Price;
|
||||
public Sprite Icon;
|
||||
}
|
||||
|
||||
@@ -14,5 +14,4 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
Name: Shoping basket
|
||||
MaxCapacity: 5
|
||||
CurrentItemsCount: 0
|
||||
prefab: {fileID: 4771105611132447618, guid: cbfa04a0e789cc44a908f6953ea6e6a9, type: 3}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ContainerItemsUI : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private Transform _container;
|
||||
[SerializeField]
|
||||
private Transform _itemsList;
|
||||
[SerializeField]
|
||||
private Transform _itemUITemplate;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_container.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Player.Instance.IsHoldContainerItem())
|
||||
{
|
||||
_container.gameObject.SetActive(true);
|
||||
|
||||
var playerContainer = Player.Instance.GetContainerItem();
|
||||
if (playerContainer.GetItems().Any())
|
||||
{
|
||||
foreach (Transform child in _itemsList)
|
||||
{
|
||||
if (child == _itemUITemplate) continue;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
for (int count = 0; count < playerItemsList.Count; count++)
|
||||
{
|
||||
var itemUI = Instantiate(_itemUITemplate, _itemsList);
|
||||
itemUI.gameObject.SetActive(true);
|
||||
itemUI.GetComponent<ItemDescriptionUI>().SetItem(playerItemsList[count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c4e9fa0f730f1b4698d6adaca1b8ffd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ItemDescriptionUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _name;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _price;
|
||||
[SerializeField]
|
||||
private Image _icon;
|
||||
|
||||
public void SetItem(SellableItemSO item)
|
||||
{
|
||||
_name.text = item.ItemName;
|
||||
_price.text = $"{item.Price}$";
|
||||
_icon.sprite = item.Icon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5de15a198a3ca5240a6c21ae0a8c6c8f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user