82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GameCore;
|
|
using DG.Tweening;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
|
|
public class SocialRushTaskView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image bar;
|
|
[SerializeField] private TMP_Text progressText;
|
|
[SerializeField] private BingoTimer timer;
|
|
[SerializeField] private RewardItemNew reward;
|
|
[SerializeField] private Animation ani;
|
|
private int _currentProgress;
|
|
private float _progressIncreaseDuration = 0.5f;
|
|
|
|
public void Init(SocialRushTaskViewData data, float progressIncreaseDuration)
|
|
{
|
|
bar.fillAmount = data.Percentage;
|
|
progressText.text = data.ProgressText;
|
|
reward.SetData(data.Item);
|
|
timer.Init(data.TimerData);
|
|
_currentProgress = data.CurrentProgressWithinStage;
|
|
_progressIncreaseDuration = progressIncreaseDuration;
|
|
}
|
|
|
|
public async void Set(int progress, int end, ItemData itemData)
|
|
{
|
|
try
|
|
{
|
|
await SetAsync(progress, end, itemData);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
public async Task SetAsync(int progress, int end, ItemData itemData)
|
|
{
|
|
ani.Play("EventSocialRushCommonRewardRefresh");
|
|
await Task.Delay(TimeSpan.FromSeconds(30f / 60));
|
|
reward.SetData(itemData);
|
|
await Task.Delay(TimeSpan.FromSeconds(10f / 60));
|
|
bar.fillAmount = (float)progress / end;
|
|
_currentProgress = progress;
|
|
progressText.text = $"{progress}/{end}";
|
|
}
|
|
|
|
public async void PlayProgress(int progress, int end)
|
|
{
|
|
try
|
|
{
|
|
await PlayProgressAsync(progress, end);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
public async Task PlayProgressAsync(int progress, int end)
|
|
{
|
|
var percentage = (float)progress / end;
|
|
bar.DOFillAmount(percentage, _progressIncreaseDuration);
|
|
DOTween.To(() => _currentProgress, v => _currentProgress = v, progress, _progressIncreaseDuration)
|
|
.OnUpdate(() => progressText.text = $"{_currentProgress}/{end}");
|
|
await Task.Delay(TimeSpan.FromSeconds(_progressIncreaseDuration));
|
|
}
|
|
}
|
|
|
|
public class SocialRushTaskViewData
|
|
{
|
|
public float Percentage;
|
|
public string ProgressText;
|
|
public ItemData Item;
|
|
public ITimerContext TimerData;
|
|
public int CurrentProgressWithinStage;
|
|
}
|