예산
This commit is contained in:
Binary file not shown.
@@ -1,28 +1,36 @@
|
|||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
namespace VRShopping.Player
|
namespace VRShopping.Player
|
||||||
{
|
{
|
||||||
public class PlayerWallet : MonoBehaviour
|
public class PlayerWallet : MonoBehaviour
|
||||||
{
|
{
|
||||||
//예산
|
// 예산 (Inspector에서 초기값 설정)
|
||||||
[Min(0)] public int Budget;
|
[SerializeField, Min(0), FormerlySerializedAs("Budget")]
|
||||||
|
private int _budget;
|
||||||
|
|
||||||
|
// UI 갱신용 이벤트
|
||||||
|
public event Action<int> OnBudgetChanged;
|
||||||
|
|
||||||
|
public int Budget => _budget;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
OnBudgetChanged?.Invoke(_budget);
|
||||||
|
}
|
||||||
|
|
||||||
public bool PayMoney(int cost)
|
public bool PayMoney(int cost)
|
||||||
{
|
{
|
||||||
bool successFlag;
|
|
||||||
|
|
||||||
//예산이 비용보다 많을시
|
//예산이 비용보다 많을시
|
||||||
if(Budget >= cost)
|
if (_budget >= cost)
|
||||||
{
|
{
|
||||||
Budget -= cost;
|
_budget -= cost;
|
||||||
successFlag = true;
|
OnBudgetChanged?.Invoke(_budget);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else //예산 부족
|
//예산 부족
|
||||||
{
|
return false;
|
||||||
successFlag = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return successFlag;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
35
Assets/02_Scripts/UI/WalletHud.cs
Normal file
35
Assets/02_Scripts/UI/WalletHud.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using VRShopping.Player;
|
||||||
|
|
||||||
|
namespace VRShopping.UI
|
||||||
|
{
|
||||||
|
// 왼쪽 손목 허기 게이지 위에 부착되는 소지금 HUD.
|
||||||
|
// PlayerWallet.OnBudgetChanged에 자동 구독.
|
||||||
|
public class WalletHud : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private TMP_Text _text;
|
||||||
|
[SerializeField] private PlayerWallet _bound;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_bound.OnBudgetChanged += HandleChanged;
|
||||||
|
HandleChanged(_bound.Budget);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (_bound != null)
|
||||||
|
{
|
||||||
|
_bound.OnBudgetChanged -= HandleChanged;
|
||||||
|
_bound = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleChanged(int current)
|
||||||
|
{
|
||||||
|
if (_text != null)
|
||||||
|
_text.text = $"₩ {current:N0}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/02_Scripts/UI/WalletHud.cs.meta
Normal file
2
Assets/02_Scripts/UI/WalletHud.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 59629d355895f5d48b2a59479440912f
|
||||||
Reference in New Issue
Block a user