상점 UI 포션 MVP 패턴 추가
This commit is contained in:
		@@ -2095,6 +2095,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 2892038168161912038}
 | 
			
		||||
  - component: {fileID: 7630059591734118752}
 | 
			
		||||
  - component: {fileID: 6983656107323574389}
 | 
			
		||||
  - component: {fileID: 5042996833529415973}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: HPPosion5
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -2160,6 +2161,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &5042996833529415973
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 691656603659687742}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 2835811577416321754}
 | 
			
		||||
  title: {fileID: 7746102705519901920}
 | 
			
		||||
  txtPrice: {fileID: 6908296491757153401}
 | 
			
		||||
  buyButton: {fileID: 4703705426857455285}
 | 
			
		||||
--- !u!1 &706951212985190310
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -3024,6 +3041,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 5878055121648309242}
 | 
			
		||||
  - component: {fileID: 8900813354726715018}
 | 
			
		||||
  - component: {fileID: 2669733002445248477}
 | 
			
		||||
  - component: {fileID: 8237828046055076472}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: MPPosion1
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -3089,6 +3107,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &8237828046055076472
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 1009847202782383007}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 1142210962579063319}
 | 
			
		||||
  title: {fileID: 3943848615682290980}
 | 
			
		||||
  txtPrice: {fileID: 1849010608715681228}
 | 
			
		||||
  buyButton: {fileID: 5139382520330716099}
 | 
			
		||||
--- !u!1 &1013687654832446300
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -3983,6 +4017,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 4377812817425128428}
 | 
			
		||||
  - component: {fileID: 482926518250686575}
 | 
			
		||||
  - component: {fileID: 2372124851589078198}
 | 
			
		||||
  - component: {fileID: 1339921229695397597}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: HPPosion1
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -4048,6 +4083,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &1339921229695397597
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 1238659231047176221}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 3145272010466771648}
 | 
			
		||||
  title: {fileID: 500466934263070813}
 | 
			
		||||
  txtPrice: {fileID: 7390841113898525167}
 | 
			
		||||
  buyButton: {fileID: 2263338202325704737}
 | 
			
		||||
--- !u!1 &1262901505653212038
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -9266,6 +9317,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 575786137439827299}
 | 
			
		||||
  - component: {fileID: 7213725879036316037}
 | 
			
		||||
  - component: {fileID: 7261399155026450201}
 | 
			
		||||
  - component: {fileID: 1762876319805661788}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: MPPosion5
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -9331,6 +9383,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &1762876319805661788
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 3505227747080097614}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 1369091806727325315}
 | 
			
		||||
  title: {fileID: 1892481066631850085}
 | 
			
		||||
  txtPrice: {fileID: 1475358832901107005}
 | 
			
		||||
  buyButton: {fileID: 9093635775014082266}
 | 
			
		||||
--- !u!1 &3513773433678305736
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -10028,6 +10096,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 5207883494733701616}
 | 
			
		||||
  - component: {fileID: 3548960397052590429}
 | 
			
		||||
  - component: {fileID: 8426959644519684905}
 | 
			
		||||
  - component: {fileID: 2445334872581908433}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: HPPosion20
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -10093,6 +10162,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &2445334872581908433
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 3599769466313680341}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 7091476854400377771}
 | 
			
		||||
  title: {fileID: 8602065505812440622}
 | 
			
		||||
  txtPrice: {fileID: 5858545111373462531}
 | 
			
		||||
  buyButton: {fileID: 6581108616243442068}
 | 
			
		||||
--- !u!1 &3619707288912244256
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -22056,6 +22141,7 @@ GameObject:
 | 
			
		||||
  - component: {fileID: 8456287251216652549}
 | 
			
		||||
  - component: {fileID: 7978602533984118169}
 | 
			
		||||
  - component: {fileID: 5872006662284563241}
 | 
			
		||||
  - component: {fileID: 6873764756110041606}
 | 
			
		||||
  m_Layer: 5
 | 
			
		||||
  m_Name: MPPosion20
 | 
			
		||||
  m_TagString: Untagged
 | 
			
		||||
