RandomGFGoStop/Assets/Scripts/UI/StorePanel.cs

138 lines
6.8 KiB
C#

using CodeJay.Classes;
using CodeJay.Enum;
using System.Collections.Generic;
using UnityEngine;
namespace CodeJay.Enum
{
public enum EProductReward
{
Delete_Ad,
Heart,
Key
}
public enum EProductType
{
ADS,
IAP,
Gold
}
}
public class StorePanel : MonoBehaviour
{
[SerializeField] private GameObject SlotPrefab;
[SerializeField] private GameObject BuyKeySlotPrefab;
[SerializeField] private RectTransform content;
[SerializeField] private List<ProductSlot> _lstSlots;
/// <summary>
/// 0 하트, 1 키, 2 냥, 3 광고 제거, 4 무료 캐시, 5 캐시200, 6 캐시1500, 7 캐시3000, 8 무료 하트, 9 하트20, 10 하트45, 11 하트75
/// </summary>
[SerializeField] private List<Sprite> sprites;
private int BuyOneKey = 6;
List<ProductData> list_item = new List<ProductData>();
private void Awake()
{
if (GameManager.Instance != null)
{
GameManager.Event.RegistEvent(EEventType.MoveToStore_Heart, this.MoveToStore_Heart);
GameManager.Event.RegistEvent(EEventType.MoveToStore_Heart_DuringGame, this.MoveToStore_Heart);
GameManager.Event.RegistEvent(EEventType.MoveToStore_Key, this.MoveToStore_Key);
GameManager.Event.RegistEvent(EEventType.OnReturnToGameFromStore, this.OnReturnToGameFromStore);
GameManager.Event.RegistEvent(EEventType.OnSynchronizeKey, this.OnSynchronizeKey);
}
if (list_item.Count == 0)
{
list_item.Add(new ProductData("com.fgb.adsremove", EProductType.IAP, "강제 광고 제거", "강제 노출 광고 제거", 5500, sprites[3], EProductReward.Delete_Ad, 1));
list_item.Add(new ProductData("heart_free", EProductType.Gold, "일일 하트 I", "무료 하트", 0, sprites[8], EProductReward.Heart, 1));
list_item.Add(new ProductData("heart_ads", EProductType.ADS, "일일 하트 II", "광고 후 무료 하트", 0, sprites[8], EProductReward.Heart, 1));
list_item.Add(new ProductData("key_free", EProductType.Gold, "일일 캐시 I", "무료 캐시", 0, sprites[4], EProductReward.Key, 1));
list_item.Add(new ProductData("heart_cash", EProductType.Gold, "하트 1개", "보석으로 하트 구매", 200, sprites[0], EProductReward.Heart, 1));
list_item.Add(new ProductData("com.fgb.cash200", EProductType.IAP, "캐시 200", "", 1000, sprites[5], EProductReward.Key, 200));
list_item.Add(new ProductData("com.fgb.cash1500", EProductType.IAP, "캐시 1500", "", 6450, sprites[6], EProductReward.Key, 1500));
list_item.Add(new ProductData("com.fgb.cash3300", EProductType.IAP, "캐시 3300", "", 11000, sprites[7], EProductReward.Key, 3300));
list_item.Add(new ProductData("com.fgb.heart20", EProductType.IAP, "하트 20개", "", 11000, sprites[9], EProductReward.Heart, 20));
list_item.Add(new ProductData("com.fgb.heart45", EProductType.IAP, "하트 45개", "", 22000, sprites[10], EProductReward.Heart, 45));
list_item.Add(new ProductData("com.fgb.heart75", EProductType.IAP, "하트 75개", "", 33000, sprites[11], EProductReward.Heart, 75));
}
return;
_lstSlots = new List<ProductSlot>();
for (int i = 0; i < 10; i++)
{
if (i == BuyOneKey)
{
_lstSlots.Add(Instantiate(BuyKeySlotPrefab, content).GetComponent<ProductSlot>());
}
else
{
_lstSlots.Add(Instantiate(SlotPrefab, content).GetComponent<ProductSlot>());
}
}
//_lstSlots[0].SetData(new CodeJay.Classes.ProductData("ads_remove", EProductType.IAP, "강제 광고 제거", "강제 노출되는 광고를 제거 합니다.", 5500, 0, EProductReward.Delete_Ad, 1));
//_lstSlots[1].SetData(new CodeJay.Classes.ProductData("heart_free", EProductType.Gold, "일일 무료 하트 I", "무료 하트 획득!", 0, 1, EProductReward.Heart, 1));
//_lstSlots[2].SetData(new CodeJay.Classes.ProductData("heart_ads", EProductType.ADS, "일일 무료 하트 II", "광고 시청 후 무료 하트 획득!", 0, 1, EProductReward.Heart, 1));
//_lstSlots[3].SetData(new CodeJay.Classes.ProductData("heart_10", EProductType.IAP, "하트 10개 구매", "", 1000, 1, EProductReward.Heart, 10));
//_lstSlots[4].SetData(new CodeJay.Classes.ProductData("heart_60", EProductType.IAP, "하트 60개 구매", "", 5500, 1, EProductReward.Heart, 60));
//_lstSlots[5].SetData(new CodeJay.Classes.ProductData("heart_130", EProductType.IAP, "하트 130개 구매", "", 11000, 1, EProductReward.Heart, 130));
//_lstSlots[BuyOneKey].SetData(new CodeJay.Classes.ProductData("key_1", EProductType.Gold, "열쇠 1 개", "", 100000 + (250000 * (int)GameManager.DB.BuyKeyCount), 2, EProductReward.Key, 1));
//_lstSlots[7].SetData(new CodeJay.Classes.ProductData("key_20", EProductType.IAP, "열쇠 20 개", "", 11000, 2, EProductReward.Key, 10));
//_lstSlots[8].SetData(new CodeJay.Classes.ProductData("key_45", EProductType.IAP, "열쇠 45 개", "", 22000, 2, EProductReward.Key, 25));
//_lstSlots[9].SetData(new CodeJay.Classes.ProductData("key_75", EProductType.IAP, "열쇠 75 개", "", 33000, 2, EProductReward.Key, 45));
}
private void OnEnable()
{
GameManager.DB.CheckDayReset();
for (int i = 0; i < _lstSlots.Count; i++)
_lstSlots[i].Set(list_item[i]);
}
private void OnDestroy()
{
if (GameManager.Instance != null)
{
GameManager.Event.RemoveEvent(EEventType.MoveToStore_Heart, this.MoveToStore_Heart);
GameManager.Event.RemoveEvent(EEventType.MoveToStore_Heart_DuringGame, this.MoveToStore_Heart);
GameManager.Event.RemoveEvent(EEventType.MoveToStore_Key, this.MoveToStore_Key);
GameManager.Event.RemoveEvent(EEventType.OnReturnToGameFromStore, this.OnReturnToGameFromStore);
GameManager.Event.RemoveEvent(EEventType.OnSynchronizeKey, this.OnSynchronizeKey);
}
}
private void OnReturnToGameFromStore()
{
this.gameObject.SetActive(false);
}
private void MoveToStore_Heart()
{
if (this.gameObject.activeInHierarchy == false)
this.gameObject.SetActive(true);
content.anchoredPosition = new Vector2(content.anchoredPosition.x, 944f);
}
private void MoveToStore_Key()
{
// Height * 6, Spacing * 5
//content.anchoredPosition = Vector2.up * ((300 * 6) + (20 * 5));
content.anchoredPosition = new Vector2(content.anchoredPosition.x, 944f);
}
private void OnSynchronizeKey()
{
//_lstSlots[BuyOneKey].SetData(new CodeJay.Classes.ProductData("10", EProductType.Gold, "열쇠 1 개", "", 100000 + (250000 * (int)GameManager.DB.BuyKeyCount), sprites[1], EProductReward.Key, 1));
}
}