장보기 프로젝트
This commit is contained in:
8
Assets/02_Scripts/Item.meta
Normal file
8
Assets/02_Scripts/Item.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13976d58f70d6d243a91f2516463219b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/02_Scripts/Item/ItemData.cs
Normal file
46
Assets/02_Scripts/Item/ItemData.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace VRShopping.Items
|
||||
{
|
||||
[CreateAssetMenu(fileName = "ItemData", menuName = "VR Shopping/Item Data", order = 0)]
|
||||
public class ItemData : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
[SerializeField] private string _itemId;
|
||||
[SerializeField] private string _displayName;
|
||||
[SerializeField] private string _brand;
|
||||
[SerializeField] private ItemCategory _category;
|
||||
|
||||
[Header("Pricing")]
|
||||
[SerializeField, Min(0)] private int _basePrice;
|
||||
[SerializeField, Range(0f, 1f)] private float _discountRate;
|
||||
|
||||
[Header("Visuals")]
|
||||
[SerializeField] private Sprite _icon;
|
||||
[SerializeField] private GameObject _prefab;
|
||||
|
||||
public string ItemId => _itemId;
|
||||
public string DisplayName => _displayName;
|
||||
public string Brand => _brand;
|
||||
public ItemCategory Category => _category;
|
||||
public int BasePrice => _basePrice;
|
||||
public float DiscountRate => _discountRate;
|
||||
public Sprite Icon => _icon;
|
||||
public GameObject Prefab => _prefab;
|
||||
|
||||
public int FinalPrice => Mathf.RoundToInt(_basePrice * (1f - _discountRate));
|
||||
}
|
||||
|
||||
public enum ItemCategory
|
||||
{
|
||||
Fruit,
|
||||
Vegetable,
|
||||
Dairy,
|
||||
Bakery,
|
||||
Meat,
|
||||
Drink,
|
||||
Snack,
|
||||
Household,
|
||||
Etc
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Item/ItemData.cs.meta
Normal file
2
Assets/02_Scripts/Item/ItemData.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff778a7d4eb15f543822fc80a8606760
|
||||
8
Assets/02_Scripts/UI.meta
Normal file
8
Assets/02_Scripts/UI.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f007d1dbc8db2534294dddaaad2ef53c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/02_Scripts/UI/Handedness.cs
Normal file
8
Assets/02_Scripts/UI/Handedness.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace VRShopping.UI
|
||||
{
|
||||
public enum Handedness
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/UI/Handedness.cs.meta
Normal file
2
Assets/02_Scripts/UI/Handedness.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a0d39e1f63994241808d2d7d877caf3
|
||||
43
Assets/02_Scripts/UI/ItemInfoHud.cs
Normal file
43
Assets/02_Scripts/UI/ItemInfoHud.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using VRShopping.Items;
|
||||
|
||||
namespace VRShopping.UI
|
||||
{
|
||||
public class ItemInfoHud : MonoBehaviour
|
||||
{
|
||||
public static ItemInfoHud Instance { get; private set; }
|
||||
|
||||
[SerializeField] private ItemInfoPanel _leftPanel;
|
||||
[SerializeField] private ItemInfoPanel _rightPanel;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (Instance == this) Instance = null;
|
||||
}
|
||||
|
||||
public void Show(Handedness hand, ItemData data)
|
||||
{
|
||||
GetPanel(hand)?.Show(data);
|
||||
}
|
||||
|
||||
public void Hide(Handedness hand)
|
||||
{
|
||||
GetPanel(hand)?.Hide();
|
||||
}
|
||||
|
||||
private ItemInfoPanel GetPanel(Handedness hand)
|
||||
{
|
||||
return hand == Handedness.Left ? _leftPanel : _rightPanel;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/UI/ItemInfoHud.cs.meta
Normal file
2
Assets/02_Scripts/UI/ItemInfoHud.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03f393b2916cda845895fdd629622563
|
||||
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}";
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/UI/ItemInfoPanel.cs.meta
Normal file
2
Assets/02_Scripts/UI/ItemInfoPanel.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ee2f146032fb094aa2a69f2843dac33
|
||||
Reference in New Issue
Block a user