122 lines
3.8 KiB
C#
122 lines
3.8 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using Cysharp.Threading.Tasks;
|
||
using DefaultNamespace;
|
||
using DefaultNamespace.Dto;
|
||
using DefaultNamespace.ProcessMode;
|
||
using MotionFramework;
|
||
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
|
||
using Newtonsoft.Json;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UserInfoComponent : MonoBehaviour
|
||
{
|
||
public TMP_Text username;
|
||
public TMP_Text processDescribe;
|
||
public TMP_Text processMessage;
|
||
public TMP_Text gameTime;
|
||
|
||
public GameObject SubmitBt;
|
||
|
||
|
||
public void Init()
|
||
{
|
||
MotionEngine.GetModule<AnimationProcessManager>().OnStepProcessMessage += SendMessagePrompt;
|
||
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
|
||
SubmitBt.GetComponent<Button>().onClick.AddListener(Submit);
|
||
|
||
StartCountdown().Forget();
|
||
}
|
||
|
||
private void SendMessagePrompt(string message)
|
||
{
|
||
processMessage.text = message;
|
||
}
|
||
|
||
private async UniTaskVoid StartCountdown()
|
||
{
|
||
await UniTask.Delay(TimeSpan.FromSeconds(1));
|
||
ParsedData parsedData = MotionEngine.GetModule<InfoDataManager>().GetParsedData();
|
||
ProcessMode pm = MotionEngine.GetModule<DataConfigManager>().GetProcessMode();
|
||
gameTime.gameObject.SetActive(false);
|
||
processMessage.gameObject.SetActive(true);
|
||
SubmitBt.SetActive(true);
|
||
switch (pm)
|
||
{
|
||
case ProcessMode.Teaching:
|
||
processDescribe.text = "模式:教学实训"; SubmitBt.SetActive(false);
|
||
break;
|
||
case ProcessMode.Training:
|
||
processDescribe.text = "模式:培训实训";
|
||
break;
|
||
case ProcessMode.Practice:
|
||
processDescribe.text = "模式:练习实训";
|
||
break;
|
||
case ProcessMode.Assessment:
|
||
processDescribe.text = "模式:考核模式";
|
||
gameTime.gameObject.SetActive(true);
|
||
processMessage.gameObject.SetActive(false);
|
||
break;
|
||
default:
|
||
throw new ArgumentOutOfRangeException();
|
||
}
|
||
|
||
|
||
//Debug.Log("parsedData.UserTime" + parsedData.UserTime);
|
||
username.text = parsedData.Username;
|
||
|
||
int totalTime = parsedData.UserTime * 60;
|
||
await Countdown(totalTime);
|
||
}
|
||
|
||
private async UniTask Countdown(int totalTime)
|
||
{
|
||
while (totalTime > 5395)
|
||
{
|
||
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";
|
||
}
|
||
|
||
|
||
public async void Submit()
|
||
{
|
||
|
||
ParsedData parsedData = MotionEngine.GetModule<InfoDataManager>().GetParsedData();
|
||
|
||
|
||
MotionEngine.GetModule<AnimationProcessManager>().CalculateTotalScore();
|
||
|
||
SubmitScoreData sub = new SubmitScoreData();
|
||
sub.userName = parsedData.SceneName;
|
||
sub.userId = parsedData.UserId;
|
||
sub.examId = parsedData.ExamId;
|
||
sub.classId = parsedData.ClassId;
|
||
sub.useTime = parsedData.UserTime.ToString();
|
||
sub.examClassId = parsedData.ExamClassId.ToString();
|
||
sub.stepList = MotionEngine.GetModule<AnimationProcessManager>().GetSubmitScoreStepList();
|
||
|
||
string js = JsonConvert.SerializeObject(sub);
|
||
|
||
Debug.Log(js);
|
||
string json = await MotionEngine.GetModule<WebRequestManager>().PostJsonAsync(APIs.SimulationScore, js, (ste) => { });
|
||
Debug.Log(json);
|
||
}
|
||
} |