using System; using UnityEngine; using UnityEngine.UI; using Cysharp.Threading.Tasks; using TMPro; namespace DefaultNamespace { public class UploadComManager : MonoBehaviour { public Button uploadButton; public GameObject win1; public GameObject win2; public TMP_Text text1; private string originalText; // 保存原始文本内容 public GameObject uoloadBt; public async void Start() { // 保存原始文本内容 if (text1 != null) { originalText = text1.text; } uploadButton.onClick.AddListener(async delegate { var (success, message) = await FileComponent.UploadExamFiles(); if (success) { // 成功:隐藏win1,显示win2 if (win1 != null) win1.SetActive(false); if (win2 != null) win2.SetActive(true); uoloadBt.gameObject.SetActive(false); } else { // 失败:显示错误消息,2秒后恢复原文本 await ShowErrorMessageAndRestore(message); Debug.LogError($"上传失败:{message}"); } }); } /// /// 显示错误消息并在2秒后恢复原始文本 /// /// 错误消息 private async UniTask ShowErrorMessageAndRestore(string errorMessage) { if (text1 != null) { // 显示错误消息 text1.text=$"{errorMessage}"; // 等待2秒 await UniTask.Delay(3000); // 恢复原始文本 text1.text = originalText; } } } }