Shegotwet/Assets/Scripts/UI/ShopCard.cs

264 lines
10 KiB
C#
Raw Normal View History

using TMPro;
using UnityEngine;
using UnityEngine.UI;
2025-09-25 04:20:13 +00:00
#if UNITY_EDITOR
using UnityEditor;
[CustomEditor(typeof(ShopCard))]
2025-09-25 05:57:17 +00:00
[CanEditMultipleObjects] // 🔑 여러 오브젝트 동시 지원
2025-09-25 04:20:13 +00:00
public class ShopCardEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
2025-09-25 05:57:17 +00:00
if (GUILayout.Button("🔄 Auto Link Components (All Selected)"))
2025-09-25 04:20:13 +00:00
{
2025-09-25 05:57:17 +00:00
foreach (Object obj in targets) // 🔑 선택된 모든 ShopCard 순회
{
ShopCard shopCard = obj as ShopCard;
if (shopCard != null)
{
shopCard.AutoLink();
EditorUtility.SetDirty(shopCard); // 변경 사항 기록
}
}
2025-09-25 04:20:13 +00:00
}
}
}
#endif
public class ShopCard : MonoBehaviour
{
public string m_ID;
2025-09-25 05:57:17 +00:00
public Image i_shopitem, i_buymoney;
2025-09-24 23:10:16 +00:00
public TextMeshProUGUI t_name, t_peakefficiency;
2025-09-25 04:20:13 +00:00
public TextMeshProUGUI t_amount, t_goods;
2025-09-25 05:57:17 +00:00
public TextMeshProUGUI t_price, t_limit, t_pricelimit, t_buymoneyprice;
public GameObject go_btnbuy, go_btnbuylimit, go_btnbuymoney, go_initDesc, go_BuyComplete;
shoptabledata m_Data;
#if UNITY_EDITOR
2025-09-25 04:20:13 +00:00
// 자동 연결 함수 (버튼에서 호출)
public void AutoLink()
{
i_shopitem = DSUtil.Get_Child_T<Image>(gameObject, "i_shopitem");
2025-09-25 05:57:17 +00:00
i_buymoney = DSUtil.Get_Child_T<Image>(gameObject, "i_buymoney");
2025-09-24 23:10:16 +00:00
t_name = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_name");
t_peakefficiency = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_peakefficiency");
2025-09-25 04:20:13 +00:00
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");
2025-09-25 04:20:13 +00:00
t_limit = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_limit");
t_pricelimit = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_pricelimit");
2025-09-25 05:57:17 +00:00
t_buymoneyprice = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_buymoneyprice");
2025-09-13 21:35:38 +00:00
go_BuyComplete = DSUtil.Get_Child_GameObject(gameObject, "BuyComplete");
2025-09-25 04:20:13 +00:00
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");
2025-09-25 05:57:17 +00:00
go_btnbuymoney = DSUtil.Get_Child_GameObject(gameObject, "btn_buymoney");
}
#endif
private void Awake()
{
2025-09-25 04:20:13 +00:00
var btn = go_btnbuy.GetComponent<Button>();
btn.onClick.RemoveAllListeners();
btn.onClick.AddListener(OnClick_Button);
2025-09-25 04:20:13 +00:00
if (go_btnbuylimit != null)
{
var btnlimit = go_btnbuylimit.GetComponent<Button>();
btnlimit.onClick.RemoveAllListeners();
btnlimit.onClick.AddListener(OnClick_Button);
}
2025-09-25 05:57:17 +00:00
if (go_btnbuymoney != null)
{
var btnbuymoney = go_btnbuymoney.GetComponent<Button>();
btnbuymoney.onClick.RemoveAllListeners();
btnbuymoney.onClick.AddListener(OnClick_Button);
}
}
private void OnEnable()
{
m_Data = table_shop.Ins.Get_Data(m_ID);
2025-09-24 23:37:35 +00:00
i_shopitem.sprite = UIAtlasMgr.Ins.Get_Sprite(m_Data.s_Icon);
2025-09-25 04:20:13 +00:00
i_shopitem.SetNativeSize();
if (t_peakefficiency != null) t_peakefficiency.text = m_Data.s_PeakEffective;
2025-09-25 04:20:13 +00:00
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;
2025-09-25 04:20:13 +00:00
if (go_initDesc != null) go_initDesc.SetActive(m_Data.n_Limit > 0);
2025-09-25 05:57:17 +00:00
if (go_btnbuylimit != null) go_btnbuy.SetActive(true);
if (go_btnbuylimit != null) go_btnbuylimit.SetActive(false);
if (go_btnbuymoney != null) go_btnbuymoney.SetActive(false);
2025-09-25 04:20:13 +00:00
if (m_Data.n_Limit > 0)
{
if (go_btnbuylimit != null)
{
2025-09-25 05:57:17 +00:00
if (go_btnbuy != null) go_btnbuy.SetActive(false);
2025-09-25 04:20:13 +00:00
go_btnbuylimit.SetActive(true);
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;
}
2025-09-25 05:57:17 +00:00
if (m_Data.e_BuyType == eShopBuyType.Coin)
Set_Btn_bybuyMoney(eMoney.Gacha);
else if (m_Data.e_BuyType == eShopBuyType.Heart)
Set_Btn_bybuyMoney(eMoney.AlbumOpen);
2025-09-25 04:20:13 +00:00
}
2025-09-13 21:35:38 +00:00
Set_UI();
}
2025-09-25 05:57:17 +00:00
void Set_Btn_bybuyMoney(eMoney money)
{
i_buymoney.sprite = UIAtlasMgr.Ins.Get_Sprite(money);
t_buymoneyprice.text = m_Data.n_Price.ToString();
if (go_btnbuylimit != null) go_btnbuy.SetActive(false);
if (go_btnbuylimit != null) go_btnbuylimit.SetActive(false);
if (go_btnbuymoney != null) go_btnbuymoney.SetActive(true);
}
2025-09-13 21:35:38 +00:00
void Set_UI()
{
2025-09-25 04:20:13 +00:00
if (go_BuyComplete != null) go_BuyComplete.SetActive(!SaveMgr.Ins.CanBuyShopPackage(m_Data));
2025-09-25 05:57:17 +00:00
switch (m_Data.e_InAppInitType)
{
case eInAppInitType.One1:
case eInAppInitType.One2:
if (!SaveMgr.Ins.CanBuyShopPackage(m_Data))
gameObject.SetActive(false);
transform.parent.parent.gameObject.SetActive(SaveMgr.Ins.Shop_FullPackage_Active());
break;
case eInAppInitType.Disable_Buy1:
case eInAppInitType.Disable_Buy2:
if (!SaveMgr.Ins.CanBuyShopPackage(m_Data))
gameObject.SetActive(false);
transform.parent.parent.gameObject.SetActive(SaveMgr.Ins.Shop_FullPackage_Active());
break;
}
2025-09-25 04:20:13 +00:00
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, () =>
{
2025-09-25 04:20:13 +00:00
SaveMgr.Ins.Set_ShopReward(m_Data);
2025-09-13 21:35:38 +00:00
LobbyUI.Ins.m_ToastUI.Set(Get_BuyItemMsg());
2025-09-21 22:03:42 +00:00
var cards = gameObject.transform.parent.GetComponentsInChildren<ShopCard>();
for (int i = 0; i < cards.Length; i++)
cards[i].Set_UI();
});
break;
case eShopBuyType.AD:
2025-09-25 04:20:13 +00:00
//if (SaveMgr.Ins.CanShowShopAD())
2025-09-25 05:57:17 +00:00
if (m_Data.n_Limit == 0 || SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID) < m_Data.n_Limit)
{
ADInfo.Ins.Show_AD(false, () =>
{
2025-09-25 04:20:13 +00:00
SaveMgr.Ins.Set_ShopReward(m_Data);
LobbyUI.Ins.m_ToastUI.Set(Get_BuyItemMsg());
Set_UI();
});
}
2025-09-25 04:20:13 +00:00
else
LobbyUI.Ins.m_ToastUI.Set("광고 시청 횟수가 없습니다.");
break;
case eShopBuyType.Coin:
2025-09-25 05:57:17 +00:00
if (m_Data.n_Limit == 0 || SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID) < m_Data.n_Limit)
2025-09-13 20:18:28 +00:00
{
2025-09-25 04:20:13 +00:00
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();
}
2025-09-13 20:18:28 +00:00
}
2025-09-25 04:20:13 +00:00
else
LobbyUI.Ins.m_ToastUI.Set("오늘은 더 이상 구매하실 수 없습니다.");
break;
2025-09-25 05:57:17 +00:00
case eShopBuyType.Heart:
if (m_Data.n_Limit == 0 || SaveMgr.Ins.Get_ShopLimitCount(m_Data.s_ID) < m_Data.n_Limit)
{
if (SaveMgr.Ins.Check_Money(eMoney.AlbumOpen, m_Data.n_Price))
{
SaveMgr.Ins.Add_Money(eMoney.AlbumOpen, -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;
}
}
2025-09-13 21:35:38 +00:00
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}개를 획득했습니다.";
2025-09-13 21:35:38 +00:00
}
2025-09-25 04:20:13 +00:00
if (m_Data.b_AdRemove)
{
if (!string.IsNullOrEmpty(msg)) msg += "\n";
msg += $"광고 제거권을 획득했습니다.";
}
2025-09-25 05:57:17 +00:00
if (m_Data.n_BonusGameRefill > 0)
{
if (!string.IsNullOrEmpty(msg)) msg += "\n";
msg += $"보너스 게임 리필 횟수가 {m_Data.n_BonusGameRefill} 추가 되었습니다.";
}
2025-09-25 04:20:13 +00:00
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% 감소되었습니다.";
}
2025-09-13 21:57:57 +00:00
if (string.IsNullOrEmpty(msg)) msg = "보상이 없습니다.\n보상을 설정해 주세요!";
2025-09-13 21:35:38 +00:00
return msg;
}
}