RuralPowerCompetition_yizhe.../RuralPowerCompetition_yizheng1/Assets/Zion/Scripts/CXX/MyManage.cs

281 lines
8.5 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;
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>
List<string> 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<MyUserData>(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
}
/// <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, 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;
//}
}
/// <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);
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, DateTime.Now.ToString());
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);
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
{
,
}