From 23470d36a9437ff330427d4134c580571001eda7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-VVOCIJO\\PC" Date: Mon, 11 May 2026 13:00:44 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=88=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/01_Scenes/MyProject/GameScene.unity | 4 +-- Assets/02_Scripts/Data/Player/PlayerWallet.cs | 34 +++++++++++------- Assets/02_Scripts/UI/WalletHud.cs | 35 +++++++++++++++++++ Assets/02_Scripts/UI/WalletHud.cs.meta | 2 ++ 4 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 Assets/02_Scripts/UI/WalletHud.cs create mode 100644 Assets/02_Scripts/UI/WalletHud.cs.meta diff --git a/Assets/01_Scenes/MyProject/GameScene.unity b/Assets/01_Scenes/MyProject/GameScene.unity index f12ba9ba..5118b932 100644 --- a/Assets/01_Scenes/MyProject/GameScene.unity +++ b/Assets/01_Scenes/MyProject/GameScene.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c3c6420614657d4b4d2467920c00c19bd116d48f93b65b20e17dc04732df8a51 -size 12061215 +oid sha256:6a6307f49e4424357e639c3cbfa363ae74dd9b2bad20973ad5582e7016390b3f +size 12072711 diff --git a/Assets/02_Scripts/Data/Player/PlayerWallet.cs b/Assets/02_Scripts/Data/Player/PlayerWallet.cs index e6dceefb..fd109490 100644 --- a/Assets/02_Scripts/Data/Player/PlayerWallet.cs +++ b/Assets/02_Scripts/Data/Player/PlayerWallet.cs @@ -1,28 +1,36 @@ +using System; using UnityEngine; +using UnityEngine.Serialization; namespace VRShopping.Player { public class PlayerWallet : MonoBehaviour { - //예산 - [Min(0)] public int Budget; + // 예산 (Inspector에서 초기값 설정) + [SerializeField, Min(0), FormerlySerializedAs("Budget")] + private int _budget; + + // UI 갱신용 이벤트 + public event Action OnBudgetChanged; + + public int Budget => _budget; + + private void Start() + { + OnBudgetChanged?.Invoke(_budget); + } public bool PayMoney(int cost) { - bool successFlag; - //예산이 비용보다 많을시 - if(Budget >= cost) + if (_budget >= cost) { - Budget -= cost; - successFlag = true; + _budget -= cost; + OnBudgetChanged?.Invoke(_budget); + return true; } - else //예산 부족 - { - successFlag = false; - } - - return successFlag; + //예산 부족 + return false; } } } diff --git a/Assets/02_Scripts/UI/WalletHud.cs b/Assets/02_Scripts/UI/WalletHud.cs new file mode 100644 index 00000000..94e75eca --- /dev/null +++ b/Assets/02_Scripts/UI/WalletHud.cs @@ -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}"; + } + } +} diff --git a/Assets/02_Scripts/UI/WalletHud.cs.meta b/Assets/02_Scripts/UI/WalletHud.cs.meta new file mode 100644 index 00000000..f5ade181 --- /dev/null +++ b/Assets/02_Scripts/UI/WalletHud.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 59629d355895f5d48b2a59479440912f \ No newline at end of file