231 lines
6.3 KiB
C#
231 lines
6.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
using ZenFulcrum.EmbeddedBrowser;
|
|
|
|
public class Menu : MonoBehaviour
|
|
{
|
|
public ReadExamData ReadCon;
|
|
public Browser BrowserCon;
|
|
public GameObject[] ShowObj;
|
|
public Scrollbar scrollbar;
|
|
public Text text;
|
|
public GameObject LoadPanel;
|
|
public GameObject ModePanel;
|
|
public GameObject NoDataPanel;
|
|
int mode;
|
|
public float timer = 0;
|
|
bool isLoad;
|
|
void Start()
|
|
{
|
|
ReadCon.ReadTaskTitle();//读取所有作业标题
|
|
//StartCoroutine(UnityWebRequestPost());
|
|
Invoke("GetURL", 5);
|
|
}
|
|
void GetURL()
|
|
{
|
|
BrowserCon.Url = PlayerPrefs.GetString("理论考试入口", "");
|
|
}
|
|
public void SetMode(int m)//0引导 1训练 2考核
|
|
{
|
|
mode = m;
|
|
PlayerPrefs.SetInt("Mode", m);
|
|
}
|
|
public List<GameObject> List_Task;
|
|
int i;
|
|
public void ShowTaskByName(string TaskName)
|
|
{
|
|
//隐藏所有项
|
|
for (i = 0; i < List_Task.Count; i++)
|
|
List_Task[i].SetActive(false);
|
|
for (i = 0; i < ReadCon.List_TaskTitle.Count; i++)
|
|
{
|
|
if (i >= List_Task.Count)//增加一项
|
|
List_Task.Add(Instantiate(List_Task[0], List_Task[0].transform.parent));
|
|
}
|
|
for (i = 0; i < ReadCon.List_TaskTitle.Count; i++)
|
|
{
|
|
if (ReadCon.List_TaskTitle[i].Contains(TaskName))
|
|
{
|
|
List_Task[i].gameObject.SetActive(true);
|
|
List_Task[i].transform.GetChild(0).GetComponent<Text>().text = ReadCon.List_TaskTitle[i];
|
|
}
|
|
}
|
|
}
|
|
public void SelectTask(Text taskText)
|
|
{
|
|
PlayerPrefs.SetString("Task", taskText.text);
|
|
|
|
|
|
if (PlayerPrefs.GetString("Task").Equals("10kV电缆终端调拨物资入库"))
|
|
{
|
|
SceneManager.LoadScene("Operation_LH");
|
|
}
|
|
else if(PlayerPrefs.GetString("Task").Equals("10Kv变压器领料物资出库"))
|
|
{
|
|
SceneManager.LoadScene("Operation_CHUKU");
|
|
}
|
|
else if (PlayerPrefs.GetString("Task").Equals("柱上断路器调拨入库"))
|
|
{
|
|
SceneManager.LoadScene("Operation_HJY");
|
|
}
|
|
else
|
|
{
|
|
SceneManager.LoadScene("Leader");
|
|
}
|
|
//if (mode == 0)
|
|
// SceneManager.LoadScene("Operation_LH");
|
|
//else
|
|
// SceneManager.LoadScene("Operation_LH");
|
|
}
|
|
public void Exit()
|
|
{
|
|
Application.Quit();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 模式选择
|
|
/// </summary>
|
|
/// <param name="message"></param>
|
|
public void ReceiveWebData_ModeSelection(string message)
|
|
{
|
|
if (message != "")
|
|
{
|
|
for (int i = 0; i < ShowObj.Length; i++)
|
|
{
|
|
ShowObj[i].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
/* timer += Time.deltaTime / 4;
|
|
if (timer <= 1)
|
|
{
|
|
scrollbar.size = timer;
|
|
int a = (int)(timer * 100);
|
|
text.text = a.ToString() + "%";
|
|
}
|
|
else
|
|
{
|
|
if (isLoad) return; isLoad = true;
|
|
text.text = "100%";
|
|
LoadPanel.SetActive(false);
|
|
ModePanel.SetActive(true);
|
|
if (isError)
|
|
{
|
|
NoDataPanel.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
if (modeType == "0")
|
|
{
|
|
stuBtn.onClick.Invoke();
|
|
}
|
|
if (modeType == "1")
|
|
{
|
|
examBtn.onClick.Invoke();
|
|
}
|
|
}
|
|
|
|
}*/
|
|
}
|
|
|
|
LoginData loginData = new LoginData();
|
|
StudentTask studentTask = new StudentTask();
|
|
int count = 0;
|
|
bool isError;
|
|
public Button stuBtn;
|
|
public Button examBtn;
|
|
string modeType;
|
|
public IEnumerator UnityWebRequestPost()
|
|
{
|
|
count++; if (count > 4)
|
|
{
|
|
isError = true;
|
|
yield break;
|
|
}
|
|
|
|
WWWForm form = new WWWForm();
|
|
Dictionary<string, string> formDic = new Dictionary<string, string>();
|
|
formDic.Add("ip", InterfaceData.GetIP(ADDRESSFAM.IPv4));
|
|
foreach (var item in formDic)
|
|
{
|
|
form.AddField(item.Key, item.Value);
|
|
}
|
|
UnityWebRequest request = UnityWebRequest.Post("http://jc.lgzn.space/api/api/pro/queryCourseModel", form);
|
|
|
|
request.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
|
yield return request.SendWebRequest();
|
|
if (request.isHttpError || request.isNetworkError)
|
|
{
|
|
yield return new WaitForSecondsRealtime(1f);
|
|
StartCoroutine(UnityWebRequestPost());
|
|
Debug.LogError(request.error);
|
|
}
|
|
else
|
|
{
|
|
string result = request.downloadHandler.text;
|
|
Debug.Log(result);
|
|
if (result=="")
|
|
{
|
|
isError = true;
|
|
yield return new WaitForSecondsRealtime(1f);
|
|
StartCoroutine(UnityWebRequestPost());
|
|
}
|
|
else
|
|
{
|
|
|
|
studentTask = JsonUtility.FromJson<StudentTask>(result);
|
|
for (int i = 0; i < ShowObj.Length; i++)
|
|
{
|
|
ShowObj[i].gameObject.SetActive(true);
|
|
}
|
|
modeType = studentTask.taskType;
|
|
PlayerPrefs.SetString("id", studentTask.userId);
|
|
PlayerPrefs.SetString("Practices", studentTask.taskName);
|
|
Debug.Log(PlayerPrefs.GetString("Practices"));
|
|
isError = false;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
[Serializable]
|
|
public class LoginData
|
|
{
|
|
public string LocalIp;
|
|
public string UserId;
|
|
public List<QueryPractices> QueryPractices = new List<QueryPractices>();
|
|
public List<QueryExam> QueryExam = new List<QueryExam>();
|
|
}
|
|
[Serializable]
|
|
public class QueryPractices
|
|
{
|
|
public string courseName;
|
|
public string courseId;
|
|
}
|
|
[Serializable]
|
|
public class QueryExam
|
|
{
|
|
public string examId;
|
|
//public string sortNo;
|
|
public string actionName;
|
|
}
|
|
[Serializable]
|
|
public class StudentTask
|
|
{
|
|
public string taskType;
|
|
public string userId;
|
|
public string ip;
|
|
public string taskId;
|
|
public string taskName;
|
|
} |