602 lines
19 KiB
C#
602 lines
19 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
using Newtonsoft.Json.Linq;
|
||
using System.IO;
|
||
using Newtonsoft.Json;
|
||
using System.Linq;
|
||
using UnityEngine.SceneManagement;
|
||
using WpfApp1.Util;
|
||
|
||
public class CallForTest : MonoBehaviour
|
||
{
|
||
public static CallForTest instance;
|
||
/// <summary>
|
||
/// 启动参数
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public List<string> infos = null;
|
||
|
||
/// <summary>
|
||
/// 人员信息
|
||
/// </summary>
|
||
public ICT_user user;
|
||
/// <summary>
|
||
/// 暂存信息
|
||
/// </summary>
|
||
public MyTmpSaveInfo saveInfo;
|
||
/// <summary>
|
||
/// 章节id
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string currentContentId;
|
||
/// <summary>
|
||
/// 任务开始时间
|
||
/// </summary>
|
||
public DateTime currentStartTime;
|
||
/// <summary>
|
||
/// 实训记录id
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string recordId;
|
||
/// <summary>
|
||
/// 当前任务详情数据
|
||
/// </summary>
|
||
public TaskItemData currentTaskData;
|
||
|
||
/// <summary>
|
||
/// 读取的任务配置
|
||
/// </summary>
|
||
public List<MyTask> tasks;
|
||
|
||
|
||
/// <summary>
|
||
/// 应用appid
|
||
/// </summary>
|
||
private string appid;
|
||
/// <summary>
|
||
/// 应用密钥
|
||
/// </summary>
|
||
private string secret;
|
||
/// <summary>
|
||
/// AES公钥
|
||
/// </summary>
|
||
private string aesKey;
|
||
/// <summary>
|
||
/// RSA公钥
|
||
/// </summary>
|
||
private string rsaKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCXLr8EzT/lt9XYKOX2CzkwqVcW//UyIP5824OEgdPHLhBvGy5QXtyIj0myw3LlbqZkOoX8SZFMxJOnHiCKIVhXrTYOaxTdWYv95DR4gCZ9q55U7NQPUkeMtTbuLa5HHdpBy8DM+DfS2VJv6RTK3AJLjWkNjpyhGgWIlOTGbMsj7QIDAQAB";
|
||
|
||
public string Appid { get => appid; set => appid = value; }
|
||
/// <summary>
|
||
/// AES公钥
|
||
/// </summary>
|
||
public string AesKey { get => aesKey; set => aesKey = value; }
|
||
/// <summary>
|
||
/// 是否开启加密
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public bool is加密;
|
||
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 临时文件根目录
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string pathRoot;
|
||
/// <summary>
|
||
/// 任务模式临时工程路径
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string pathProject;
|
||
/// <summary>
|
||
/// 下载缓存路径
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string pathCache;
|
||
/// <summary>
|
||
/// 临时存储任务截图,录屏
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string pathTaskFile;
|
||
/// <summary>
|
||
/// 自由模式工程根目录
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string pathFreeProjectRoot;
|
||
|
||
/// <summary>
|
||
/// 是否打印信息
|
||
/// </summary>
|
||
private bool showDebug;
|
||
|
||
private void Awake()
|
||
{
|
||
//if(DateTime.Now>new DateTime(2024,12,31))
|
||
//{
|
||
// return;
|
||
//}
|
||
|
||
instance = this;
|
||
|
||
#if !UNITY_EDITOR
|
||
|
||
pathRoot= Application.streamingAssetsPath + "/ProjectCode";
|
||
pathProject = Application.streamingAssetsPath + "/ProjectCode/TmpCode";
|
||
pathCache = Application.streamingAssetsPath + "/ProjectCode/Cache";
|
||
pathTaskFile= Application.streamingAssetsPath + "/ProjectCode/Submit";
|
||
pathFreeProjectRoot=Application.streamingAssetsPath + "/ProjectCode/FreeModeTmpCode";
|
||
#else
|
||
|
||
|
||
//编辑器
|
||
pathRoot = "D:/UserFiles/ProjectCode";
|
||
pathProject = "D:/UserFiles/ProjectCode/TmpCode";
|
||
pathCache = "D:/UserFiles/ProjectCode/Cache";
|
||
pathTaskFile = "D:/UserFiles/ProjectCode/Submit";
|
||
pathFreeProjectRoot = "D:/UserFiles/ProjectCode/FreeModeTmpCode";
|
||
#endif
|
||
|
||
if (!Directory.Exists(pathRoot))
|
||
Directory.CreateDirectory(pathRoot);
|
||
if (!Directory.Exists(pathProject))
|
||
Directory.CreateDirectory(pathProject);
|
||
if (!Directory.Exists(pathCache))
|
||
Directory.CreateDirectory(pathCache);
|
||
if (!Directory.Exists(pathTaskFile))
|
||
Directory.CreateDirectory(pathTaskFile);
|
||
if (!Directory.Exists(pathFreeProjectRoot))
|
||
{
|
||
Directory.CreateDirectory(pathFreeProjectRoot);
|
||
Directory.CreateDirectory(pathFreeProjectRoot + "/Python");
|
||
Directory.CreateDirectory(pathFreeProjectRoot + "/Java");
|
||
Directory.CreateDirectory(pathFreeProjectRoot + "/C");
|
||
}
|
||
|
||
//读配置
|
||
File.ReadAllLines(Application.streamingAssetsPath + "/MainConfig.ini").ToList().ForEach(a =>
|
||
{
|
||
if (!a.StartsWith("#") && !string.IsNullOrEmpty(a))
|
||
{
|
||
string[] tmp = a.Split('=');
|
||
Debug.Log(tmp);
|
||
if (tmp[0].Trim() == "appid")
|
||
{
|
||
appid = tmp[1].Trim();
|
||
}
|
||
else if (tmp[0].Trim() == "secret")
|
||
{
|
||
secret = tmp[1].Trim();
|
||
}
|
||
else if (tmp[0].Trim() == "IdAddress")
|
||
{
|
||
InterfaceManager.IdAddress = tmp[1].Trim();
|
||
}
|
||
else if(tmp[0].Trim() == "showDebug")
|
||
{
|
||
showDebug = (tmp[1].Trim() == "on" ? true : false);
|
||
}
|
||
}
|
||
});
|
||
|
||
}
|
||
private void Start()
|
||
{
|
||
//if (DateTime.Now > new DateTime(2024, 12, 31))
|
||
//{
|
||
// return;
|
||
//}
|
||
//用作禁用代码的标记
|
||
string zhangheyi;
|
||
/*
|
||
//获取启动参数
|
||
infos = Environment.GetCommandLineArgs().ToList();
|
||
string ticketa = infos.Find(a => a.StartsWith("ticket="));
|
||
string component_typeta = infos.Find(a => a.StartsWith("component_type="));
|
||
|
||
//获取密钥
|
||
string url11 = InterfaceManager.IdAddress + ":8080/config/secret";
|
||
StartCoroutine(Task_Setp_Back.Get(url11, false, (ok, result) =>
|
||
{
|
||
if (ok)
|
||
{
|
||
JObject jb = JObject.Parse(result);
|
||
if(jb["enable"].ToObject<bool>())
|
||
{
|
||
//开启加密
|
||
is加密 = true;
|
||
string rsa = jb["key"].ToString();
|
||
AesKey=RSAHelper.DecryptByPublicKey(rsa, rsaKey);
|
||
Debug.Log("开启加密");
|
||
}
|
||
else
|
||
{
|
||
//未开启加密
|
||
is加密 = false;
|
||
Debug.Log("关闭加密");
|
||
}
|
||
|
||
//获取token
|
||
if (! string.IsNullOrEmpty(ticketa) && !string.IsNullOrEmpty(component_typeta) && !string.IsNullOrEmpty(ticketa.Split("ticket=")[1]) && !string.IsNullOrEmpty(component_typeta.Split("component_type=")[1]))
|
||
{
|
||
Debug.Log("有任务启动:"+ ticketa +" "+ component_typeta);
|
||
string ticket = ticketa.Split("ticket=")[1];
|
||
string component_type = component_typeta.Split("component_type=")[1];
|
||
//有任务启动
|
||
GetToken(ticket, a =>
|
||
{
|
||
if (a)
|
||
{
|
||
GetData(ticket, (MainMenuType)int.Parse(component_type));
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
//无任务启动
|
||
Debug.Log("无任务启动");
|
||
GameInit.Instance.LoadScene();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("获取密文失败");
|
||
}
|
||
}));
|
||
*/
|
||
}
|
||
|
||
/// <summary>
|
||
/// tcp切换任务
|
||
/// </summary>
|
||
[HideInInspector]
|
||
public string doChangTask = "";
|
||
[HideInInspector]
|
||
public string doChangeType = "";
|
||
|
||
private void Update()
|
||
{
|
||
if(!string.IsNullOrEmpty(doChangTask) && !string.IsNullOrEmpty(doChangeType))
|
||
{
|
||
string tmp = doChangTask;
|
||
string tmptype = doChangeType;
|
||
doChangTask = "";
|
||
doChangeType = "";
|
||
|
||
//任务切换
|
||
GetToken(tmp, a =>
|
||
{
|
||
if (a)
|
||
{
|
||
GetData(tmp, (MainMenuType)int.Parse(tmptype));
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
public string 测试ticket;
|
||
public MainMenuType 测试type;
|
||
|
||
[ContextMenu("切换任务")]
|
||
public void Test()
|
||
{
|
||
GetToken(测试ticket, a =>
|
||
{
|
||
if (a)
|
||
{
|
||
GetData(测试ticket, 测试type);
|
||
}
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 获取当前实训任务,并启动(网页切换任务)
|
||
/// </summary>
|
||
/// <param name="ticket"></param>
|
||
private void GetData(string ticket,MainMenuType mainMenuType)
|
||
{
|
||
//如果当前任务已启动,不切换任务
|
||
if (!UnityEngine.SceneManagement.SceneManager.GetSceneByName("UIScene").isLoaded)
|
||
{
|
||
Debug.Log("任务加载中ticket=" + ticket);
|
||
string url = InterfaceManager.IdAddress + ":8080/postback/getTicketInfo?ticket=" + ticket;
|
||
StartCoroutine(Task_Setp_Back.Get(url, true,(isok, info) =>
|
||
{
|
||
if (isok)
|
||
{
|
||
if (info != null)
|
||
{
|
||
JObject jb = JObject.Parse(info);
|
||
|
||
if ((int)jb["code"] == 200)
|
||
{
|
||
var data = jb["data"];
|
||
ICT_user user = new ICT_user();
|
||
user.userId = data["userId"].ToString();
|
||
user.nickName = data["userName"].ToString();
|
||
this.user = user;
|
||
currentContentId = data["contentId"].ToString();
|
||
|
||
MyTask _task = new MyTask();
|
||
_task._taskId = (string)data["taskId"];
|
||
_task.taskCode = (string)data["taskCode"];
|
||
_task._contentId = (string)data["contentId"];
|
||
_task._startTime = (string)data["startTime"];
|
||
_task._endTime = (string)data["expireTime"];
|
||
_task._ticket = (string)data["ticket"];
|
||
_task.programLanguage = data["programLanguage"].ToString();
|
||
_task.studyRecordId = data["studyRecordId"].ToString();
|
||
CallForTest.instance.recordId = data["studyRecordId"].ToString();
|
||
|
||
|
||
|
||
GameManager.is_login = true;
|
||
GameManager.current_main_menu_type = mainMenuType;
|
||
|
||
//加载任务,跳场景
|
||
Debug.Log("加载任务,跳场景");
|
||
|
||
//启动器启动任务,直接跳转至对应任务场景
|
||
GetTaskDetail(_task._taskId, _task._contentId, _task.programLanguage, true);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError(jb["msg"].ToString());
|
||
}
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
else
|
||
{
|
||
MainCanvasManager.confirm_panel.OnPopup("切换任务失败,已有任务进行中。请先点击上方<color=red>返回</color>按钮,退出到首页。","");
|
||
}
|
||
}
|
||
|
||
private void OnGUI()
|
||
{
|
||
if (showDebug)
|
||
{
|
||
if (infos != null && infos.Count > 0)
|
||
{
|
||
GUILayout.Label("启动参数:");
|
||
for (int i = 0; i < infos.Count; i++)
|
||
{
|
||
GUILayout.Label(infos[i]);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
public void GetTaskDetail(string taskid, string ContentId, string laugulage, bool has_task = false)
|
||
{
|
||
//获取任务详情
|
||
var _url = InterfaceManager.IdAddress + ":8080/component/app/task/detail?programLanguage=" + laugulage + "&taskId=" + taskid;
|
||
StartCoroutine(InterfaceManager.Get(_url,true, (_data) =>
|
||
{
|
||
JObject obj = JObject.Parse(_data);
|
||
if (obj["code"].ToObject<int>() == 200)
|
||
{
|
||
var tmpde = obj["data"];
|
||
|
||
CallForTest.instance.currentTaskData = HandleData(tmpde);
|
||
CallForTest.instance.currentContentId = ContentId;
|
||
CallForTest.instance.currentStartTime = DateTime.Now;
|
||
|
||
|
||
List<string> senceNames = new List<string> { "数字人舞台", "机器人舞台", "深圳市民中心", "西丽湖校区" };
|
||
|
||
if (senceNames.Contains(CallForTest.instance.currentTaskData.task_scenename))
|
||
{
|
||
string tmpscene = "";
|
||
if (CallForTest.instance.currentTaskData.task_scenename == "深圳市民中心" || CallForTest.instance.currentTaskData.task_scenename == "西丽湖校区")
|
||
{
|
||
tmpscene = CallForTest.instance.currentTaskData.task_scenename + "_昼";
|
||
}
|
||
else
|
||
{
|
||
tmpscene = CallForTest.instance.currentTaskData.task_scenename;
|
||
}
|
||
|
||
LoginSceneUIManager.current_preselect_scene = tmpscene;
|
||
GameManager.current_scene = CallForTest.instance.currentTaskData.task_scenename;
|
||
GameManager.current_component_type = (ComponentType)int.Parse(CallForTest.instance.currentTaskData.task_componentType);
|
||
//跳
|
||
if (has_task)
|
||
{
|
||
SceneManager.LoadSceneAsync("LoadingScene", LoadSceneMode.Additive);
|
||
}
|
||
else
|
||
{
|
||
LoginSceneUIManager.loading_panel.OnActive(LoginSceneUIManager.course_task_detail_panel);
|
||
}
|
||
|
||
Debug.Log("启动关卡!");
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("无此场景:" + CallForTest.instance.currentTaskData.task_scenename);
|
||
}
|
||
|
||
}
|
||
}));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 解析任务详情数据
|
||
/// </summary>
|
||
/// <param name="_data"></param>
|
||
private TaskItemData HandleData(JToken _data)
|
||
{
|
||
TaskItemData _taskdata = new TaskItemData();
|
||
_taskdata.task_id = _data["id"].ToString();
|
||
_taskdata.task_componentType = _data["componentType"].ToString();
|
||
_taskdata.task_name = _data["taskName"].ToString();
|
||
_taskdata.task_scenename = _data["sceneName"].ToString();
|
||
_taskdata.task_packagefilename = _data["taskPackageFileName"].ToString();
|
||
_taskdata.task_packagefileurl = _data["taskPackageFileUrl"].ToString();
|
||
_taskdata.investigatePointList = _data["investigatePointList"].ToObject<List<string>>();
|
||
_taskdata.task_description = _data["taskDescription"].ToString();
|
||
_taskdata.task_picturelist = _data["taskPictureList"].ToObject<List<Picture>>();
|
||
_taskdata.task_steplist = _data["taskStepList"].ToObject<List<TaskStep>>();
|
||
_taskdata.scene_formdtoslist = _data["sceneFormDto"].ToObject<SceneformDto>();
|
||
_taskdata.programDto = _data["programDto"].ToObject<ProgramDto>();
|
||
return _taskdata;
|
||
}
|
||
|
||
#region 暂时无用
|
||
|
||
// public IEnumerator GetCall(string url,Action<bool,JToken> back)
|
||
// {
|
||
// UnityWebRequest webRequest =UnityWebRequest.Get(url);
|
||
// webRequest.SetRequestHeader("Authorization","Bearer "+access_token);
|
||
// yield return webRequest.SendWebRequest();
|
||
// if(webRequest.isDone)
|
||
// {
|
||
// if(webRequest.isNetworkError)
|
||
// {
|
||
// Debug.LogError(webRequest.error);
|
||
// }
|
||
// else
|
||
// {
|
||
// JObject jb=JObject.Parse(webRequest.downloadHandler.text);
|
||
// if(jb["code"].ToObject<int>()==200)
|
||
// {
|
||
// back(true, jb["data"]);
|
||
// }
|
||
// else
|
||
// {
|
||
// Debug.LogError(jb["msg"].ToString());
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// back(false, null);
|
||
// }
|
||
|
||
public IEnumerator PostCall(string url, string postData, Action<bool, JToken> back)
|
||
{
|
||
UnityWebRequest webRequest = UnityWebRequest.Post(url, postData, "application/json");
|
||
yield return webRequest.SendWebRequest();
|
||
if (webRequest.isDone)
|
||
{
|
||
if (webRequest.isNetworkError)
|
||
{
|
||
Debug.LogError(webRequest.error);
|
||
}
|
||
else
|
||
{
|
||
JObject jb = JObject.Parse(webRequest.downloadHandler.text);
|
||
if (jb["code"].ToObject<int>() == 200)
|
||
{
|
||
back(true, jb["access_token"]);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError(jb["msg"].ToString());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据启动器返回的ticket去获取token
|
||
/// </summary>
|
||
public void GetToken(string ticket, Action<bool> callback)
|
||
{
|
||
string url = InterfaceManager.IdAddress + ":8080/appAuth";
|
||
var tmpdata = new
|
||
{
|
||
appId = Appid, //应用ID
|
||
ticket = ticket, //票据ID
|
||
signature = ticket + Appid + secret//签名信息:票据ID+应用ID+秘钥(暂未RSA加密)
|
||
};
|
||
string postData = JsonConvert.SerializeObject(tmpdata);
|
||
StartCoroutine(Task_Setp_Back.Post(url, postData, null,(result, data) =>
|
||
{
|
||
if (result)
|
||
{
|
||
JObject jb = JObject.Parse(data);
|
||
if (jb["code"].ToObject<int>() == 200)
|
||
{
|
||
InterfaceManager.Token = jb["access_token"].ToString();
|
||
callback(true);
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError(jb["msg"].ToString());
|
||
callback(false);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
callback(false);
|
||
}
|
||
}));
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// ict人员信息
|
||
/// </summary>
|
||
public class ICT_user
|
||
{
|
||
public string userId;
|
||
/// <summary>
|
||
/// 登录账号
|
||
/// </summary>
|
||
public string userName;
|
||
/// <summary>
|
||
/// 人员姓名
|
||
/// </summary>
|
||
public string nickName;
|
||
/// <summary>
|
||
/// 头像地址
|
||
/// </summary>
|
||
public string avatar;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 任务
|
||
/// </summary>
|
||
public class MyTask
|
||
{
|
||
/// <summary>
|
||
/// 任务名称
|
||
/// </summary>
|
||
public string name;
|
||
/// <summary>
|
||
/// 任务编号
|
||
/// </summary>
|
||
public string code;
|
||
public string _taskId;
|
||
public string taskCode;
|
||
public string _contentId;
|
||
public string _startTime;
|
||
public string _endTime;
|
||
public string _ticket;
|
||
public string _staginstate;//暂存状态
|
||
public List<MyStep> stepList;
|
||
public string programLanguage;
|
||
public string studyRecordId;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 步骤
|
||
/// </summary>
|
||
public class MyStep
|
||
{
|
||
public string name;
|
||
public string code;//步骤编码
|
||
public string stepName;
|
||
public string stepStatus;
|
||
|
||
}
|
||
|