50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using Cysharp.Threading.Tasks;
|
||
using MotionFramework;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
|
||
public class UserInfoComponent : MonoBehaviour
|
||
{
|
||
public TMP_Text username;
|
||
public TMP_Text processDescribe;
|
||
public TMP_Text gameTime;
|
||
|
||
private void Start()
|
||
{
|
||
StartCountdown().Forget();
|
||
}
|
||
|
||
private async UniTaskVoid StartCountdown()
|
||
{
|
||
await UniTask.Delay(TimeSpan.FromSeconds(1));
|
||
ParsedData parsedData = MotionEngine.GetModule<InfoDataManager>().GetParsedData();
|
||
|
||
Debug.Log(parsedData.UserTime);
|
||
username.text = parsedData.Username;
|
||
|
||
int totalTime = parsedData.UserTime * 60; // Convert minutes to seconds for countdown
|
||
await Countdown(totalTime);
|
||
}
|
||
|
||
private async UniTask Countdown(int totalTime)
|
||
{
|
||
while (totalTime > 0)
|
||
{
|
||
totalTime--;
|
||
int minutes = totalTime / 60;
|
||
int seconds = totalTime % 60;
|
||
|
||
string formattedMinutes = minutes < 10 ? "0" + minutes.ToString() : minutes.ToString();
|
||
string formattedSeconds = seconds < 10 ? "0" + seconds.ToString() : seconds.ToString();
|
||
|
||
gameTime.text = $"剩余时间:{formattedMinutes}:{formattedSeconds}";
|
||
await UniTask.Delay(TimeSpan.FromSeconds(1));
|
||
}
|
||
|
||
gameTime.text = "剩余时间:00:00"; // Countdown finished
|
||
}
|
||
} |