266 lines
10 KiB
C#
266 lines
10 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
|
|
[CustomEditor(typeof(ShopCard))]
|
|
[CanEditMultipleObjects] // 🔑 여러 오브젝트 동시 지원
|
|
public class ShopCardEditor : Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.OnInspectorGUI();
|
|
|
|
if (GUILayout.Button("🔄 Auto Link Components (All Selected)"))
|
|
{
|
|
foreach (Object obj in targets) // 🔑 선택된 모든 ShopCard 순회
|
|
{
|
|
ShopCard shopCard = obj as ShopCard;
|
|
if (shopCard != null)
|
|
{
|
|
shopCard.AutoLink();
|
|
EditorUtility.SetDirty(shopCard); // 변경 사항 기록
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
public class ShopCard : MonoBehaviour
|
|
{
|
|
public string m_ID;
|
|
public Image i_shopitem, i_buymoney;
|
|
public TextMeshProUGUI t_name, t_peakefficiency;
|
|
public TextMeshProUGUI t_amount, t_goods;
|
|
public TextMeshProUGUI t_price, t_limit, t_pricelimit, t_buymoneyprice, t_sale;
|
|
public GameObject go_btnbuy, go_btnbuylimit, go_btnbuymoney, go_initDesc, go_BuyComplete;
|
|
|
|
shoptabledata m_Data;
|
|
|
|
#if UNITY_EDITOR
|
|
// 자동 연결 함수 (버튼에서 호출)
|
|
public void AutoLink()
|
|
{
|
|
i_shopitem = DSUtil.Get_Child_T<Image>(gameObject, "i_shopitem");
|
|
i_buymoney = DSUtil.Get_Child_T<Image>(gameObject, "i_buymoney");
|
|
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");
|
|
t_buymoneyprice = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_buymoneyprice");
|
|
t_sale = DSUtil.Get_Child_T<TextMeshProUGUI>(gameObject, "t_sale");
|
|
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");
|
|
go_btnbuymoney = DSUtil.Get_Child_GameObject(gameObject, "btn_buymoney");
|
|
}
|
|
#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);
|
|
}
|
|
|
|
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);
|
|
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_sale != null) t_sale.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 (go_btnbuylimit != null) go_btnbuy.SetActive(true);
|
|
if (go_btnbuylimit != null) go_btnbuylimit.SetActive(false);
|
|
if (go_btnbuymoney != null) go_btnbuymoney.SetActive(false);
|
|
if (m_Data.n_Limit > 0)
|
|
{
|
|
if (go_btnbuylimit != null)
|
|
{
|
|
if (go_btnbuy != null) go_btnbuy.SetActive(false);
|
|
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;
|
|
}
|
|
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);
|
|
}
|
|
Set_UI();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void Set_UI()
|
|
{
|
|
if (go_BuyComplete != null) go_BuyComplete.SetActive(!SaveMgr.Ins.CanBuyShopPackage(m_Data));
|
|
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;
|
|
}
|
|
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 (m_Data.n_Limit == 0 || 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 (m_Data.n_Limit == 0 || 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;
|
|
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;
|
|
}
|
|
}
|
|
|
|
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.n_BonusGameRefill > 0)
|
|
{
|
|
if (!string.IsNullOrEmpty(msg)) msg += "\n";
|
|
msg += $"보너스 게임 리필 횟수가 {m_Data.n_BonusGameRefill} 추가 되었습니다.";
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
} |