198 lines
6.9 KiB
C#
198 lines
6.9 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
|
|
[CustomEditor(typeof(ShopCard))]
|
|
public class ShopCardEditor : Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.OnInspectorGUI();
|
|
|
|
ShopCard shopCard = (ShopCard)target;
|
|
|
|
if (GUILayout.Button("Auto Link Components"))
|
|
{
|
|
shopCard.AutoLink();
|
|
EditorUtility.SetDirty(shopCard); // 변경 사항 저장
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
public class ShopCard : MonoBehaviour
|
|
{
|
|
public string m_ID;
|
|
public Image i_shopitem;
|
|
public TextMeshProUGUI t_name, t_peakefficiency;
|
|
public TextMeshProUGUI t_amount, t_goods;
|
|
public TextMeshProUGUI t_price, t_limit, t_pricelimit;
|
|
public GameObject go_btnbuy, go_btnbuylimit, go_initDesc, go_BuyComplete;
|
|
|
|
shoptabledata m_Data;
|
|
|
|
#if UNITY_EDITOR
|
|
// 자동 연결 함수 (버튼에서 호출)
|
|
public void AutoLink()
|
|
{
|
|
i_shopitem = DSUtil.Get_Child_T<Image>(gameObject, "i_shopitem");
|
|
t_name = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_name");
|
|
t_peakefficiency = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_peakefficiency");
|
|
t_amount = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_amount");
|
|
t_goods = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_goods");
|
|
t_price = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_price");
|
|
t_limit = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_limit");
|
|
t_pricelimit = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_pricelimit");
|
|
go_BuyComplete = DSUtil.Get_Child_GameObject(gameObject, "BuyComplete");
|
|
go_initDesc = DSUtil.Get_Child_GameObject(gameObject, "go_initDesc");
|
|
go_btnbuy = DSUtil.Get_Child_GameObject(gameObject, "btn_buy");
|
|
go_btnbuylimit = DSUtil.Get_Child_GameObject(gameObject, "btn_buylimit");
|
|
}
|
|
#endif
|
|
|
|
private void Awake()
|
|
{
|
|
var btn = go_btnbuy.GetComponent<Button>();
|
|
btn.onClick.RemoveAllListeners();
|
|
btn.onClick.AddListener(OnClick_Button);
|
|
|
|
if (go_btnbuylimit != null)
|
|
{
|
|
var btnlimit = go_btnbuylimit.GetComponent<Button>();
|
|
btnlimit.onClick.RemoveAllListeners();
|
|
btnlimit.onClick.AddListener(OnClick_Button);
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
m_Data = table_shop.Ins.Get_Data(m_ID);
|
|
i_shopitem.sprite = UIAtlasMgr.Ins.Get_Sprite(m_Data.s_Icon);
|
|
i_shopitem.SetNativeSize();
|
|
if (t_peakefficiency != null) t_peakefficiency.text = m_Data.s_PeakEffective;
|
|
if (t_amount != null) t_amount.text = m_Data.Get_Amount();
|
|
if (t_name != null) t_name.text = m_Data.s_Name;
|
|
t_goods.text = m_Data.s_Items;
|
|
if (go_initDesc != null) go_initDesc.SetActive(m_Data.n_Limit > 0);
|
|
if (m_Data.n_Limit > 0)
|
|
{
|
|
go_btnbuy.SetActive(true);
|
|
if (go_btnbuylimit != null)
|
|
{
|
|
go_btnbuylimit.SetActive(true);
|
|
if (go_btnbuy != null)
|
|
go_btnbuy.SetActive(false);
|
|
t_pricelimit.text = m_Data.e_BuyType == eShopBuyType.IAP ? $"{m_Data.n_Price}원" : m_Data.n_Price.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (t_price != null)
|
|
{
|
|
t_price.text = m_Data.e_BuyType == eShopBuyType.IAP ? $"{m_Data.n_Price}원" : m_Data.n_Price.ToString();
|
|
t_price.transform.localPosition = !string.IsNullOrEmpty(m_Data.s_PeakEffective) ? Vector3.up * 10f : Vector3.zero;
|
|
}
|
|
}
|
|
Set_UI();
|
|
}
|
|
|
|
void Set_UI()
|
|
{
|
|
if (go_BuyComplete != null) go_BuyComplete.SetActive(!SaveMgr.Ins.CanBuyShopPackage(m_Data));
|
|
if (t_limit != null) t_limit.text = $"{SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID)}/{m_Data.n_Limit}";
|
|
}
|
|
|
|
public void OnClick_Button()
|
|
{
|
|
switch (m_Data.e_BuyType)
|
|
{
|
|
case eShopBuyType.IAP:
|
|
InappInfo.Ins.BuyProduct(m_ID, () =>
|
|
{
|
|
SaveMgr.Ins.Set_ShopReward(m_Data);
|
|
|
|
LobbyUI.Ins.m_ToastUI.Set(Get_BuyItemMsg());
|
|
var cards = gameObject.transform.parent.GetComponentsInChildren<ShopCard>();
|
|
for (int i = 0; i < cards.Length; i++)
|
|
cards[i].Set_UI();
|
|
});
|
|
break;
|
|
case eShopBuyType.AD:
|
|
//if (SaveMgr.Ins.CanShowShopAD())
|
|
if (SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID) < m_Data.n_Limit)
|
|
{
|
|
ADInfo.Ins.Show_AD(false, () =>
|
|
{
|
|
SaveMgr.Ins.Set_ShopReward(m_Data);
|
|
LobbyUI.Ins.m_ToastUI.Set(Get_BuyItemMsg());
|
|
Set_UI();
|
|
});
|
|
}
|
|
else
|
|
LobbyUI.Ins.m_ToastUI.Set("광고 시청 횟수가 없습니다.");
|
|
break;
|
|
case eShopBuyType.Coin:
|
|
if (SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID) < m_Data.n_Limit)
|
|
{
|
|
if (SaveMgr.Ins.Check_Money(eMoney.Gacha, m_Data.n_Price))
|
|
{
|
|
SaveMgr.Ins.Add_Money(eMoney.Gacha, -m_Data.n_Price);
|
|
SaveMgr.Ins.Set_ShopReward(m_Data);
|
|
LobbyUI.Ins.m_ToastUI.Set(Get_BuyItemMsg());
|
|
Set_UI();
|
|
}
|
|
}
|
|
else
|
|
LobbyUI.Ins.m_ToastUI.Set("오늘은 더 이상 구매하실 수 없습니다.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
string Get_BuyItemMsg()
|
|
{
|
|
var msg = "";
|
|
|
|
if (m_Data.n_RewardHeart > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"앨범 오픈 재화 {m_Data.n_RewardHeart}개를 획득했습니다.";
|
|
}
|
|
|
|
if (m_Data.n_RewardChatCoin > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"채팅 코인 {m_Data.n_RewardChatCoin}개를 획득했습니다.";
|
|
}
|
|
|
|
if (m_Data.n_RewardGacha > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"뽑기 재화 {m_Data.n_RewardGacha}개를 획득했습니다.";
|
|
}
|
|
|
|
if (m_Data.b_AdRemove)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"광고 제거권을 획득했습니다.";
|
|
}
|
|
|
|
if (m_Data.b_InfinityMiniGame)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"수집 게임 무제한 입장을 획득했습니다.";
|
|
}
|
|
|
|
if (m_Data.b_LuckyGameCharge)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"뽑기 무료 충전 시간이 90% 감소되었습니다.";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(msg)) msg = "보상이 없습니다.\n보상을 설정해 주세요!";
|
|
return msg;
|
|
}
|
|
|
|
} |