94 lines
3.0 KiB
C#
94 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class ShowExamItem : MonoBehaviour
|
|
{
|
|
public List<GameObject> List_Task;
|
|
string TaskName;
|
|
int i;
|
|
void Start()
|
|
{
|
|
//隐藏所有项
|
|
for (i = 0; i < List_Task.Count; i++)
|
|
List_Task[i].SetActive(false);
|
|
for (i = 1; i <= 10; i++)
|
|
{
|
|
TaskName = PlayerPrefs.GetString("Exam_" + i, "");
|
|
if (TaskName != "")
|
|
{
|
|
List_Task[i - 1].gameObject.SetActive(true);
|
|
List_Task[i - 1].transform.GetChild(0).GetComponent<Text>().text = TaskName;
|
|
if (PlayerPrefs.GetInt("Join_" + i) == 1)//已参加
|
|
{
|
|
List_Task[i - 1].transform.GetComponent<Button>().interactable = false;
|
|
List_Task[i - 1].transform.GetChild(1).gameObject.SetActive(false);
|
|
List_Task[i - 1].transform.GetChild(2).gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void SetTaskNum(int n)
|
|
{
|
|
PlayerPrefs.SetInt("TaskNum", n);
|
|
}
|
|
public void SelectTask(Text taskText)
|
|
{
|
|
PlayerPrefs.SetString("Task", taskText.text);
|
|
SceneManager.LoadScene("Operation");
|
|
}
|
|
|
|
string SubmitStr;
|
|
TimeSpan ts;
|
|
/// <summary>
|
|
/// 提交分数
|
|
/// </summary>
|
|
public void SubmitScore()
|
|
{
|
|
//各作业任务详细
|
|
SubmitStr = "";
|
|
for (i = 1; i <= 10; i++)
|
|
{
|
|
TaskName = PlayerPrefs.GetString("Exam_" + i);
|
|
if (TaskName != "")
|
|
{
|
|
SubmitStr += "[TaskName:" + TaskName;
|
|
SubmitStr += ",UseTime:" + PlayerPrefs.GetInt("UseTime_" + i);
|
|
SubmitStr += ",Score:" + PlayerPrefs.GetInt("Score_" + i) + "],";
|
|
}
|
|
}
|
|
Debug.Log(SubmitStr);
|
|
//总时间
|
|
ts = DateTime.Now - DateTime.Parse(PlayerPrefs.GetString("EnterTime"));
|
|
StartCoroutine(PostScore());
|
|
Debug.Log("提交考试" + PlayerPrefs.GetString("完成考试"));
|
|
}
|
|
UnityWebRequest Request_Score;
|
|
string GetStr;
|
|
IEnumerator PostScore()//提交分数
|
|
{
|
|
WWWForm Form = new WWWForm();
|
|
Form.AddField("userId", PlayerPrefs.GetString("id"));
|
|
Form.AddField("examId", PlayerPrefs.GetString("ExamId"));
|
|
Form.AddField("result", SubmitStr);
|
|
Form.AddField("useTime", ((int)ts.TotalSeconds).ToString());
|
|
Request_Score = UnityWebRequest.Post(PlayerPrefs.GetString("完成考试"), Form);
|
|
yield return Request_Score.SendWebRequest();
|
|
if (Request_Score.isHttpError || Request_Score.isNetworkError)
|
|
{
|
|
Debug.Log("错误" + Request_Score.error);
|
|
}
|
|
else
|
|
{
|
|
GetStr = Request_Score.downloadHandler.text;
|
|
Debug.Log(GetStr);
|
|
//SceneManager.LoadScene("Menu");
|
|
Application.Quit();
|
|
}
|
|
}
|
|
}
|