장보기 프로젝트
This commit is contained in:
66
Assets/02_Scripts/UI/ItemInfoPanel.cs
Normal file
66
Assets/02_Scripts/UI/ItemInfoPanel.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using VRShopping.Items;
|
||||
|
||||
namespace VRShopping.UI
|
||||
{
|
||||
public class ItemInfoPanel : MonoBehaviour
|
||||
{
|
||||
[Header("Refs")]
|
||||
[SerializeField] private GameObject _root;
|
||||
[SerializeField] private Image _iconImage;
|
||||
[SerializeField] private TMP_Text _nameText;
|
||||
[SerializeField] private TMP_Text _brandText;
|
||||
[SerializeField] private TMP_Text _priceText;
|
||||
[SerializeField] private TMP_Text _originalPriceText;
|
||||
[SerializeField] private GameObject _discountBadge;
|
||||
[SerializeField] private TMP_Text _discountRateText;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_root == null) _root = gameObject;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Show(ItemData data)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_iconImage != null)
|
||||
{
|
||||
_iconImage.sprite = data.Icon;
|
||||
_iconImage.enabled = data.Icon != null;
|
||||
}
|
||||
|
||||
if (_nameText != null) _nameText.text = data.DisplayName;
|
||||
if (_brandText != null) _brandText.text = data.Brand;
|
||||
if (_priceText != null) _priceText.text = FormatPrice(data.FinalPrice);
|
||||
|
||||
bool hasDiscount = data.DiscountRate > 0f;
|
||||
if (_originalPriceText != null)
|
||||
{
|
||||
_originalPriceText.gameObject.SetActive(hasDiscount);
|
||||
if (hasDiscount) _originalPriceText.text = $"<s>{FormatPrice(data.BasePrice)}</s>";
|
||||
}
|
||||
if (_discountBadge != null) _discountBadge.SetActive(hasDiscount);
|
||||
if (_discountRateText != null && hasDiscount)
|
||||
{
|
||||
_discountRateText.text = $"-{Mathf.RoundToInt(data.DiscountRate * 100f)}%";
|
||||
}
|
||||
|
||||
_root.SetActive(true);
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
_root.SetActive(false);
|
||||
}
|
||||
|
||||
private static string FormatPrice(int price) => $"₩{price:N0}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user