备份CatanBuilding瘦身独立工程
This commit is contained in:
121
Assets/Scripts/UI/Shop/GiftOneAddTwoItem.cs
Normal file
121
Assets/Scripts/UI/Shop/GiftOneAddTwoItem.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GiftOneAddTwoItem : MonoBehaviour
|
||||
{
|
||||
Tables _tables;
|
||||
Transform rewardRoot;
|
||||
List<RewardItemNew> items = new List<RewardItemNew>();
|
||||
public List<ItemData> itemData;
|
||||
public IAPItemList iAPItemList;
|
||||
int dropID;
|
||||
public int dataIndex;
|
||||
Button btn_buy;
|
||||
TMP_Text text_buy;
|
||||
GameObject done;
|
||||
Action OnBuySuccess;
|
||||
GameObject lockGo;
|
||||
RectTransform rectTransform;
|
||||
int isDone;
|
||||
private void Awake()
|
||||
{
|
||||
rewardRoot = transform.Find("reward");
|
||||
int count = rewardRoot.childCount;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
items.Add(rewardRoot.GetChild(i).GetComponent<RewardItemNew>());
|
||||
}
|
||||
btn_buy = transform.Find("btn_buy/btn_green").GetComponent<Button>();
|
||||
text_buy = transform.Find("btn_buy/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||||
done = transform.Find("done").gameObject;
|
||||
|
||||
lockGo = transform.Find("btn_buy/btn_green/Ani_Container/p_text/lock").gameObject;
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
btn_buy.onClick.AddListener(OnBuy);
|
||||
}
|
||||
public void SetData(Action action, int dropID, int IAPID, int isDone, int dataIndex, List<ItemData> itemDatas)
|
||||
{
|
||||
this.dropID = dropID;
|
||||
this.dataIndex = dataIndex;
|
||||
itemData = itemDatas;
|
||||
done.SetActive(isDone == 0);
|
||||
btn_buy.gameObject.SetActive(isDone != 0);
|
||||
this.isDone = isDone;
|
||||
lockGo.SetActive(isDone == 2);
|
||||
iAPItemList = _tables.TbIAPItemList.GetOrDefault(IAPID);
|
||||
int itemCount = itemData.Count;
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].gameObject.SetActive(i < itemCount);
|
||||
if (i < itemCount)
|
||||
{
|
||||
items[i].SetData(itemData[i]);
|
||||
items[i].SetReceived(isDone == 0);
|
||||
}
|
||||
}
|
||||
SKUDetailDataEvent sKUDetailDataEvent = new SKUDetailDataEvent(iAPItemList);
|
||||
GContext.Publish(sKUDetailDataEvent);
|
||||
text_buy.text = sKUDetailDataEvent.price;
|
||||
this.OnBuySuccess = action;
|
||||
}
|
||||
public void SetReceived()
|
||||
{
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
items[i].SetReceived(true);
|
||||
}
|
||||
done.SetActive(true);
|
||||
btn_buy.gameObject.SetActive(false);
|
||||
}
|
||||
public void PlayMove()
|
||||
{
|
||||
rectTransform.DOKill();
|
||||
rectTransform.anchoredPosition = Vector3.right * rectTransform.rect.width;
|
||||
rectTransform.DOAnchorPosX(0, 0.5f).SetEase(Ease.Linear);
|
||||
}
|
||||
async void OnBuy()
|
||||
{
|
||||
if (isDone == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (isDone == 2)
|
||||
{
|
||||
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_30"));
|
||||
return;
|
||||
}
|
||||
btn_buy.enabled = false;
|
||||
if (iAPItemList == null)
|
||||
{
|
||||
GContext.Publish(new ShowData(itemData, RewardType.Normal));
|
||||
GContext.container.Resolve<PlayerItemData>().AddItem(itemData);
|
||||
GContext.Publish(new ShowData());
|
||||
GContext.container.Resolve<FishingEventData>().SetPack1A2Index();
|
||||
OnBuySuccess?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
ShopBuyTypeData shopBuyTypeData = new ShopBuyTypeData();
|
||||
shopBuyTypeData.type = ShopBuyType.EventPack;
|
||||
shopBuyTypeData.ID = GContext.container.Resolve<FishingEventData>().Pack1A2Data.lastID;
|
||||
bool Result = await GContext.container.Resolve<PlayerShopData>().OnBuy(dropID, shopBuyTypeData, iAPItemList, itemData, RewardType.Normal);
|
||||
if (Result)
|
||||
{
|
||||
OnBuySuccess?.Invoke();
|
||||
}
|
||||
}
|
||||
btn_buy.enabled = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user