74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
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 _originalPriceText;
|
|
[SerializeField] private TMP_Text _discountPriceText;
|
|
[SerializeField] private TMP_Text _discountRateText;
|
|
[SerializeField] private GameObject _discountRoot;
|
|
|
|
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;
|
|
|
|
bool hasDiscount = data.DiscountRate > 0f;
|
|
|
|
if (_originalPriceText != null)
|
|
{
|
|
_originalPriceText.gameObject.SetActive(true);
|
|
_originalPriceText.text = hasDiscount
|
|
? $"<s>{FormatPrice(data.BasePrice)}</s>"
|
|
: FormatPrice(data.FinalPrice);
|
|
}
|
|
|
|
if (_discountRoot != null) _discountRoot.SetActive(hasDiscount);
|
|
|
|
if (hasDiscount)
|
|
{
|
|
if (_discountPriceText != null) _discountPriceText.text = FormatPrice(data.FinalPrice);
|
|
if (_discountRateText != null) _discountRateText.text = $"{Mathf.RoundToInt(data.DiscountRate * 100f)}";
|
|
}
|
|
|
|
_root.SetActive(true);
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
_root.SetActive(false);
|
|
}
|
|
|
|
private static string FormatPrice(int price) => $"₩{price:N0}";
|
|
}
|
|
}
|