备份CatanBuilding瘦身独立工程
This commit is contained in:
173
Assets/Scripts/UI/Rod/RodBag/RodBagImprove.cs
Normal file
173
Assets/Scripts/UI/Rod/RodBag/RodBagImprove.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using Coffee.UIExtensions;
|
||||
using DG.Tweening;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RodBagImprove : MonoBehaviour
|
||||
{
|
||||
public TMP_Text btn_improve_text;
|
||||
public Button btn_improve;
|
||||
public Image up_bar;
|
||||
public TMP_Text bar_text;
|
||||
public GameObject max_text;
|
||||
public GameObject fx;
|
||||
public CanvasGroup canvasGroup;
|
||||
|
||||
public UIParticleAttractor uIParticleAttractor;
|
||||
private List<RodLevelupStats> dataList;
|
||||
PlayerFishData playerFishData;
|
||||
int allScore = 0;
|
||||
bool isMax = false;
|
||||
int level = 0;
|
||||
private void Awake()
|
||||
{
|
||||
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
||||
var _tables = GContext.container.Resolve<Tables>();
|
||||
dataList = _tables.TbRodLevelupStats.DataList;
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
btn_improve.onClick.AddListener(() =>
|
||||
{
|
||||
_ = UIManager.Instance.ShowUI(UITypes.FishingRodRewardPopupPanel);
|
||||
});
|
||||
InitLevel();
|
||||
}
|
||||
void InitLevel()
|
||||
{
|
||||
allScore = playerFishData.GetRodAllScore();
|
||||
int count = dataList.Count;
|
||||
var data = dataList[^1];
|
||||
level = count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (allScore < dataList[i].Count)
|
||||
{
|
||||
data = dataList[i];
|
||||
level = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isMax = level == count;
|
||||
max_text.SetActive(isMax);
|
||||
bar_text.gameObject.SetActive(!max_text.activeSelf);
|
||||
if (isMax)
|
||||
{
|
||||
up_bar.fillAmount = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bar_text.text = $"{allScore}/{data.Count}";
|
||||
float fillAmount = (float)allScore / data.Count;
|
||||
up_bar.fillAmount = fillAmount;
|
||||
}
|
||||
btn_improve_text.text = level.ToString();
|
||||
}
|
||||
|
||||
public async void UpLevel()
|
||||
{
|
||||
int newScore = playerFishData.GetRodAllScore();
|
||||
if (isMax || newScore == allScore)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int count = dataList.Count;
|
||||
var newdata = dataList[^1];
|
||||
int newlevel = count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (newScore < dataList[i].Count)
|
||||
{
|
||||
newdata = dataList[i];
|
||||
newlevel = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
canvasGroup.blocksRaycasts = false;
|
||||
ParticleAttractor(newScore - allScore);
|
||||
await Awaiters.Seconds(1f);
|
||||
if (up_bar == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (level != newlevel)
|
||||
{
|
||||
int oldlevel = level;
|
||||
var data = dataList[level];
|
||||
level = newlevel;
|
||||
isMax = level == count;
|
||||
up_bar.DOKill();
|
||||
up_bar.DOFillAmount(1, 0.5f).OnUpdate(() =>
|
||||
{
|
||||
bar_text.text = $"{(int)(data.Count * up_bar.fillAmount)}/{data.Count}";
|
||||
}).OnComplete(async () =>
|
||||
{
|
||||
btn_improve_text.text = level.ToString();
|
||||
bar_text.text = $"{data.Count}/{data.Count}";
|
||||
max_text.SetActive(isMax);
|
||||
bar_text.gameObject.SetActive(!max_text.activeSelf);
|
||||
GameObject go = await UIManager.Instance.ShowUI(UITypes.FishingRodRewardSettlementPopupPanel);
|
||||
if (go != null)
|
||||
{
|
||||
var panel = go.GetComponent<FishingRodRewardSettlementPopupPanel>();
|
||||
panel.Show(oldlevel);
|
||||
}
|
||||
});
|
||||
if (isMax)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await Awaiters.Seconds(0.5f);
|
||||
}
|
||||
if (up_bar==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
up_bar.DOKill();
|
||||
bar_text.text = $"{allScore}/{newdata.Count}";
|
||||
float fillAmount = (float)allScore / newdata.Count;
|
||||
up_bar.fillAmount = fillAmount;
|
||||
//新进度条
|
||||
allScore = newScore;
|
||||
fillAmount = (float)allScore / newdata.Count;
|
||||
up_bar.DOFillAmount(fillAmount, 0.5f).OnUpdate(() =>
|
||||
{
|
||||
bar_text.text = $"{(int)(allScore * up_bar.fillAmount)}/{newdata.Count}";
|
||||
}).OnComplete(() =>
|
||||
{
|
||||
bar_text.text = $"{allScore}/{newdata.Count}";
|
||||
});
|
||||
canvasGroup.blocksRaycasts = true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 资源飞入
|
||||
/// </summary>
|
||||
/// <param name="classification"></param>
|
||||
/// <returns></returns>
|
||||
public async System.Threading.Tasks.Task ParticleAttractor(int showCount)
|
||||
{
|
||||
ParticleSystem particleSystem = fx.transform.Find("Scale/quan03").GetComponent<ParticleSystem>();
|
||||
if (particleSystem != null)
|
||||
{
|
||||
particleSystem.Clear();
|
||||
|
||||
var main = particleSystem.main;
|
||||
int maxCount = main.maxParticles;
|
||||
if (showCount < maxCount)
|
||||
{
|
||||
int addCount = (int)showCount;
|
||||
main.maxParticles = addCount;
|
||||
}
|
||||
fx.SetActive(true);
|
||||
uIParticleAttractor.enabled = true;
|
||||
await Awaiters.Seconds(1.8f);
|
||||
fx.SetActive(false);
|
||||
uIParticleAttractor.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user