상점 포션 구매 UniRx(MVP 패턴)를 활용하여 수정중
This commit is contained in:
61
Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs
Normal file
61
Gameton-06/Assets/Gameton/Scripts/UI/ShopItemUI.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user