@@ -22121,6 +22207,22 @@ MonoBehaviour:
 | 
			
		||||
  m_FillOrigin: 0
 | 
			
		||||
  m_UseSpriteMesh: 0
 | 
			
		||||
  m_PixelsPerUnitMultiplier: 1
 | 
			
		||||
--- !u!114 &6873764756110041606
 | 
			
		||||
MonoBehaviour:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
  m_CorrespondingSourceObject: {fileID: 0}
 | 
			
		||||
  m_PrefabInstance: {fileID: 0}
 | 
			
		||||
  m_PrefabAsset: {fileID: 0}
 | 
			
		||||
  m_GameObject: {fileID: 7242532085717922559}
 | 
			
		||||
  m_Enabled: 1
 | 
			
		||||
  m_EditorHideFlags: 0
 | 
			
		||||
  m_Script: {fileID: 11500000, guid: 87c3d53b1193f3c4bb806d0427e769ca, type: 3}
 | 
			
		||||
  m_Name: 
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  image: {fileID: 8915519731411800351}
 | 
			
		||||
  title: {fileID: 869895467774996221}
 | 
			
		||||
  txtPrice: {fileID: 6638863789167436681}
 | 
			
		||||
  buyButton: {fileID: 7451733678936642017}
 | 
			
		||||
--- !u!1 &7272884211138009173
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
@@ -23529,12 +23631,13 @@ MonoBehaviour:
 | 
			
		||||
  m_EditorClassIdentifier: 
 | 
			
		||||
  HeartPopUp: {fileID: 7274226733673243529}
 | 
			
		||||
  PositionPopUp: {fileID: 7383083170921283796}
 | 
			
		||||
  hpPotionPrice1: 200
 | 
			
		||||
  hpPotionPrice5: 1000
 | 
			
		||||
  hpPotionPrice20: 3600
 | 
			
		||||
  mpPotionPrice1: 400
 | 
			
		||||
  mpPotionPrice5: 2000
 | 
			
		||||
  mpPotionPrice20: 7600
 | 
			
		||||
  ShopItems:
 | 
			
		||||
  - {fileID: 1339921229695397597}
 | 
			
		||||
  - {fileID: 5042996833529415973}
 | 
			
		||||
  - {fileID: 2445334872581908433}
 | 
			
		||||
  - {fileID: 8237828046055076472}
 | 
			
		||||
  - {fileID: 1762876319805661788}
 | 
			
		||||
  - {fileID: 6873764756110041606}
 | 
			
		||||
--- !u!1 &7575278570391883562
 | 
			
		||||
GameObject:
 | 
			
		||||
  m_ObjectHideFlags: 0
 | 
			
		||||
 
 | 
			
		||||
