196 lines
5.9 KiB
C#
196 lines
5.9 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using game;
|
|
using DG.Tweening;
|
|
using UniRx;
|
|
public class RewardFishCardUpgrade : MonoBehaviour
|
|
{
|
|
class FishCard
|
|
{
|
|
public Transform root;
|
|
public FishCardUI FishCardUI;
|
|
public MapFishAttribute attribute;
|
|
public float startAttribute1;
|
|
public float startAttribute2;
|
|
|
|
public FishCard(FishData data, Transform root, float startAttribute1, float startAttribute2)
|
|
{
|
|
this.root = root;
|
|
FishCardUI = root.Find("card").GetComponent<FishCardUI>();
|
|
attribute = root.Find("card/bg_attribute").GetComponent<MapFishAttribute>();
|
|
FishCardUI.gameObject.SetActive(false);
|
|
attribute.gameObject.SetActive(false);
|
|
|
|
FishCardUI.data = data;
|
|
this.startAttribute1 = startAttribute1;
|
|
this.startAttribute2 = startAttribute2;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
FishCardUI.Init();
|
|
FishCardUI.gameObject.SetActive(true);
|
|
attribute.gameObject.SetActive(true);
|
|
attribute.SetRewardShowData(FishCardUI.data, startAttribute1, startAttribute2);
|
|
}
|
|
}
|
|
|
|
[SerializeField]
|
|
Transform tran_rewardParent;
|
|
|
|
List<FishCard> fishCards = new();
|
|
|
|
[SerializeField]
|
|
private GameObject go_row;
|
|
[SerializeField] private PanelScroll ps;
|
|
|
|
public float RewardPopSpeed = 0.1f;
|
|
|
|
[SerializeField]
|
|
private Button
|
|
btn_close,
|
|
btn_skip;
|
|
private List<GameObject> rows = new();
|
|
public bool IsShow;
|
|
int childCount;
|
|
void Init()
|
|
{
|
|
tran_rewardParent = transform.Find("ScrollView/Viewport/Content").GetComponent<Transform>();
|
|
go_row = transform.Find("ScrollView/Viewport/Content/reward_group1").gameObject;
|
|
ps = transform.Find("ScrollView").GetComponent<PanelScroll>();
|
|
btn_close = transform.Find("reward/btn_play/btn_green").GetComponent<Button>();
|
|
btn_skip = transform.Find("btn_skip").GetComponent<Button>();
|
|
gameObject.SetActive(true);
|
|
|
|
}
|
|
private void Awake()
|
|
{
|
|
btn_close.onClick.AddListener(OnClose);
|
|
btn_skip.onClick.AddListener(OnClick);
|
|
go_row.SetActive(false);
|
|
childCount = go_row.transform.childCount;
|
|
}
|
|
|
|
|
|
|
|
private int clickCount;
|
|
private bool jump;
|
|
private void OnClick()
|
|
{
|
|
if (IsShow)
|
|
{
|
|
clickCount++;
|
|
if (clickCount == 2)
|
|
{
|
|
jump = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnClose()
|
|
{
|
|
rows.ForEach(x => Destroy(x.gameObject));
|
|
rows.Clear();
|
|
IsShow = false;
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
|
|
|
|
#region Func
|
|
public async void InitAsync()
|
|
{
|
|
Init();
|
|
clickCount = 0;
|
|
jump = false;
|
|
IsShow = true;
|
|
gameObject.SetActive(true);
|
|
GameObject curParent;
|
|
btn_skip.gameObject.SetActive(true);
|
|
btn_close.gameObject.SetActive(false);
|
|
var playerFishData = GContext.container.Resolve<PlayerFishData>();
|
|
var fishCardIds = playerFishData.GetFishCardIdsCanLevelUpAll();
|
|
//var fishCardIds = playerFishData.GetFishCardIdsCanLevelUp(mapID);
|
|
var fishCardInfos = GContext.container.Resolve<Tables>().TbFishCard;
|
|
var fishInfos = GContext.container.Resolve<Tables>().TbFishData;
|
|
|
|
for (int i = 0; i < fishCardIds.Count; i += childCount)
|
|
{
|
|
curParent = Instantiate(go_row, tran_rewardParent);
|
|
// curParent.SetActive(true);
|
|
rows.Add(curParent.gameObject);
|
|
var count = fishCardIds.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);
|
|
}
|
|
await Awaiters.NextFrame;
|
|
// ps.verticalNormalizedPosition = 0f;
|
|
for (int j = 0; j < childCount; j++)
|
|
{
|
|
if (j < count)
|
|
{
|
|
var fishCardId = fishCardIds[i + j];
|
|
var fishData = fishInfos.Get(fishCardInfos.Get(fishCardId).FishID);
|
|
var slot = curParent.transform.GetChild(j);
|
|
// slot.gameObject.SetActive(true);
|
|
(var startAtrribute1, var startAtrribute2) = GetFishCardAtrributes(fishData);
|
|
|
|
fishCards.Add(new FishCard
|
|
(
|
|
fishData, slot.transform, startAtrribute1, startAtrribute2
|
|
));
|
|
|
|
}
|
|
}
|
|
}
|
|
playerFishData.AutoUpgradeFishCardAll();
|
|
|
|
|
|
foreach (var fishCard in fishCards)
|
|
{
|
|
fishCard.Init();
|
|
fishCard.root.parent.gameObject.SetActive(true);
|
|
if (jump)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
await Awaiters.NextFrame;
|
|
ps.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
|
await new WaitForSeconds(RewardPopSpeed);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
await Awaiters.NextFrame;
|
|
ps.DONormalizedPos(Vector2.zero, RewardPopSpeed);
|
|
btn_skip.gameObject.SetActive(false);
|
|
|
|
btn_close.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
private (float, float) GetFishCardAtrributes(FishData fishData)
|
|
{
|
|
|
|
int level = GContext.container.Resolve<PlayerFishData>().GetDataLevel(fishData.ID);
|
|
cfg.FishCard fishCard = GContext.container.Resolve<Tables>().TbFishCard[fishData.FishCardID];
|
|
if (level >= fishCard.MaxLevel)
|
|
{
|
|
return (fishCard.WeightMagList[fishCard.MaxLevel - 1], fishCard.DamageMagList[fishCard.MaxLevel - 1]);
|
|
}
|
|
else
|
|
{
|
|
return level == 0 ? (0f, 0f) : (fishCard.WeightMagList[level - 1], fishCard.DamageMagList[level - 1]);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|