2026-04-22 계산대 진행중
This commit is contained in:
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using VRShopping.Items;
|
using VRShopping.Items;
|
||||||
using VRShopping.UI;
|
using VRShopping.UI;
|
||||||
@@ -12,24 +13,51 @@ public class CheckoutMachine : MonoBehaviour
|
|||||||
[SerializeField] private Transform _rowContainer;
|
[SerializeField] private Transform _rowContainer;
|
||||||
[SerializeField] private CheckoutProductionRow _rowPrefab;
|
[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)
|
public void AddCheckoutProduction(ItemData itemData)
|
||||||
{
|
{
|
||||||
if (itemData == null) return;
|
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);
|
row.Bind(itemData, row.Quantity + 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
row = Instantiate(_rowPrefab, _rowContainer);
|
row = Instantiate(_rowPrefab, _rowContainer);
|
||||||
|
row.OnAddClicked += AddCheckoutProduction;
|
||||||
|
row.OnRemoveClicked += RemoveCheckoutProduction;
|
||||||
row.Bind(itemData, 1);
|
row.Bind(itemData, 1);
|
||||||
_rowByItem[itemData] = row;
|
_rowByItemId[itemData.ItemId] = row;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckoutSum += itemData.FinalPrice;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
using System;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
using VRShopping.Items;
|
using VRShopping.Items;
|
||||||
|
|
||||||
namespace VRShopping.UI
|
namespace VRShopping.UI
|
||||||
@@ -9,9 +11,21 @@ public class CheckoutProductionRow : MonoBehaviour
|
|||||||
[SerializeField] private TMP_Text _nameText;
|
[SerializeField] private TMP_Text _nameText;
|
||||||
[SerializeField] private TMP_Text _quantityText;
|
[SerializeField] private TMP_Text _quantityText;
|
||||||
[SerializeField] private TMP_Text _priceText;
|
[SerializeField] private TMP_Text _priceText;
|
||||||
|
[SerializeField] private Button _addButton;
|
||||||
|
[SerializeField] private Button _removeButton;
|
||||||
|
|
||||||
|
public ItemData Item { get; private set; }
|
||||||
public int Quantity { get; private set; }
|
public int Quantity { get; private set; }
|
||||||
|
|
||||||
|
public event Action<ItemData> OnAddClicked;
|
||||||
|
public event Action<ItemData> OnRemoveClicked;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (_addButton != null) _addButton.onClick.AddListener(() => OnAddClicked?.Invoke(Item));
|
||||||
|
if (_removeButton != null) _removeButton.onClick.AddListener(() => OnRemoveClicked?.Invoke(Item));
|
||||||
|
}
|
||||||
|
|
||||||
public void Bind(ItemData item, int quantity)
|
public void Bind(ItemData item, int quantity)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
@@ -20,11 +34,12 @@ public void Bind(ItemData item, int quantity)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item = item;
|
||||||
Quantity = quantity;
|
Quantity = quantity;
|
||||||
|
|
||||||
if (_nameText != null) _nameText.text = item.DisplayName;
|
if (_nameText != null) _nameText.text = item.DisplayName;
|
||||||
if (_quantityText != null) _quantityText.text = $"x{quantity}";
|
if (_quantityText != null) _quantityText.text = $"x{quantity}";
|
||||||
if (_priceText != null) _priceText.text = (item.FinalPrice * quantity).ToString();
|
if (_priceText != null) _priceText.text = (item.FinalPrice * quantity).ToString("N0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user