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; public class MyManage : MonoBehaviour { public static MyManage instance; /// /// 平台人员信息 /// public MyUserData userData; /// /// 启动信息 /// public SGAppStartMode startMode; /// /// 模式 /// public PlayModeEnum playModeEnum; /// /// 启动参数 /// List infos; private void Awake() { instance = this; infos = Environment.GetCommandLineArgs().ToList(); //初始化 #if UNITY_EDITOR SGStartParamsService.GetInstance().setMode("eyJtb2RlIjo1LCJwbGFuTG9jYWxQYXRoIjoiRDpcXFVzZXJGaWxlc1xc5Yac55S156ue6LWb5a+55o6lXFzmoYjkvoszLnppcCIsInByYWN0aXNlSWQiOiI1NCIsInN0dVVzZXJJZCI6IjI5OSIsImFwcElkIjoiNjciLCJleGFtSWQiOiItMSIsInRlYWNocGxhbklkIjoiMyIsImNvdXJzZUlkIjoiLTEifQ=="); SGStartParamsService.GetInstance().setToken("fb2efb8f-99d4-42b4-81e5-728b9b6c78e1"); #endif SGUConfig config = new SGUConfig(); SGUSdk.GetInstance().InitSDK(config); startMode = SGUSdk.GetInstance().GetAppStartMode(); //获取用户信息 HttpAuthService getUserInfo = new HttpAuthService(); ResponObject responObject1 = getUserInfo.GetUserInfo(); if(responObject1.code=="0") { string data1 = responObject1.data.ToString(); Debug.Log("GetUserInfo:" + data1); userData = JsonConvert.DeserializeObject(data1); //判断模式 if (startMode.examId > 0) { //考试 playModeEnum = PlayModeEnum.考试; HttpExamService getPractiseInfo = new HttpExamService(); ResponObject responObject = getPractiseInfo.PrepareExam(startMode.examId, userData.id); if(responObject.code=="0") { string data = responObject.data.ToString(); Debug.Log("考生获取考试题目" + data); } else { Debug.LogError("获取考试失败:" + responObject.msg); } } else if (startMode.practiseId > 0) { //练习 playModeEnum = PlayModeEnum.练习; 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 } /// /// 开始练习 /// /// /// /// public void GetStartPractise() { //try { HttpPractiseService getPractiseInfo = new HttpPractiseService(); ResponObject responObject = getPractiseInfo.StartPractise(startMode.practiseId, userData.id, DateTime.Now.ToString()); if(responObject.code=="0") { string data = responObject.data.ToString(); Debug.Log("开始练习:" + data); } else { Debug.LogError(responObject.msg); } } //catch (System.Exception e) //{ // throw; //} } /// /// 提交练习 /// /// /// /// 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); if (responObject.code == "0") { string data = responObject.data.ToString(); Debug.Log("提交练习" + data); } else { Debug.LogError(responObject.msg); } } /// /// 提交练习 /// /// /// /// public void GetEndPractise() { HttpPractiseService getPractiseInfo = new HttpPractiseService(); ResponObject responObject = getPractiseInfo.EndPractise(startMode.practiseId, userData.id, DateTime.Now.ToString()); if (responObject.code == "0") { string data = responObject.data.ToString(); Debug.Log("结束练习:" + data); } else { Debug.LogError(responObject.msg); } } /// /// 开始考试 /// /// /// 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); } } /// /// 提交考试 /// /// /// /// 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); if (responObject.code == "0") { string data = responObject.data.ToString(); Debug.Log("提交考试:" + data); } else { Debug.LogError(responObject.msg); } } /// /// 结束考试 /// /// /// 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); } } } /// /// 模式 /// public enum PlayModeEnum { 练习, 考试 }