修改任务书的读取

This commit is contained in:
YangHua 2024-09-08 00:42:12 +08:00
parent a0b04f7e3b
commit fa4ebea54d
5 changed files with 18 additions and 112 deletions

View File

@ -21,17 +21,8 @@ public class NetManager : BaseManager<NetManager>
public string token;
public string url;
/// <summary>
/// UI_CheckTaskPanel面板内容的学习、练习模式可以外配,读取json的名称
/// </summary>
string fileName = "10001.json";
public string content { get; private set; }
[Serializable]
public class IPConfig
{
public string content;
}
/// <summary>
@ -67,69 +58,5 @@ public class NetManager : BaseManager<NetManager>
string path = Application.streamingAssetsPath + "/Config/info.txt";
Debug.Log(path);
File.WriteAllText(path, info);
}
/// <summary>
/// UI_CheckTaskPanel面板内容的学习、练习模式用json读取可以外配
/// </summary>
/// <param name="action"></param>
public void GetCheckTaskState(UnityAction<bool> action)
{
MonoMgr.Instance.StartCoroutine(GetCheckTaskStateAsync(action));
}
private IEnumerator GetCheckTaskStateAsync(UnityAction<bool> action)
{
string path = System.IO.Path.Combine(Application.streamingAssetsPath, fileName);
UnityWebRequest request = UnityWebRequest.Get(path);
yield return request.SendWebRequest();
if (request.result != UnityWebRequest.Result.Success)
{
Debug.Log("Failed to load file: " + request.error);
}
else
{
// 获取文件内容
string fileContent = request.downloadHandler.text;
IPConfig config = JsonUtility.FromJson<IPConfig>(fileContent);
content = config.content;
Debug.Log(content);
action?.Invoke(true);
}
}
/// <summary>
/// UI_CheckTaskPanel面板内容的考试模式用接口调取
/// </summary>
/// <param name="action"></param>
public void GetCheckTaskExam(UnityAction<bool> action)
{
MonoMgr.Instance.StartCoroutine(GetCheckTaskExamAsync(action));
}
private IEnumerator GetCheckTaskExamAsync(UnityAction<bool> action)
{
using (UnityWebRequest unityWebRequest = UnityWebRequest.Post("", string.Empty))
{
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.result == UnityWebRequest.Result.Success)
{
Debug.Log("连接成功:*******************\n" + unityWebRequest.downloadHandler.text);
string json = unityWebRequest.downloadHandler.text;
action?.Invoke(true);
Debug.Log("连接成功 ");
}
else
{
Debug.Log("连接失败 ");
action?.Invoke(false);
}
}
}
}

View File

@ -1,12 +1,16 @@
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[Serializable]
public class Mission
{
public string content;
}
public class UI_CheckTaskPanel : BasePanel
{
public override void ShowMe()
{
base.ShowMe();
@ -19,41 +23,8 @@ public class UI_CheckTaskPanel : BasePanel
}
public void Init()
{
switch (ProcessManager.Instance.mode)
{
case E_ModeType.Study:
NetManager.Instance.GetCheckTaskState((value) =>
{
if (value)
{
GetControl<TextMeshProUGUI>("Text_Content").text = NetManager.Instance.content;
Debug.Log(NetManager.Instance.content);
}
});
break;
case E_ModeType.Practice:
NetManager.Instance.GetCheckTaskState((value) =>
{
if (value)
{
GetControl<TextMeshProUGUI>("Text_Content").text = NetManager.Instance.content;
Debug.Log(NetManager.Instance.content);
}
});
break;
case E_ModeType.Exam:
NetManager.Instance.GetCheckTaskExam((value) =>
{
if (value)
{
GetControl<TextMeshProUGUI>("Text_Content").text = NetManager.Instance.content;
Debug.Log(NetManager.Instance.content);
}
});
break;
}
Mission jsonData = GameManager.JsonMgr.LoadData<Mission>($"MissionData/{GameManager.RunModelMgr.schemeID.ToString()}");
GetControl<TextMeshProUGUI>("Text_Content").text = jsonData.content;
}
protected override void OnClick(string btnName)

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 797d21241acf24142a6296937122766e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: