备份CatanBuilding瘦身独立工程
This commit is contained in:
422
Assets/Scripts/UI/RewardPopup/RewardBox.cs
Normal file
422
Assets/Scripts/UI/RewardPopup/RewardBox.cs
Normal file
@@ -0,0 +1,422 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RewardBox : RewardPopupBase
|
||||
{
|
||||
[Range(0f, 3.5f)]
|
||||
public float CannotClickTimer;
|
||||
Tables _tables;
|
||||
public Animation anim;
|
||||
public Animation[] boxGo;
|
||||
public Button btn_click;
|
||||
public Button btn_close;
|
||||
public Button btn_next;
|
||||
public Button btn_all;
|
||||
public FishCardUI[] fishCardAttributes;
|
||||
public Animation[] gameObjects;
|
||||
List<ItemData> itemDataCards = new List<ItemData>();
|
||||
public List<DropFishCardData> itemDataGifts = new List<DropFishCardData>();
|
||||
GameObject reward_layout;
|
||||
|
||||
List<Transform> trans = new List<Transform>();
|
||||
[SerializeField]
|
||||
private Transform tran_rewardParent;
|
||||
[SerializeField]
|
||||
private GameObject go_row;
|
||||
[SerializeField] private PanelScroll ps;
|
||||
|
||||
public float RewardPopSpeed = 0.075f;
|
||||
|
||||
private List<GameObject> rows = new();
|
||||
public bool IsShow;
|
||||
int childCount;
|
||||
int Quality;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
anim = GetComponent<Animation>();
|
||||
btn_click = GetComponent<Button>();
|
||||
btn_close = transform.Find("reward/btn_receive/btn_green").GetComponent<Button>();
|
||||
btn_next = transform.Find("reward/btn_next/btn_green").GetComponent<Button>();
|
||||
btn_all = transform.Find("reward/btn_open_all/btn_green").GetComponent<Button>();
|
||||
boxGo = new Animation[5];
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
boxGo[i] = transform.Find($"icon_box/icon_box_{i + 1}").GetComponent<Animation>();
|
||||
}
|
||||
fishCardAttributes = new FishCardUI[2];
|
||||
fishCardAttributes[0] = transform.Find("card").GetComponent<FishCardUI>();
|
||||
fishCardAttributes[1] = transform.Find("cardNext").GetComponent<FishCardUI>();
|
||||
gameObjects = new Animation[2];
|
||||
gameObjects[0] = transform.Find("card").GetComponent<Animation>();
|
||||
gameObjects[1] = transform.Find("cardNext").GetComponent<Animation>();
|
||||
Transform tran;
|
||||
reward_layout = transform.Find("reward_layout").gameObject;
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
for (int j = 1; j < 4; j++)
|
||||
{
|
||||
tran = transform.Find($"reward_layout/reward_group{i}/reward{j}");
|
||||
trans.Add(tran);
|
||||
}
|
||||
}
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
go_row.SetActive(false);
|
||||
childCount = go_row.transform.childCount;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
receive.SetActive(true);
|
||||
GContext.Publish(new VibrationData(HapticTypes.Success));
|
||||
btn_close.onClick.AddListener(OnClickClose);
|
||||
btn_all.onClick.AddListener(ShowAll);
|
||||
btn_next.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
void OnClickClose()
|
||||
{
|
||||
if (itemDataGifts.Count > 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnClose();
|
||||
}
|
||||
}
|
||||
|
||||
//双击跳过
|
||||
void DoubleClickSkip()
|
||||
{
|
||||
OnClickSkip();
|
||||
}
|
||||
void OnClickSkip()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
anim.Play("RewardPopupPanel_reward_box_end");
|
||||
StartCoroutine(SetShowPicture());
|
||||
btn_click.onClick.RemoveAllListeners();
|
||||
gameObjects[0].gameObject.SetActive(false);
|
||||
gameObjects[1].gameObject.SetActive(false);
|
||||
}
|
||||
IEnumerator SetShowPicture()
|
||||
{
|
||||
reward_layout.SetActive(true);
|
||||
FishCardUI pictureAttribute;
|
||||
GameObject go;
|
||||
int allCount = 0;
|
||||
List<GameObject> cards = new List<GameObject>();
|
||||
foreach (var itemData in itemDataCards)
|
||||
{
|
||||
Item item = _tables.TbItem[itemData.id];
|
||||
|
||||
var fishCard = _tables.TbFishCard.GetOrDefault(item.RedirectID);
|
||||
var picture = _tables.TbFishData[fishCard.FishID];
|
||||
if (picture != null)
|
||||
{
|
||||
int addCount = Mathf.RoundToInt(itemData.count);
|
||||
go = trans[allCount].gameObject;
|
||||
go.SetActive(true);
|
||||
pictureAttribute = go.transform.Find("card").GetComponent<FishCardUI>();
|
||||
pictureAttribute.data = picture;
|
||||
pictureAttribute.curShowNum = (int)itemData.curCount + addCount;
|
||||
pictureAttribute.Init();
|
||||
pictureAttribute.SetNum(addCount);
|
||||
pictureAttribute.transfer.gameObject.SetActive(false);
|
||||
pictureAttribute.gameObject.SetActive(false);
|
||||
if (itemData.exchangeItemData != null)
|
||||
{
|
||||
ExchangeItemData exchangeItemData = itemData.exchangeItemData;
|
||||
if (exchangeItemData.exchangeCount > 0)
|
||||
{
|
||||
pictureAttribute.transfer.SetData(exchangeItemData.exchangeId, $"x{exchangeItemData.exchangeCount}");
|
||||
pictureAttribute.transfer.gameObject.SetActive(true);
|
||||
|
||||
var flyItem = _tables.TbItem.GetOrDefault(exchangeItemData.exchangeId);
|
||||
var showCount = exchangeItemData.exchangeCount;
|
||||
ResAddEvent resAddEvent = new ResAddEvent(flyItem.ID, flyItem.Type, flyItem.SubType);
|
||||
resAddEvent.addCount = showCount;
|
||||
GContext.Publish(resAddEvent);
|
||||
}
|
||||
}
|
||||
cards.Add(pictureAttribute.gameObject);
|
||||
allCount++;
|
||||
if (allCount >= trans.Count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
{
|
||||
cards[i].SetActive(true);
|
||||
yield return new WaitForSeconds(RewardPopSpeed);
|
||||
}
|
||||
AutoClose();
|
||||
}
|
||||
void ShowAll()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
gameObject.SetActive(false);
|
||||
for (int i = 0; i < boxGo.Length; i++)
|
||||
{
|
||||
boxGo[i].gameObject.SetActive(false);
|
||||
}
|
||||
for (int i = 0; i < trans.Count; i++)
|
||||
{
|
||||
trans[i].gameObject.SetActive(false);
|
||||
}
|
||||
reward_layout.SetActive(false);
|
||||
btn_click.onClick.RemoveAllListeners();
|
||||
btn_click.onClick.AddListener(OnClick);
|
||||
gameObjects[0].gameObject.SetActive(false);
|
||||
gameObjects[1].gameObject.SetActive(false);
|
||||
List<ItemData> dropItems = new List<ItemData>();
|
||||
for (int i = 0; itemDataGifts.Count > 0; i++)
|
||||
{
|
||||
DropFishCardData dropFishCardData = itemDataGifts[0];
|
||||
itemDataCards = dropFishCardData.FishCardItemList;
|
||||
dropItems.AddRange(itemDataCards);
|
||||
itemDataGifts.Remove(dropFishCardData);
|
||||
}
|
||||
receive.SetActive(true);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
ps.gameObject.SetActive(true);
|
||||
StartCoroutine(InitAsync(dropItems));
|
||||
btn_close.gameObject.SetActive(false);
|
||||
btn_next.gameObject.SetActive(false);
|
||||
btn_all.gameObject.SetActive(false);
|
||||
anim.Play("RewardPopupPanel_reward_box_end");
|
||||
}
|
||||
|
||||
public ItemData exchangeItemData;
|
||||
|
||||
public void Show()
|
||||
{
|
||||
receive.SetActive(true);
|
||||
|
||||
gameObject.SetActive(true);
|
||||
ps.gameObject.SetActive(false);
|
||||
gameObjects[0].gameObject.SetActive(false);
|
||||
gameObjects[1].gameObject.SetActive(false);
|
||||
for (int i = 0; i < trans.Count; i++)
|
||||
{
|
||||
trans[i].gameObject.SetActive(false);
|
||||
}
|
||||
btn_click.onClick.RemoveAllListeners();
|
||||
DropFishCardData dropFishCardData = itemDataGifts[0];
|
||||
itemDataCards = dropFishCardData.FishCardItemList;
|
||||
itemDataGifts.Remove(dropFishCardData);
|
||||
if (exchangeItemData == null && dropFishCardData.exchangeItemData != null)
|
||||
{
|
||||
exchangeItemData = dropFishCardData.exchangeItemData;
|
||||
InitResource(new List<ItemData>() { exchangeItemData });
|
||||
}
|
||||
Show(dropFishCardData.ItemID);
|
||||
StartCoroutine(ShowItem());
|
||||
|
||||
btn_close.gameObject.SetActive(itemDataGifts.Count == 0);
|
||||
btn_next.gameObject.SetActive(itemDataGifts.Count > 0);
|
||||
btn_all.gameObject.SetActive(itemDataGifts.Count > 1);
|
||||
}
|
||||
public void Show(int id)
|
||||
{
|
||||
for (int i = 0; i < boxGo.Length; i++)
|
||||
{
|
||||
boxGo[i].gameObject.SetActive(false);
|
||||
}
|
||||
Quality = 0;
|
||||
Item item = _tables.TbItem.GetOrDefault(id);
|
||||
if (item != null)
|
||||
{
|
||||
Quality = item.Quality - 1;
|
||||
if (Quality > 4)
|
||||
{
|
||||
Quality = 4;
|
||||
}
|
||||
}
|
||||
GameObject box = boxGo[Quality].gameObject;
|
||||
Image logo = box.transform.Find("box/logo").GetComponent<Image>();
|
||||
Image num = box.transform.Find("box/num").GetComponent<Image>();
|
||||
IUIService uiService = GContext.container.Resolve<IUIService>();
|
||||
List<string> BgNameList;
|
||||
if (item.SubType == 1)
|
||||
{
|
||||
var fishCard = GContext.container.Resolve<Tables>().TbFishCardDrop.GetOrDefault(item.RedirectID);
|
||||
BgNameList = fishCard.BgNameList;
|
||||
}
|
||||
else
|
||||
{
|
||||
var fishCard = GContext.container.Resolve<Tables>().TbGeneralCardWeight.GetOrDefault(item.RedirectID);
|
||||
BgNameList = fishCard.BgNameList;
|
||||
}
|
||||
uiService.SetImageSprite(logo, BgNameList[1], BasePanel.PanelName);
|
||||
uiService.SetImageSprite(num, BgNameList[2], BasePanel.PanelName);
|
||||
box.gameObject.SetActive(true);
|
||||
boxGo[Quality].Play("box_open");
|
||||
boxGo[Quality].Sample();
|
||||
}
|
||||
IEnumerator ShowItem()
|
||||
{
|
||||
yield return new WaitForSeconds(CannotClickTimer);
|
||||
btn_click.onClick.AddListener(DoubleClickSkip);
|
||||
yield return new WaitForSeconds(3.5f - CannotClickTimer);
|
||||
int curIndex = 0;
|
||||
|
||||
FishCardUI pictureAttribute;
|
||||
|
||||
foreach (var itemData in itemDataCards)
|
||||
{
|
||||
Item item = _tables.TbItem[itemData.id];
|
||||
var fishCard = _tables.TbFishCard.GetOrDefault(item.RedirectID);
|
||||
var picture = _tables.TbFishData[fishCard.FishID];
|
||||
if (picture != null)
|
||||
{
|
||||
int addCount = Mathf.RoundToInt(itemData.count);
|
||||
gameObjects[curIndex].gameObject.SetActive(true);
|
||||
gameObjects[curIndex].Play("card_show");
|
||||
pictureAttribute = fishCardAttributes[curIndex];
|
||||
pictureAttribute.curShowNum = (int)itemData.curCount + addCount;
|
||||
pictureAttribute.data = picture;
|
||||
pictureAttribute.Init();
|
||||
pictureAttribute.SetNum(addCount);
|
||||
curIndex++;
|
||||
if (curIndex >= fishCardAttributes.Length)
|
||||
{
|
||||
curIndex = 0;
|
||||
}
|
||||
yield return new WaitForSeconds(0.7f);
|
||||
}
|
||||
}
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
OnClickSkip();
|
||||
}
|
||||
|
||||
IEnumerator AutoCloseCoroutine()
|
||||
{
|
||||
yield return new WaitForSeconds(3f);
|
||||
if (isAutoClose)
|
||||
{
|
||||
if (itemDataGifts.Count > 1)
|
||||
{
|
||||
ShowAll();
|
||||
}
|
||||
else if (itemDataGifts.Count > 0)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
OnClose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator InitAsync(List<ItemData> dropItems)
|
||||
{
|
||||
clickCount = 0;
|
||||
jump = false;
|
||||
IsShow = true;
|
||||
GameObject curParent;
|
||||
btn_close.gameObject.SetActive(false);
|
||||
|
||||
for (int i = 0; i < dropItems.Count; i += childCount)
|
||||
{
|
||||
curParent = Instantiate(go_row, tran_rewardParent);
|
||||
curParent.SetActive(true);
|
||||
rows.Add(curParent.gameObject);
|
||||
var count = dropItems.Count - i;
|
||||
for (int j = 0; j < childCount; j++)
|
||||
{
|
||||
curParent.transform.GetChild(j).gameObject.SetActive(j < count);
|
||||
curParent.transform.GetChild(j).GetChild(0).gameObject.SetActive(false);
|
||||
}
|
||||
yield return Awaiters.NextFrame;
|
||||
ps.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
||||
for (int j = 0; j < childCount; j++)
|
||||
{
|
||||
if (j < count)
|
||||
{
|
||||
var itemData = dropItems[i + j];
|
||||
Item item = _tables.TbItem[itemData.id];
|
||||
curParent.transform.GetChild(j).gameObject.SetActive(true);
|
||||
var pictureAttribute = curParent.transform.GetChild(j).GetChild(0).GetComponent<FishCardUI>();
|
||||
var fishCard = _tables.TbFishCard.GetOrDefault(item.RedirectID);
|
||||
var picture = _tables.TbFishData[fishCard.FishID];
|
||||
if (picture != null)
|
||||
{
|
||||
int addCount = Mathf.RoundToInt(itemData.count);
|
||||
pictureAttribute.gameObject.SetActive(true);
|
||||
pictureAttribute.data = picture;
|
||||
pictureAttribute.curShowNum = (int)itemData.curCount + addCount;
|
||||
pictureAttribute.Init();
|
||||
pictureAttribute.SetNum(addCount);
|
||||
pictureAttribute.transfer.gameObject.SetActive(false);
|
||||
if (itemData.exchangeItemData != null)
|
||||
{
|
||||
ExchangeItemData exchangeItemData = itemData.exchangeItemData;
|
||||
if (exchangeItemData.exchangeCount > 0)
|
||||
{
|
||||
pictureAttribute.transfer.SetData(exchangeItemData.exchangeId, $"x{exchangeItemData.exchangeCount}");
|
||||
pictureAttribute.transfer.gameObject.SetActive(true);
|
||||
var flyItem = _tables.TbItem.GetOrDefault(exchangeItemData.exchangeId);
|
||||
var showCount = exchangeItemData.exchangeCount;
|
||||
ResAddEvent resAddEvent = new ResAddEvent(flyItem.ID, flyItem.Type, flyItem.SubType);
|
||||
resAddEvent.addCount = showCount;
|
||||
GContext.Publish(resAddEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jump)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return new WaitForSeconds(RewardPopSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
yield return Awaiters.NextFrame;
|
||||
ps.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
||||
btn_close.gameObject.SetActive(true);
|
||||
AutoClose();
|
||||
}
|
||||
|
||||
|
||||
private int clickCount;
|
||||
private bool jump;
|
||||
private void OnClick()
|
||||
{
|
||||
if (IsShow)
|
||||
{
|
||||
clickCount++;
|
||||
if (clickCount == 2)
|
||||
{
|
||||
jump = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClose()
|
||||
{
|
||||
receive.SetActive(false);
|
||||
|
||||
StopCoroutine("AutoCloseCoroutine");
|
||||
rows.ForEach(x => Destroy(x.gameObject));
|
||||
rows.Clear();
|
||||
IsShow = false;
|
||||
GContext.Publish(new ShowData(RewardType.Destroy));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user