84 lines
2.5 KiB
C#
84 lines
2.5 KiB
C#
using System.Collections.Generic;
|
|
using asap.core;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Threading.Tasks;
|
|
using DG.Tweening;
|
|
|
|
public class EventPartnerStatueBuildProgressView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image[] bars;
|
|
[SerializeField] private TMP_Text[] scoreTextList;
|
|
[SerializeField] private RewardItemNew[] rewards;
|
|
// private IReadOnlyList<float> _progressMark = new List<float>() { 0f, 0.2f, 0.4f, 0.6f, 0.8f, 1f, 1f };
|
|
|
|
public void Init(EventPartnerStatueBuildProgressData data)
|
|
{
|
|
// bar.fillAmount = Mathf.Lerp(_progressMark[data.Stage], _progressMark[data.Stage + 1], data.Progress);
|
|
for (int i = 0; i < bars.Length; i++)
|
|
{
|
|
if (i == data.Stage)
|
|
bars[i].fillAmount = data.Progress;
|
|
else if (i < data.Stage)
|
|
bars[i].fillAmount = 1;
|
|
else
|
|
bars[i].fillAmount = 0;
|
|
}
|
|
for (int i = 0; i < scoreTextList.Length; i++)
|
|
scoreTextList[i].text = data.Scores[i].ToString();
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
rewards[i].SetData(data.RewardList[i]);
|
|
rewards[i].SetReceived(i < data.Stage);
|
|
}
|
|
}
|
|
|
|
public async void OnBuild(int newScore)
|
|
{
|
|
try
|
|
{
|
|
await OnBuildAsync(newScore);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
public async Task OnBuildAsync(int newScore)
|
|
{
|
|
// var progress = GetBarProgress(newScore);
|
|
// bar.DOFillAmount(progress, 0.5f);
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
var stage = arc.TableContext.GetStageFromTotalScore(newScore);
|
|
var progress = arc.TableContext.GetPercentageWithinStage(newScore);
|
|
// var progressList = new List<float>();
|
|
for (int i = 0; i < bars.Length; i++)
|
|
{
|
|
float p;
|
|
if (i == stage)
|
|
p = progress;
|
|
else if (i < stage)
|
|
p = 1;
|
|
else
|
|
p = 0;
|
|
if (p - bars[i].fillAmount > 1e-7)
|
|
await bars[i].DOFillAmount(p, 0.5f).AsyncWaitForCompletion();
|
|
if (p >= 1.0f)
|
|
rewards[i].SetReceived(true);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public class EventPartnerStatueBuildProgressData
|
|
{
|
|
public int Stage;
|
|
public int[] Scores;
|
|
public float Progress;
|
|
public List<ItemData> RewardList;
|
|
}
|