47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class TimerestDisplay : MonoBehaviour
|
|
{
|
|
[SerializeField] private List<CanvasGroup> canvasGroups;
|
|
[SerializeField] private List<TextMeshProUGUI> Labels;
|
|
|
|
public void Init()
|
|
{
|
|
if(G.EndGameChecker.TimeRest <= 0)
|
|
{
|
|
foreach (CanvasGroup group in canvasGroups)
|
|
group.alpha = 0;
|
|
}
|
|
else
|
|
{
|
|
foreach(CanvasGroup group in canvasGroups)
|
|
group.alpha = 1;
|
|
|
|
|
|
CancellationToken ct = this.GetCancellationTokenOnDestroy();
|
|
UpdateTimers(ct).Forget();
|
|
}
|
|
}
|
|
|
|
private async UniTask UpdateTimers(CancellationToken ct)
|
|
{
|
|
while (!ct.IsCancellationRequested)
|
|
{
|
|
foreach (var label in Labels)
|
|
{
|
|
TimeSpan time = TimeSpan.FromSeconds(G.EndGameChecker.TimeRest);
|
|
label.text = time.ToString(@"mm\:ss");
|
|
}
|
|
|
|
if (G.EndGameChecker.TimeRest < 0) break; //проверить работу этой шляпы
|
|
|
|
await UniTask.Delay(1000, cancellationToken: ct);
|
|
}
|
|
}
|
|
}
|