2026-04-22 계산대 진행중
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using VRShopping.Items;
|
||||
using VRShopping.UI;
|
||||
@@ -12,24 +13,51 @@ public class CheckoutMachine : MonoBehaviour
|
||||
[SerializeField] private Transform _rowContainer;
|
||||
[SerializeField] private CheckoutProductionRow _rowPrefab;
|
||||
|
||||
private readonly Dictionary<ItemData, CheckoutProductionRow> _rowByItem = new();
|
||||
private readonly Dictionary<string, CheckoutProductionRow> _rowByItemId = new();
|
||||
|
||||
[SerializeField] private TMP_Text _checkoutSumField;
|
||||
|
||||
public void UpdateSumUI()
|
||||
{
|
||||
_checkoutSumField.text = CheckoutSum.ToString("N0");
|
||||
}
|
||||
|
||||
public void AddCheckoutProduction(ItemData itemData)
|
||||
{
|
||||
if (itemData == null) return;
|
||||
|
||||
if (_rowByItem.TryGetValue(itemData, out CheckoutProductionRow row))
|
||||
if (_rowByItemId.TryGetValue(itemData.ItemId, out CheckoutProductionRow row))
|
||||
{
|
||||
row.Bind(itemData, row.Quantity + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
row = Instantiate(_rowPrefab, _rowContainer);
|
||||
row.OnAddClicked += AddCheckoutProduction;
|
||||
row.OnRemoveClicked += RemoveCheckoutProduction;
|
||||
row.Bind(itemData, 1);
|
||||
_rowByItem[itemData] = row;
|
||||
_rowByItemId[itemData.ItemId] = row;
|
||||
}
|
||||
|
||||
CheckoutSum += itemData.FinalPrice;
|
||||
}
|
||||
|
||||
public void RemoveCheckoutProduction(ItemData itemData)
|
||||
{
|
||||
if (itemData == null) return;
|
||||
if (!_rowByItemId.TryGetValue(itemData.ItemId, out CheckoutProductionRow row)) return;
|
||||
|
||||
CheckoutSum -= itemData.FinalPrice;
|
||||
|
||||
if (row.Quantity <= 1)
|
||||
{
|
||||
_rowByItemId.Remove(itemData.ItemId);
|
||||
Destroy(row.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.Bind(itemData, row.Quantity - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user