상점 포션 구매 UniRx(MVP 패턴)를 활용하여 수정중

This commit is contained in:
Mingu Kim
2025-06-02 00:28:39 +09:00
parent 8a54d47b56
commit 66ee4d6d2e
6 changed files with 156 additions and 47 deletions

View File

@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
namespace TON
{
// View
public class ShopItemUI : MonoBehaviour
{
[SerializeField] private Image image;
[SerializeField] private TextMeshProUGUI title;
[SerializeField] private TextMeshProUGUI txtPrice;
[SerializeField] private Button buyButton;
public void Bind(ShopItemPresenter presenter)
{
}
}
// Presenter
public class ShopItemPresenter
{
public ReactiveProperty<int> Price { get; set; }
public ReactiveProperty<string> PotionType { get; set; }
public ReactiveProperty<int> Quantity { get; set; }
public ReactiveCommand BuyCommand { get; set; }
private ShopItemModel _model;
public ShopItemPresenter(ShopPresenter shopPresenter, ShopItemModel model)
{
_model = model;
Price = new ReactiveProperty<int>(_model.Price);
PotionType = new ReactiveProperty<string>(_model.PotionType);
Quantity = new ReactiveProperty<int>(_model.Quantity);
BuyCommand = new ReactiveCommand();
BuyCommand.Subscribe(_ => shopPresenter.BuyPotion(this));
}
}
// Model
public class ShopItemModel
{
public int Price;
public string PotionType;
public int Quantity;
public ShopItemModel(int price, string postionType, int quantity)
{
Price = price;
PotionType = postionType;
Quantity = quantity;
}
}
}