@@ -14,10 +14,24 @@ namespace TON
 | 
			
		||||
        [SerializeField] private TextMeshProUGUI title;
 | 
			
		||||
        [SerializeField] private TextMeshProUGUI txtPrice;
 | 
			
		||||
        [SerializeField] private Button buyButton;
 | 
			
		||||
 | 
			
		||||
        
 | 
			
		||||
        public void Bind(ShopItemPresenter presenter)
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
            presenter.Price.Subscribe(text => txtPrice.text = text.ToString()).AddTo(this);
 | 
			
		||||
			presenter.PotionType.CombineLatest(presenter.Quantity, (type, quantity)=> $"{type} 포션 {quantity}개")
 | 
			
		||||
				.Subscribe(text => title.text = text)
 | 
			
		||||
				.AddTo(this);
 | 
			
		||||
			presenter.BuyCommand.BindTo(buyButton).AddTo(this);
 | 
			
		||||
			
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        [ContextMenu("Bind")]
 | 
			
		||||
        public void BindReference()
 | 
			
		||||
        {
 | 
			
		||||
            image = transform.Find("ItemLayout/ItemImage").GetComponent<Image>();
 | 
			
		||||
            title = transform.Find("ItemLayout/Text (TMP)").GetComponent<TextMeshProUGUI>();
 | 
			
		||||
            txtPrice = transform.Find("ItemLayout/Button/Text (TMP)").GetComponent<TextMeshProUGUI>();
 | 
			
		||||
            buyButton = transform.Find("ItemLayout/Button").GetComponent<Button>();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
@@ -44,21 +44,21 @@ namespace TON
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // 포션 구매 메서드
 | 
			
		||||
        private void BuyPotion(int price, string potionType, int quantity)
 | 
			
		||||
        public void BuyPotion(ShopItemPresenter shopItem)
 | 
			
		||||
        {
 | 
			
		||||
            if (playerDataManager.goldAmount >= price)
 | 
			
		||||
            if (playerDataManager.goldAmount >= shopItem.Price.Value)
 | 
			
		||||
            {
 | 
			
		||||
                playerDataManager.UseGold(price, (isSuccess) =>
 | 
			
		||||
                playerDataManager.UseGold(shopItem.Price.Value, (isSuccess) =>
 | 
			
		||||
                {
 | 
			
		||||
                    if (isSuccess)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (potionType == "hp")
 | 
			
		||||
                        if (shopItem.PotionType.Value == "hp")
 | 
			
		||||
                        {
 | 
			
		||||
                            playerDataManager.AddPotion("HP", quantity);
 | 
			
		||||
                            playerDataManager.AddPotion("HP", shopItem.Quantity.Value);
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (potionType == "mp")
 | 
			
		||||
                        else if (shopItem.PotionType.Value == "mp")
 | 
			
		||||
                        {
 | 
			
		||||
                            playerDataManager.AddPotion("MP", quantity);
 | 
			
		||||
                            playerDataManager.AddPotion("MP", shopItem.Quantity.Value);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        UIManager.Singleton.UpdateCashData();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,47 +1,33 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace TON
 | 
			
		||||
{
 | 
			
		||||
	// MVP 패턴 : Model <> Presenter <> View
 | 
			
		||||
 | 
			
		||||
	// View
 | 
			
		||||
    public class ShopUI : UIBase
 | 
			
		||||
    {
 | 
			
		||||
        [SerializeField] private GameObject HeartPopUp;
 | 
			
		||||
        [SerializeField] private GameObject PositionPopUp;
 | 
			
		||||
        
 | 
			
		||||
        [SerializeField] private List<ShopItemUI> ShopItems;
 | 
			
		||||
 | 
			
		||||
		private ShopPresenter _presenter;
 | 
			
		||||
 | 
			
		||||
        private void Start()
 | 
			
		||||
        {
 | 
			
		||||
            _presenter = new ShopPresenter();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < ShopItems.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                ShopItems[i].Bind(_presenter.ShopItems[i]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnClickLobbyButton()
 | 
			
		||||
        {
 | 
			
		||||
            Main.Singleton.ChangeScene(SceneType.Lobby);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // HP 포션 구매 버튼 클릭 시 호출
 | 
			
		||||
        public void OnClickBuyHpPotion1Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(hpPotionPrice1, "hp", 1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnClickBuyHpPotion5Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(hpPotionPrice5, "hp", 5);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnClickBuyHpPotion20Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(hpPotionPrice20, "hp", 20);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // MP 포션 구매 버튼 클릭 시 호출
 | 
			
		||||
        public void OnClickBuyMpPotion1Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(mpPotionPrice1, "mp", 1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnClickBuyMpPotion5Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(mpPotionPrice5, "mp", 5);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnClickBuyMpPotion20Button()
 | 
			
		||||
        {
 | 
			
		||||
            BuyPotion(mpPotionPrice20, "mp", 20);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user