Shegotwet/Assets/Scripts/UI/ShopCard.cs

66 lines
2.2 KiB
C#

using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ShopCard : MonoBehaviour
{
public string m_ID;
public Image i_shopitem;
public TextMeshProUGUI t_peakefficiency;
public TextMeshProUGUI t_goods;
public TextMeshProUGUI t_price;
shoptabledata m_Data;
#if UNITY_EDITOR
private void Reset()
{
i_shopitem = DSUtil.Get_Child_T<Image>(gameObject, "i_shopitem");
t_peakefficiency = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_peakefficiency");
t_goods = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_goods");
t_price = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_price");
}
#endif
private void Awake()
{
var btn = DSUtil.Get_Child_T<Button>(gameObject, "btn_buy");
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(OnClick_Button);
}
private void OnEnable()
{
m_Data = table_shop.Ins.Get_Data(m_ID);
if (t_peakefficiency != null) t_peakefficiency.text = m_Data.s_PeakEffective;
t_goods.text = m_Data.s_Items;
t_price.text = m_Data.e_BuyType == eShopBuyType.IAP ? $"\\{m_Data.n_Price}" : m_Data.n_Price.ToString();
}
public void OnClick_Button()
{
switch (m_Data.e_BuyType)
{
case eShopBuyType.IAP:
break;
case eShopBuyType.AD:
if (SaveMgr.Ins.CanShowShopAD())
{
// TODO : 광고 보기
SaveMgr.Ins.Add_Money(eMoney.Chat, m_Data.n_RewardChatCoin);
SaveMgr.Ins.Add_ShopADTime(m_Data.n_ADSec);
LobbyUI.Ins.m_ToastUI.Set($"채팅 코인 {m_Data.n_RewardChatCoin}개를 획득했습니다.");
}
break;
case eShopBuyType.Coin:
if (SaveMgr.Ins.Check_Money(eMoney.AlbumOpen, m_Data.n_Price))
{
SaveMgr.Ins.Add_Money(eMoney.AlbumOpen, -m_Data.n_Price);
SaveMgr.Ins.Add_Money(eMoney.Chat, m_Data.n_RewardChatCoin);
SaveMgr.Ins.Save();
LobbyUI.Ins.m_ToastUI.Set($"채팅 코인 {m_Data.n_RewardChatCoin}개를 획득했습니다.");
}
break;
}
}
}