369 lines
12 KiB
C#
369 lines
12 KiB
C#
using SGUnitySDK.Etys;
|
||
using SGUnitySDK.Services.SGStartParams;
|
||
using SGUnitySDK;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using NPOI.OpenXml4Net.OPC.Internal;
|
||
using Newtonsoft.Json;
|
||
using SGUnitySDK.Services.HTTP;
|
||
using SGUnitySDK.Utils;
|
||
using System;
|
||
using RuralPower;
|
||
using System.Linq;
|
||
using NPOI.SS.UserModel;
|
||
using System.Text;
|
||
using System.IO;
|
||
using Newtonsoft.Json.Linq;
|
||
|
||
public class MyManage : MonoBehaviour
|
||
{
|
||
public static MyManage instance;
|
||
/// <summary>
|
||
/// 平台人员信息
|
||
/// </summary>
|
||
public MyUserData userData;
|
||
/// <summary>
|
||
/// 启动信息
|
||
/// </summary>
|
||
public SGAppStartMode startMode;
|
||
/// <summary>
|
||
/// 模式
|
||
/// </summary>
|
||
public PlayModeEnum playModeEnum;
|
||
/// <summary>
|
||
/// 案例编号
|
||
/// </summary>
|
||
public int examNum;
|
||
/// <summary>
|
||
/// 启动参数
|
||
/// </summary>
|
||
List<string> infos;
|
||
|
||
|
||
public string testMode;
|
||
public string testToken;
|
||
|
||
public DateTime starttime;
|
||
public DateTime endtime;
|
||
/// <summary>
|
||
/// 剩余事件
|
||
/// </summary>
|
||
public int leftTime;
|
||
/// <summary>
|
||
/// 是否有限时
|
||
/// </summary>
|
||
public bool hasMit=true;
|
||
private void Awake()
|
||
{
|
||
instance = this;
|
||
|
||
infos = Environment.GetCommandLineArgs().ToList();
|
||
|
||
//初始化
|
||
#if UNITY_EDITOR
|
||
if (testMode != "" && testToken!="")
|
||
{
|
||
//SGStartParamsService.GetInstance().setMode(testMode);
|
||
//SGStartParamsService.GetInstance().setToken(testToken);
|
||
SGStartParamsService.GetInstance().Init(testMode, testToken);
|
||
}
|
||
|
||
if(Directory.Exists(@"D:\zy"))
|
||
{
|
||
Directory.Delete(@"D:\zy", true);
|
||
}
|
||
Directory.CreateDirectory(@"D:\zy");
|
||
|
||
#endif
|
||
SGUConfig config = new SGUConfig();
|
||
SGUSdk.GetInstance().InitSDK(config);
|
||
startMode = SGUSdk.GetInstance().GetAppStartMode();
|
||
|
||
Debug.Log("启动信息:" + JsonConvert.SerializeObject(startMode));
|
||
|
||
|
||
//获取用户信息
|
||
HttpAuthService getUserInfo = new HttpAuthService();
|
||
ResponObject responObject1 = getUserInfo.GetUserInfo();
|
||
if (responObject1.code=="0")
|
||
{
|
||
string data1 = responObject1.data.ToString();
|
||
Debug.Log("GetUserInfo:" + data1);
|
||
userData = JsonConvert.DeserializeObject<MyUserData>(data1);
|
||
|
||
//判断模式
|
||
if (startMode.examId > 0)
|
||
{
|
||
//考试
|
||
playModeEnum = PlayModeEnum.考试;
|
||
Debug.Log("考试模式:" + startMode.examId);
|
||
HttpExamService getPractiseInfo = new HttpExamService();
|
||
ResponObject responObject = getPractiseInfo.GetExamInfo(startMode.examId);
|
||
if (responObject.code == "0")
|
||
{
|
||
string data = responObject.data.ToString();
|
||
leftTime = 99999999;
|
||
hasMit = false;
|
||
if (JObject.Parse(data)["left_time"]!=null)
|
||
{
|
||
string tmplef = JObject.Parse(data)["left_time"].ToString();
|
||
if (!string.IsNullOrEmpty(tmplef))
|
||
{
|
||
leftTime = (int)float.Parse(tmplef);
|
||
hasMit = true;
|
||
}
|
||
}
|
||
Debug.Log("获取考试时长:" + data);
|
||
GetZip();
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("获取考试失败:" + responObject.msg);
|
||
}
|
||
}
|
||
else if (startMode.practiseId > 0)
|
||
{
|
||
//练习
|
||
playModeEnum = PlayModeEnum.练习;
|
||
Debug.Log("练习模式:" + startMode.practiseId);
|
||
HttpPractiseService getPractiseInfo = new HttpPractiseService();
|
||
ResponObject responObject = getPractiseInfo.GetCurrentPractice(startMode.practiseId, userData.id);
|
||
if (responObject.code == "0")
|
||
{
|
||
string data = responObject.data.ToString();
|
||
Debug.Log("获取时长:" + data);
|
||
JObject jb=JObject.Parse(data);
|
||
//starttime = DateTime.Parse(jb["current_train"]["start_time"].ToString());
|
||
//endtime = DateTime.Parse(jb["current_train"]["end_time"].ToString());
|
||
leftTime = 99999999;
|
||
hasMit = false;
|
||
if (jb["current_train"]["left_time"] != null)
|
||
{
|
||
string tmplif = jb["current_train"]["left_time"].ToString();
|
||
if (!string.IsNullOrEmpty(tmplif))
|
||
{
|
||
leftTime = (int)float.Parse(tmplif);
|
||
hasMit = true;
|
||
}
|
||
}
|
||
GetZip();
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("获取考试时间:" + responObject.msg);
|
||
}
|
||
|
||
//HttpPractiseService getPractiseInfo = new HttpPractiseService();
|
||
//ResponObject responObject = getPractiseInfo.GetPractiseInfo(startMode.practiseId);
|
||
//if(responObject.code=="0")
|
||
//{
|
||
// string data = responObject.data.ToString();
|
||
// Debug.Log("GetPractiseInfo:" + data);
|
||
//}
|
||
//else
|
||
//{
|
||
// Debug.LogError("获取练习失败:" + responObject.msg);
|
||
//}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("获取用户失败:" + responObject1.msg);
|
||
}
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
#if UNITY_EDITOR
|
||
if(Input.GetKeyDown(KeyCode.O))
|
||
{
|
||
RuralPowerAPI ruralPowerAPI = new RuralPowerAPI();
|
||
var tmps=ruralPowerAPI.GetAnswer(ScenesRecorder.user.ExamId, ScenesRecorder.user.user_id, startMode.teachplanId);
|
||
Debug.Log("当前答案=====================");
|
||
Debug.Log(JsonConvert.SerializeObject(DataBase.achievement_list));
|
||
foreach (var tmp in tmps)
|
||
{
|
||
Debug.Log(JsonConvert.SerializeObject(tmp));
|
||
}
|
||
Debug.Log("当前答案显示结束=====================");
|
||
}
|
||
#endif
|
||
}
|
||
|
||
private void OnGUI()
|
||
{
|
||
#if UNITY_EDITOR
|
||
if (infos != null && infos.Count > 0)
|
||
{
|
||
GUILayout.Label("启动参数:");
|
||
for (int i = 0; i < infos.Count; i++)
|
||
{
|
||
GUILayout.Label(infos[i]);
|
||
}
|
||
}
|
||
#endif
|
||
}
|
||
|
||
private void GetZip()
|
||
{
|
||
string path = Application.streamingAssetsPath + "/tmpcxx";
|
||
Directory.Delete(path,true);
|
||
Directory.CreateDirectory(path);
|
||
System.IO.Compression.ZipFile.ExtractToDirectory(startMode.planLocalPath, path, Encoding.GetEncoding("GBK"));
|
||
examNum = int.Parse(File.ReadAllText(path + "/examNum.txt"));
|
||
Debug.Log("案例编号:" + examNum);
|
||
}
|
||
/// <summary>
|
||
/// 开始练习
|
||
/// </summary>
|
||
/// <param name="practiseId"></param>
|
||
/// <param name="userId"></param>
|
||
/// <param name="startTime"></param>
|
||
public void GetStartPractise()
|
||
{
|
||
//try
|
||
//{
|
||
//HttpPractiseService getPractiseInfo = new HttpPractiseService();
|
||
//ResponObject responObject = getPractiseInfo.StartPractise(startMode.practiseId, userData.id);
|
||
//if(responObject.code=="0")
|
||
//{
|
||
// string data = responObject.data.ToString();
|
||
// Debug.Log("开始练习:" + data);
|
||
//}
|
||
//else
|
||
//{
|
||
// Debug.LogError(responObject.msg);
|
||
//}
|
||
//}
|
||
//catch (System.Exception e)
|
||
//{
|
||
// throw;
|
||
//}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交练习
|
||
/// </summary>
|
||
/// <param name="practiseId"></param>
|
||
/// <param name="userId"></param>
|
||
/// <param name="answerList"></param>
|
||
public void GetUploadPracticeAnswer()
|
||
{
|
||
RuralPowerAPI ruralPowerAPI=new RuralPowerAPI();
|
||
var answers=ruralPowerAPI.GetAnswer(ScenesRecorder.user.ExamId, ScenesRecorder.user.user_id, startMode.teachplanId);
|
||
Debug.Log("结束练习:");
|
||
Debug.Log(JsonConvert.SerializeObject(answers));
|
||
|
||
HttpPractiseService getPractiseInfo = new HttpPractiseService();
|
||
ResponObject responObject = getPractiseInfo.UploadAnswer(startMode.practiseId, userData.id, answers);
|
||
Debug.Log("提交成绩 : " + JsonConvert.SerializeObject(responObject));
|
||
if (responObject.code == "0")
|
||
{
|
||
string data = responObject.data.ToString();
|
||
Debug.Log("提交练习成绩成功:" + data);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("提交练习成绩失败:" +responObject.msg);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交练习
|
||
/// </summary>
|
||
/// <param name="practiseId"></param>
|
||
/// <param name="userId"></param>
|
||
/// <param name="endTime"></param>
|
||
public void GetEndPractise()
|
||
{
|
||
//HttpPractiseService getPractiseInfo = new HttpPractiseService();
|
||
//ResponObject responObject = getPractiseInfo.EndPractise(startMode.practiseId, userData.id);
|
||
//if (responObject.code == "0")
|
||
//{
|
||
// string data = responObject.data.ToString();
|
||
// Debug.Log("结束练习:" + data);
|
||
//}
|
||
//else
|
||
//{
|
||
// Debug.LogError(responObject.msg);
|
||
//}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 开始考试
|
||
/// </summary>
|
||
/// <param name="examInfoId"></param>
|
||
/// <param name="userId"></param>
|
||
public void GetStartExam()
|
||
{
|
||
//HttpExamService getPractiseInfo = new HttpExamService();
|
||
//ResponObject responObject = getPractiseInfo.StartExam(startMode.examId, userData.id);
|
||
//if (responObject.code == "0")
|
||
//{
|
||
// string data = responObject.data.ToString();
|
||
// Debug.Log("开始考试:" + data);
|
||
//}
|
||
//else
|
||
//{
|
||
// Debug.LogError(responObject.msg);
|
||
//}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交考试
|
||
/// </summary>
|
||
/// <param name="examInfoId"></param>
|
||
/// <param name="userId"></param>
|
||
/// <param name="answerList"></param>
|
||
public void GetUploadExamAnswer()
|
||
{
|
||
RuralPowerAPI ruralPowerAPI = new RuralPowerAPI();
|
||
var answers = ruralPowerAPI.GetAnswer(ScenesRecorder.user.ExamId, ScenesRecorder.user.user_id, startMode.teachplanId);
|
||
Debug.Log("结束考试:");
|
||
Debug.Log(JsonConvert.SerializeObject(answers));
|
||
HttpExamService getPractiseInfo = new HttpExamService();
|
||
ResponObject responObject = getPractiseInfo.UploadAnswer(startMode.examId, userData.id, answers);
|
||
Debug.Log("提交成绩 : "+JsonConvert.SerializeObject(responObject));
|
||
if (responObject.code == "0")
|
||
{
|
||
string data = responObject.data.ToString();
|
||
Debug.Log("提交考试成绩成功:" + data);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("提交考试成绩失败:"+responObject.msg);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 结束考试
|
||
/// </summary>
|
||
/// <param name="examInfoId"></param>
|
||
/// <param name="userId"></param>
|
||
public void GetEndExam()
|
||
{
|
||
//HttpExamService getPractiseInfo = new HttpExamService();
|
||
//ResponObject responObject = getPractiseInfo.EndExam(startMode.examId, userData.id);
|
||
//if (responObject.code == "0")
|
||
//{
|
||
// string data = responObject.data.ToString();
|
||
// Debug.Log("结束考试:" + data);
|
||
//}
|
||
//else
|
||
//{
|
||
// Debug.LogError(responObject.msg);
|
||
//}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模式
|
||
/// </summary>
|
||
public enum PlayModeEnum
|
||
{
|
||
练习,
|
||
考试
|
||
} |