36 lines
990 B
C#
36 lines
990 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using VRShopping.Items;
|
|
using VRShopping.UI;
|
|
|
|
namespace VRShopping.Interact
|
|
{
|
|
public class CheckoutMachine : MonoBehaviour
|
|
{
|
|
public int CheckoutSum { get; private set; }
|
|
|
|
[SerializeField] private Transform _rowContainer;
|
|
[SerializeField] private CheckoutProductionRow _rowPrefab;
|
|
|
|
private readonly Dictionary<ItemData, CheckoutProductionRow> _rowByItem = new();
|
|
|
|
public void AddCheckoutProduction(ItemData itemData)
|
|
{
|
|
if (itemData == null) return;
|
|
|
|
if (_rowByItem.TryGetValue(itemData, out CheckoutProductionRow row))
|
|
{
|
|
row.Bind(itemData, row.Quantity + 1);
|
|
}
|
|
else
|
|
{
|
|
row = Instantiate(_rowPrefab, _rowContainer);
|
|
row.Bind(itemData, 1);
|
|
_rowByItem[itemData] = row;
|
|
}
|
|
|
|
CheckoutSum += itemData.FinalPrice;
|
|
}
|
|
}
|
|
}
|