1142 lines
44 KiB
Plaintext
1142 lines
44 KiB
Plaintext
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Xml;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using Newtonsoft.Json.Linq;
|
||
using Newtonsoft.Json.Converters;
|
||
using Newtonsoft.Json;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
|
||
using TMPro;
|
||
using System.Linq;
|
||
using System.IO;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
|
||
|
||
public class ExaminationPanel : MonoBehaviour
|
||
{
|
||
/// <summary>
|
||
/// 提交按钮
|
||
/// </summary>
|
||
private Button submitBtn, backBtn,returnBtn, btn_Submit_mask, dropDown_mask;
|
||
/// <summary>
|
||
/// 当前是第几道题
|
||
/// </summary>
|
||
private Text questionID;
|
||
/// <summary>
|
||
/// 题目的父节点
|
||
/// </summary>
|
||
private Transform questionRoot;
|
||
|
||
private Transform fillRoot;
|
||
private Transform selectRoot;
|
||
private Transform shortRoot;
|
||
/// <summary>
|
||
/// 选项的组
|
||
/// </summary>
|
||
private ToggleGroup questionGroup;
|
||
/// <summary>
|
||
/// 答题界面数据内容
|
||
/// </summary>
|
||
private QuestionPanelData mQuestionPanelData;
|
||
/// <summary>
|
||
/// 每一道题的题目内容
|
||
/// </summary>
|
||
private QuestionData mQuestionData;
|
||
/// <summary>
|
||
/// 题目内容物体
|
||
/// </summary>
|
||
private GameObject mQuestion;
|
||
/// <summary>
|
||
/// 题目计数
|
||
/// </summary>
|
||
private int mQuestionCount;
|
||
/// <summary>
|
||
/// 选项的链表
|
||
/// </summary>
|
||
private List<Options> options = new List<Options>();
|
||
private List<ToggleGroup> toggleGroups = new List<ToggleGroup>();
|
||
/// <summary>
|
||
/// 填空的链表
|
||
/// </summary>
|
||
private List<FillText> fillTexts = new List<FillText>();
|
||
private List<ShortText> shortTexts = new List<ShortText>();
|
||
public Canvas canvas;
|
||
/// <summary>
|
||
/// 左上角选择框
|
||
/// </summary>
|
||
public Dropdown dropdown;
|
||
/// <summary>
|
||
/// 选择题数量
|
||
/// </summary>
|
||
public int selectCount = 0;
|
||
/// <summary>
|
||
/// 多选题标题文字
|
||
/// </summary>
|
||
public Text text_fill;
|
||
/// <summary>
|
||
/// 选择题标题文字
|
||
/// </summary>
|
||
public Text text_Choose;
|
||
/// <summary>
|
||
/// 试卷名称
|
||
/// </summary>
|
||
public TMP_Text text_title;
|
||
/// <summary>
|
||
/// 试卷背景
|
||
/// </summary>
|
||
public Image image_exam;
|
||
/// <summary>
|
||
/// 大图显示
|
||
/// </summary>
|
||
public BigPicturePanel bigPicturePanel;
|
||
|
||
private List<GameObject> list_fillsubgo;
|
||
private List<GameObject> list_selectsubgo;
|
||
private List<GameObject> list_shortsubgo;
|
||
private List<GameObject> list_shortinput;
|
||
private void Awake()
|
||
{
|
||
Init();
|
||
}
|
||
/// <summary>
|
||
/// 初始化找到相关物体和组件,并给按钮添加监听方法
|
||
/// </summary>
|
||
private void Init()
|
||
{
|
||
submitBtn = transform.Find("BGImage/btn_Submit").GetComponent<Button>();
|
||
btn_Submit_mask = transform.Find("BGImage/btn_Submit_mask").GetComponent<Button>();
|
||
dropDown_mask = transform.Find("BGImage/dropDown_mask").GetComponent<Button>();
|
||
returnBtn = transform.Find("BGImage/btn_Return").GetComponent<Button>();
|
||
backBtn = transform.Find("backBtn").GetComponent<Button>();
|
||
questionID = transform.Find("BGImage/topic/questionNumber").GetComponent<Text>();
|
||
questionRoot = transform.Find("BGImage/topic/Scroll View/Viewport/Content").transform;
|
||
fillRoot = transform.Find("BGImage/topic/Scroll View/Viewport/Content/fill").transform;
|
||
selectRoot = transform.Find("BGImage/topic/Scroll View/Viewport/Content/select").transform;
|
||
shortRoot = transform.Find("BGImage/topic/Scroll View/Viewport/Content/short").transform;
|
||
text_fill = transform.Find("BGImage/topic/Scroll View/Viewport/Content/fill/topicText").GetComponent<Text>();
|
||
text_Choose = transform.Find("BGImage/topic/Scroll View/Viewport/Content/select/topicText").GetComponent<Text>();
|
||
questionGroup = transform.Find("BGImage/topic/Scroll View/Viewport/Content").GetComponent<ToggleGroup>();
|
||
image_exam = transform.Find("BGImage").GetComponent<Image>();
|
||
text_title = transform.Find("BGImage/title_text").GetComponent<TMP_Text>();
|
||
list_selectsubgo = new List<GameObject>();
|
||
list_fillsubgo = new List<GameObject>();
|
||
list_shortsubgo = new List<GameObject>();
|
||
list_shortinput = new List<GameObject>();
|
||
backBtn.onClick.AddListener(() =>
|
||
{
|
||
SceneLocating.Loacting("02_模式选择");
|
||
});
|
||
submitBtn.onClick.AddListener(submitClick);
|
||
returnBtn.onClick.AddListener(ReturnClick);
|
||
dropdown.onValueChanged.AddListener((s) =>
|
||
{
|
||
for (int i = 1; i < fillRoot.childCount; i++)
|
||
{
|
||
Destroy(fillRoot.GetChild(i).gameObject);
|
||
}
|
||
for (int i = 1; i < selectRoot.childCount; i++)
|
||
{
|
||
Destroy(selectRoot.GetChild(i).gameObject);
|
||
}
|
||
for (int i = 1; i < shortRoot.childCount; i++)
|
||
{
|
||
Destroy(shortRoot.GetChild(i).gameObject);
|
||
}
|
||
list_fillsubgo.Clear();
|
||
list_selectsubgo.Clear();
|
||
list_shortsubgo.Clear();
|
||
InitExamBG();
|
||
taskName = dropdown.options[s].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
});
|
||
}
|
||
/// <summary>
|
||
/// 初始化考试背景
|
||
/// </summary>
|
||
private void InitExamBG()
|
||
{
|
||
image_exam.sprite = Resources.Load<Sprite>("UI/Submit/框");
|
||
text_title.text ="";
|
||
}
|
||
private void Start()
|
||
{
|
||
|
||
dropdown.options.Clear();
|
||
string content = ModeSelectPanel.instance.currentSelectSubject;
|
||
List<string> dropList = new List<string>() { "", "", "" };
|
||
switch (content)
|
||
{
|
||
case "网络架构":
|
||
dropList.Clear();
|
||
dropList = new List<string>() { "区分工业互联网网络场景", "了解工业互联网网络功能", "理解工业互联网网络建设要求" };
|
||
dropdown.AddOptions(dropList);
|
||
dropdown.transform.GetChild(0).GetComponent<Text>().text = dropdown.options[0].text;
|
||
taskName= dropdown.options[0].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
break;
|
||
case "网络设备":
|
||
dropList.Clear();
|
||
dropList = new List<string>() { "对接工业网络物理接口", "配置工业网关设备", "配置工业交换设备", "配置工业无线设备", "配置工业网络安全设备" };
|
||
dropdown.AddOptions(dropList);
|
||
dropdown.transform.GetChild(0).GetComponent<Text>().text = dropdown.options[0].text;
|
||
taskName = dropdown.options[0].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
break;
|
||
case "网络技术":
|
||
dropList.Clear();
|
||
dropList = new List<string>() { "运用工业现场总线技术", "运用工业以太网技术", "运用工业无线通信技术", "运用数据互通技术" };
|
||
dropdown.AddOptions(dropList);
|
||
dropdown.transform.GetChild(0).GetComponent<Text>().text = dropdown.options[0].text;
|
||
taskName = dropdown.options[0].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
break;
|
||
case "网络建设":
|
||
dropList.Clear();
|
||
dropList = new List<string>() { "规划工业网络系统", "实施工业网络集成", "运维工业网络系统" };
|
||
dropdown.AddOptions(dropList);
|
||
dropdown.transform.GetChild(0).GetComponent<Text>().text = dropdown.options[0].text;
|
||
taskName = dropdown.options[0].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
break;
|
||
case "网络巡检":
|
||
dropList.Clear();
|
||
dropList = new List<string>() { "巡检网络设备", "监测网络环境"};
|
||
dropdown.AddOptions(dropList);
|
||
dropdown.transform.GetChild(0).GetComponent<Text>().text = dropdown.options[0].text;
|
||
taskName = dropdown.options[0].text;
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
// dropdown.options.Clear();
|
||
|
||
//dropdown.AddOptions
|
||
|
||
|
||
//taskName = dropdown.captionText;
|
||
}
|
||
public string taskName = "区分工业互联网网络场景";
|
||
public void StartAnswer(string taskName)
|
||
{
|
||
for (int i = 0; i < QuestionPanel.questionPanelData.Count; i++)
|
||
{
|
||
if (QuestionPanel.questionPanelData[i].Panel.Equals(taskName))
|
||
{
|
||
InitQuestionPanel(QuestionPanel.questionPanelData[i]);
|
||
}
|
||
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 加载xml文件的协程
|
||
/// </summary>
|
||
/// <param name="path">文件路径</param>
|
||
/// <returns></returns>
|
||
IEnumerator LoadingQuesiton(string path)
|
||
{
|
||
yield return null;
|
||
using (WWW www = new WWW(path))
|
||
{
|
||
yield return www;
|
||
XmlDocument doc = new XmlDocument();
|
||
doc.LoadXml(www.text);
|
||
new QuestionPanel(doc.FirstChild);
|
||
Debug.Log(QuestionPanel.questionPanelData.Count);
|
||
StartAnswer(taskName);
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 初始化第一道题
|
||
/// </summary>
|
||
/// <param name="questionPanelData"></param>
|
||
public void InitQuestionPanel(QuestionPanelData questionPanelData)
|
||
{
|
||
//this.gameObject.SetActive(true);
|
||
mQuestionCount = 0;
|
||
mQuestionPanelData = questionPanelData;
|
||
fillTexts.Clear();
|
||
shortTexts.Clear();
|
||
toggleGroups.Clear();
|
||
for (int i = 0; i < questionPanelData.questionData.Count; i++)
|
||
{
|
||
CreateQuestion(questionPanelData.questionData[i]);
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 创建题目
|
||
/// </summary>
|
||
/// <param name="questionData"></param>
|
||
private void CreateQuestion(QuestionData questionData)
|
||
{
|
||
// 单选题
|
||
if (questionData.isSingleChoice && questionData.isShortAnswerChoice == false)
|
||
{
|
||
mQuestionData = questionData;
|
||
mQuestion = GameObject.Instantiate(Resources.Load<GameObject>(DataPath.QuestionText));
|
||
mQuestion.transform.SetParent(selectRoot);
|
||
mQuestion.transform.localScale = Vector3.one;
|
||
mQuestion.GetComponent<Text>().text = questionData.problem;
|
||
ToggleGroup optionGroup = mQuestion.AddComponent<ToggleGroup>();
|
||
optionGroup.allowSwitchOff = true;
|
||
toggleGroups.Add(optionGroup);
|
||
//options = new List<Options>();
|
||
for (int i = 0; i < questionData.answerData.Count; i++)
|
||
{
|
||
Options option = GameObject.Instantiate(Resources.Load<Options>("UI/NetworkFramePanel/Prefabs/Options"));
|
||
option.Init(questionData.answerData[i], questionData);
|
||
option.transform.SetParent(selectRoot);
|
||
option.thisToggle.group = optionGroup;
|
||
options.Add(option);
|
||
}
|
||
selectCount++;
|
||
|
||
GameObject subpanel = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/SelectSubmitBG"), selectRoot);
|
||
list_selectsubgo.Add(subpanel);
|
||
subpanel.gameObject.SetActive(false);
|
||
text_Choose.gameObject.SetActive(true);
|
||
}
|
||
// 填空题
|
||
if (questionData.isSingleChoice == false && questionData.isShortAnswerChoice == false)
|
||
{
|
||
mQuestionData = questionData;
|
||
mQuestion = GameObject.Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/FillText"));
|
||
FillText ft = mQuestion.GetComponent<FillText>();
|
||
ft.Init(questionData.fillData, questionData);
|
||
mQuestion.transform.SetParent(fillRoot);
|
||
mQuestion.transform.localScale = Vector3.one;
|
||
fillTexts.Add(ft);
|
||
// 答案
|
||
// 本体
|
||
if (questionData.problem.Contains("_________1_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_1_");
|
||
|
||
}
|
||
if (questionData.problem.Contains("_________2_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_2_");
|
||
}
|
||
if (questionData.problem.Contains("_________3_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_3_");
|
||
}
|
||
if (questionData.problem.Contains("_________4_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_4_");
|
||
}
|
||
if (questionData.problem.Contains("_________5_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_5_");
|
||
}
|
||
if (questionData.problem.Contains("_________6_________"))
|
||
{
|
||
GameObject g = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/InputField"), mQuestion.transform);
|
||
g.GetComponent<RectTransform>().position = GetPosAtText(canvas, mQuestion.GetComponent<Text>(), "_6_");
|
||
}
|
||
//GameObject subpanel = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/fillsubmitBG"), fillRoot);
|
||
//没有选择题的话就不显示选择题标题,此方法感觉不稳妥,后续修改(根据读取Question.xml配置表配值的先填空再选择的顺序来读取的,先faslse后true) todo
|
||
text_Choose.gameObject.SetActive(false);
|
||
|
||
GameObject subpanel = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/FillSubmitBG"), fillRoot);
|
||
list_fillsubgo.Add(subpanel);
|
||
subpanel.gameObject.SetActive(false);
|
||
}
|
||
//简答题
|
||
if (questionData.isSingleChoice && questionData.isShortAnswerChoice)
|
||
{
|
||
mQuestionData = questionData;
|
||
mQuestion = GameObject.Instantiate(Resources.Load<GameObject>(DataPath.ShortQuestionText));
|
||
ShortText st = mQuestion.GetComponent<ShortText>();
|
||
st.Init(questionData.shortanswerData, questionData);
|
||
mQuestion.transform.SetParent(shortRoot);
|
||
mQuestion.transform.localScale = Vector3.one;
|
||
shortTexts.Add(st);
|
||
//mQuestion.GetComponent<Text>().text = questionData.problem;
|
||
|
||
|
||
//简答题输入框
|
||
GameObject short_input = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/ShortInputField"), shortRoot);
|
||
list_shortinput.Add(short_input);
|
||
//简答题参考答案
|
||
GameObject shrot_answer = Instantiate(Resources.Load<GameObject>("UI/NetworkFramePanel/Prefabs/ShortAnswerRoot"), shortRoot);
|
||
list_shortsubgo.Add(shrot_answer);
|
||
shrot_answer.gameObject.SetActive(false);
|
||
|
||
if (questionData.shortanswerData[0].isLoadPicture)//判断是否需要上传图片
|
||
{
|
||
//上传图片
|
||
short_input.GetComponent<InputField>().interactable = false;
|
||
short_input.transform.Find("tip").gameObject.SetActive(true);
|
||
short_input.transform.Find("选择").gameObject.SetActive(true);
|
||
short_input.transform.Find("value").gameObject.SetActive(true);
|
||
short_input.transform.Find("RawImage").gameObject.SetActive(false);
|
||
short_input.transform.Find("tip").GetComponent<Text>().text = questionData.shortanswerData[0].tip;
|
||
short_input.transform.Find("选择").GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
//选择上传图片
|
||
string path=FileChose.ChoseFile();
|
||
if(path != null)
|
||
{
|
||
short_input.transform.Find("value").GetComponent<Text>().text= path;
|
||
}
|
||
else
|
||
{
|
||
short_input.transform.Find("value").GetComponent<Text>().text = "";
|
||
}
|
||
});
|
||
}
|
||
else
|
||
{
|
||
//不上传图片
|
||
short_input.GetComponent<InputField>().interactable = true ;
|
||
short_input.transform.Find("tip").gameObject.SetActive(false);
|
||
short_input.transform.Find("选择").gameObject.SetActive(false);
|
||
short_input.transform.Find("value").gameObject.SetActive(false);
|
||
short_input.transform.Find("RawImage").gameObject.SetActive(false);
|
||
}
|
||
|
||
//初始化ui
|
||
st.SetUI(short_input.GetComponent<InputField>(), short_input.transform.Find("value").GetComponent<Text>(), short_input.transform.Find("RawImage").GetComponent<RawImage>(), shrot_answer.transform.Find("RawImage").GetComponent<RawImage>(), short_input.transform.Find("tip").GetComponent<Text>(), shrot_answer.transform.Find("RawImage").GetComponent<Button>());
|
||
}
|
||
}
|
||
|
||
public Vector3 GetPosAtText(Canvas canvas, Text text, string strFragment)
|
||
{
|
||
int strFragmentIndex = text.text.IndexOf(strFragment);
|
||
Vector3 stringPos = Vector3.zero;
|
||
if (strFragmentIndex > -1)
|
||
{
|
||
Vector3 firstPos = GetPosAtText(canvas, text, strFragmentIndex + 1);
|
||
Vector3 lastPos = GetPosAtText(canvas, text, strFragmentIndex + strFragment.Length);
|
||
stringPos = (firstPos + lastPos) * 0.5f;
|
||
}
|
||
else
|
||
{
|
||
stringPos = GetPosAtText(canvas, text, strFragmentIndex);
|
||
}
|
||
stringPos = new Vector3(stringPos.x, stringPos.y + 21, stringPos.z);
|
||
return stringPos;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 得到Text中字符的位置;canvas:所在的Canvas,text:需要定位的Text,charIndex:Text中的字符位置
|
||
/// </summary>
|
||
public Vector3 GetPosAtText(Canvas canvas, Text text, int charIndex)
|
||
{
|
||
string textStr = text.text;
|
||
Vector3 charPos = Vector3.zero;
|
||
if (charIndex <= textStr.Length && charIndex > 0)
|
||
{
|
||
TextGenerator textGen = new TextGenerator(textStr.Length);
|
||
Vector2 extents = text.gameObject.GetComponent<RectTransform>().rect.size;
|
||
textGen.Populate(textStr, text.GetGenerationSettings(extents));
|
||
|
||
int newLine = textStr.Substring(0, charIndex).Split('\n').Length - 1;
|
||
int whiteSpace = textStr.Substring(0, charIndex).Split(' ').Length - 1;
|
||
int indexOfTextQuad = (charIndex * 4) + (newLine * 4) - 4;
|
||
if (indexOfTextQuad < textGen.vertexCount)
|
||
{
|
||
charPos = (textGen.verts[indexOfTextQuad].position +
|
||
textGen.verts[indexOfTextQuad + 1].position +
|
||
textGen.verts[indexOfTextQuad + 2].position +
|
||
textGen.verts[indexOfTextQuad + 3].position) / 4f;
|
||
|
||
|
||
}
|
||
}
|
||
charPos /= canvas.scaleFactor;//适应不同分辨率的屏幕
|
||
charPos = text.transform.TransformPoint(charPos);//转换为世界坐标
|
||
return charPos;
|
||
}
|
||
|
||
private string rightAnswer;
|
||
|
||
/// <summary>
|
||
/// 提交事件
|
||
/// 填空题 填写顺序需要和参考答案一致
|
||
/// </summary>
|
||
private void submitClick()
|
||
{
|
||
List<QuestionItem> resultList = new List<QuestionItem>();
|
||
int sright = 0;
|
||
int no = 0;
|
||
btn_Submit_mask.gameObject.SetActive(true);
|
||
dropDown_mask.gameObject.SetActive(true);
|
||
//单选题
|
||
foreach (var group in toggleGroups)
|
||
{
|
||
no++;
|
||
QuestionItem result = new QuestionItem();
|
||
rightAnswer = "";
|
||
if (group.AnyTogglesOn())
|
||
{
|
||
Toggle toggle = group.GetFirstActiveToggle();
|
||
Options item = toggle.GetComponent<Options>();
|
||
string select = item.optionText.text.Substring(0, 1);
|
||
for (int j = 0; j < QuestionPanel.questionPanelData.Count; j++)
|
||
{
|
||
foreach (var questionDataitem in QuestionPanel.questionPanelData[j].questionData)
|
||
{
|
||
if (questionDataitem.isSingleChoice && questionDataitem.isShortAnswerChoice==false)//如果是选择题
|
||
{
|
||
if (questionDataitem.problem.Equals(item.questionData.problem))//用xml文件里的数据和面板文字框里的数据做对比,如果相等
|
||
{
|
||
|
||
for (int i = 0; i < questionDataitem.answerData.Count; i++)
|
||
{
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
if (questionDataitem.answerData[i].Score > 0)//大于0就是正确选项
|
||
{
|
||
rightAnswer += "A";
|
||
}
|
||
break;
|
||
case 1:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "B";
|
||
}
|
||
break;
|
||
case 2:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "C";
|
||
}
|
||
break;
|
||
case 3:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "D";
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if (rightAnswer.Equals(select))//如果正确答案和选择出的答案相等
|
||
{
|
||
sright++;
|
||
result.result = 1;
|
||
}
|
||
|
||
result.no = no;
|
||
result.questionType = "选择题";
|
||
result.yourAnswer = select;
|
||
result.rightAnswer = rightAnswer;
|
||
resultList.Add(result);
|
||
Debug.Log(String.Format("{0}正确选项是:{1}", questionDataitem.problem, rightAnswer));
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else//未选择
|
||
{
|
||
for (int j = 0; j < QuestionPanel.questionPanelData.Count; j++)
|
||
{
|
||
foreach (var questionDataitem in QuestionPanel.questionPanelData[j].questionData)
|
||
{
|
||
if (questionDataitem.isSingleChoice && questionDataitem.isShortAnswerChoice == false)
|
||
{
|
||
if (questionDataitem.problem.Equals(group.GetComponent<Text>().text))
|
||
{
|
||
for (int i = 0; i < questionDataitem.answerData.Count; i++)
|
||
{
|
||
switch (i)
|
||
{
|
||
case 0:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "A";
|
||
}
|
||
break;
|
||
case 1:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "B";
|
||
}
|
||
break;
|
||
case 2:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "C";
|
||
}
|
||
break;
|
||
case 3:
|
||
if (questionDataitem.answerData[i].Score > 0)
|
||
{
|
||
rightAnswer += "D";
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
Debug.Log("未选择");
|
||
result.no = no;
|
||
result.questionType = "选择题";
|
||
result.yourAnswer = "未选择";
|
||
result.rightAnswer = rightAnswer;
|
||
resultList.Add(result);
|
||
}
|
||
}
|
||
|
||
|
||
no = 0;
|
||
InputField[] inputs;
|
||
// 填空题
|
||
foreach (var item in fillTexts)
|
||
{
|
||
QuestionItem result = new QuestionItem();
|
||
no++;
|
||
int rightSpce = 0;
|
||
string rightAnswer = string.Empty;
|
||
string yourAnswer = string.Empty;
|
||
inputs = item.transform.GetComponentsInChildren<InputField>();
|
||
|
||
//当前题目的正确答案 字符串
|
||
for (int i = 0; i < item.fillDates.Count; i++)
|
||
{
|
||
rightAnswer += item.fillDates[i].option;// 填空题1 、填空题2 、填空题3、
|
||
if (i != item.fillDates.Count-1)
|
||
{
|
||
rightAnswer += "、";
|
||
}
|
||
}
|
||
|
||
//你输入的答案
|
||
for (int i = 0; i < inputs.Length; i++)
|
||
{
|
||
yourAnswer += inputs[i].text == string.Empty ? null : inputs[i].text;//输入的所有答案
|
||
if (i != item.fillDates.Count - 1 && inputs[i].text != string.Empty && inputs[i+1].text != string.Empty)
|
||
{
|
||
yourAnswer += "、";
|
||
}
|
||
Debug.Log(inputs[i].text +"__" + item.fillDates[i].option);
|
||
|
||
if (inputs[i].text == item.fillDates[i].option)
|
||
{
|
||
rightSpce++;
|
||
item.fillDates[i].isMatch = true;
|
||
}
|
||
}
|
||
|
||
result.questionType = "填空题";
|
||
result.no = no;
|
||
result.allspace = inputs.Length;
|
||
result.rightSpace = rightSpce;
|
||
result.rightAnswer = rightAnswer;
|
||
result.yourAnswer = yourAnswer;
|
||
resultList.Add(result);
|
||
}
|
||
|
||
no = 0;
|
||
Dictionary<string, byte[]> files = new Dictionary<string, byte[]>();
|
||
// 简答题
|
||
foreach (var item in shortTexts)
|
||
{
|
||
|
||
QuestionItem result = new QuestionItem();
|
||
string rightAnswer = ""; //参考答案
|
||
no++;
|
||
foreach (var shortanswer in item.shortDates)
|
||
{
|
||
rightAnswer = shortanswer.option;
|
||
result.isLoadPic = shortanswer.isLoadPicture;
|
||
result.path = shortanswer.path;
|
||
}
|
||
|
||
result.questionType = "简答题";
|
||
result.no = no;
|
||
result.rightAnswer = rightAnswer;
|
||
if (!result.isLoadPic)
|
||
{
|
||
result.yourAnswer = item.myanswer.text;
|
||
}
|
||
else
|
||
{
|
||
result.yourAnswer = item.myPicAnswerText.text;
|
||
if (File.Exists(result.yourAnswer))
|
||
{
|
||
files.Add(no.ToString(), File.ReadAllBytes(result.yourAnswer));
|
||
}
|
||
|
||
string path = Application.streamingAssetsPath + "/cxx/参考答案图片/" +result.path;
|
||
if (File.Exists(path))
|
||
{
|
||
files.Add(no.ToString()+"_2", File.ReadAllBytes(path));
|
||
}
|
||
}
|
||
resultList.Add(result);
|
||
}
|
||
|
||
string url = LoginFlowManager.loginIP+ "/Handler/ResultDetail.ashx";
|
||
// userid
|
||
string userId = LoginFlowManager.user.user_id;
|
||
// 科目名
|
||
string subjectName = taskName;
|
||
// 总分
|
||
float total = 100;
|
||
// 得分
|
||
float score = 0;
|
||
// 计算每题分数 选择是没空的2倍分数
|
||
int tempSelectCount = 0;
|
||
int tempFillCount = 0;
|
||
// 序号
|
||
foreach (var item in resultList)
|
||
{
|
||
if (item.questionType == "选择题")
|
||
{
|
||
tempSelectCount++;
|
||
}
|
||
else if (item.questionType == "填空题")
|
||
{
|
||
tempFillCount += item.allspace;
|
||
}
|
||
}
|
||
float subScore = 100f / (tempSelectCount * 2 + tempFillCount);
|
||
foreach (var item in resultList)
|
||
{
|
||
if (item.questionType == "选择题")
|
||
{
|
||
item.total = subScore * 2;
|
||
if (item.result == 1)
|
||
{
|
||
item.score = subScore * 2;
|
||
score += item.score;
|
||
}
|
||
}
|
||
else if (item.questionType == "填空题")
|
||
{
|
||
item.total = subScore * item.allspace;
|
||
item.score = subScore * item.rightSpace;
|
||
score += item.score;
|
||
}
|
||
}
|
||
|
||
QuestionResult question = new QuestionResult();
|
||
question.score = score;
|
||
question.user_id = userId;
|
||
question.total = total;
|
||
question.subject = subjectName;
|
||
string res = JsonConvert.SerializeObject(question);
|
||
string js = JsonConvert.SerializeObject(resultList);
|
||
Debug.Log(js);
|
||
Dictionary<string, string> dict = new Dictionary<string, string>();
|
||
dict.Add("action", "saveresult");
|
||
dict.Add("exam_result", res);
|
||
dict.Add("exam_result_detail", js);
|
||
|
||
|
||
StartCoroutine(Request.Post(url, dict,files, (b, s) =>
|
||
{
|
||
// 回调
|
||
if (b)
|
||
{
|
||
XFrame.Core.UI.XUIPanel.ShowPanel<TipPanel>("成绩上传成功");
|
||
image_exam.sprite = Resources.Load<Sprite>("UI/Submit/submitBG");
|
||
text_title.text = question.subject;
|
||
returnBtn.gameObject.SetActive(true);
|
||
btn_Submit_mask.gameObject.SetActive(false);
|
||
dropDown_mask.gameObject.SetActive(false);
|
||
dropdown.gameObject.SetActive(false);
|
||
|
||
//提交完成之后显示提交反馈界面
|
||
for (int i = 0; i < resultList.Count; )
|
||
{
|
||
if (resultList[i].questionType == "选择题")
|
||
{
|
||
for (int j = 0; j < list_selectsubgo.Count; j++)
|
||
{
|
||
list_selectsubgo[j].gameObject.SetActive(true);
|
||
list_selectsubgo[j].GetComponent<SelectSubText>().init(resultList[i].yourAnswer,resultList[i].rightAnswer);
|
||
i++;
|
||
}
|
||
}
|
||
else if (resultList[i].questionType == "填空题")
|
||
{
|
||
for (int k = 0; k < list_fillsubgo.Count; k++)
|
||
{
|
||
list_fillsubgo[k].gameObject.SetActive(true);
|
||
list_fillsubgo[k].GetComponent<FillSubText>().init(resultList[i].yourAnswer,resultList[i].rightAnswer);
|
||
i++;
|
||
}
|
||
}
|
||
else if (resultList[i].questionType == "简答题")
|
||
{
|
||
for (int j = 0; j < list_shortsubgo.Count; j++)
|
||
{
|
||
list_shortsubgo[j].gameObject.SetActive(true);
|
||
int index = list_shortsubgo[j].transform.Find("ContentText").parent.GetSiblingIndex();
|
||
Debug.Log(index);
|
||
if (resultList[i].isLoadPic)
|
||
{
|
||
//隐藏选择按钮
|
||
shortTexts[j].myanswer.transform.Find("选择").gameObject.SetActive(false);
|
||
shortTexts[j].myanswer.transform.Find("tip").gameObject.SetActive(false);
|
||
//我的答案
|
||
if (File.Exists(resultList[i].yourAnswer))
|
||
{
|
||
RawImage raw = shortTexts[j].myAnswerRawimage;
|
||
raw.gameObject.SetActive(true);
|
||
shortTexts[j].myPicAnswerText.gameObject.SetActive(false);
|
||
shortTexts[j].tipText.gameObject.SetActive(false);
|
||
byte[] picture = File.ReadAllBytes(resultList[i].yourAnswer);
|
||
shortTexts[j].mypic= new Texture2D((int)(raw.rectTransform.rect.width), (int)(raw.rectTransform.rect.height));
|
||
shortTexts[j].mypic.LoadImage(picture);
|
||
raw.texture = shortTexts[j].mypic;
|
||
}
|
||
|
||
//标准答案
|
||
string path = Application.streamingAssetsPath + "/cxx/参考答案图片/" + resultList[i].path;
|
||
if (File.Exists(path))
|
||
{
|
||
//RawImage raw = list_shortsubgo[j].transform.Find("RawImage").GetComponent<RawImage>();
|
||
RawImage raw = shortTexts[j].rightAnswerRawimage;
|
||
raw.gameObject.SetActive(true);
|
||
list_shortsubgo[j].transform.Find("ContentText").gameObject.SetActive(false);
|
||
shortTexts[j].myanswer.text = "您的答案:";
|
||
//加载标准答案图片
|
||
byte[] picture=File.ReadAllBytes(path);
|
||
shortTexts[j].rightPic= new Texture2D((int)(raw.rectTransform.rect.width), (int)(raw.rectTransform.rect.height));
|
||
shortTexts[j].rightPic.LoadImage(picture);
|
||
raw.texture = shortTexts[j].rightPic;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//我的答案
|
||
shortTexts[j].myanswer.text = "您的答案:"+resultList[i].yourAnswer;
|
||
//标准答案
|
||
list_shortsubgo[j].transform.Find("RawImage").gameObject.SetActive(false);
|
||
shortTexts[j].myAnswerRawimage.gameObject.SetActive(false);
|
||
list_shortsubgo[j].transform.Find("ContentText").gameObject.SetActive(true);
|
||
list_shortsubgo[j].transform.Find("ContentText").GetComponent<Text>().text = resultList[i].rightAnswer;
|
||
|
||
}
|
||
|
||
i++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
XFrame.Core.UI.XUIPanel.ShowPanel<TipPanel>("上传失败");
|
||
}
|
||
}));
|
||
//}
|
||
}
|
||
|
||
private void ReturnClick()
|
||
{
|
||
dropdown.gameObject.SetActive(true);
|
||
returnBtn.gameObject.SetActive(false);
|
||
InitExamBG();
|
||
for (int i = 1; i < fillRoot.childCount; i++)
|
||
{
|
||
Destroy(fillRoot.GetChild(i).gameObject);
|
||
}
|
||
for (int i = 1; i < selectRoot.childCount; i++)
|
||
{
|
||
Destroy(selectRoot.GetChild(i).gameObject);
|
||
}
|
||
for (int i = 1; i < shortRoot.childCount; i++)
|
||
{
|
||
Destroy(shortRoot.GetChild(i).gameObject);
|
||
}
|
||
list_fillsubgo.Clear();
|
||
list_selectsubgo.Clear();
|
||
list_shortsubgo.Clear();
|
||
StartCoroutine(LoadingQuesiton(DataPath.QuestionData));
|
||
}
|
||
}
|
||
|
||
class QuestionResult
|
||
{
|
||
public string user_id;
|
||
public string subject; // 科目名
|
||
public float total;
|
||
public float score;
|
||
public string sjms = "考核";
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单个题目
|
||
/// </summary>
|
||
class QuestionItem
|
||
{
|
||
/// <summary>
|
||
/// 题号
|
||
/// </summary>
|
||
public int no;
|
||
/// <summary>
|
||
/// 题目类型
|
||
/// </summary>
|
||
public string questionType;
|
||
/// <summary>
|
||
/// 答案
|
||
/// </summary>
|
||
public string rightAnswer;
|
||
/// <summary>
|
||
/// 你的答案
|
||
/// </summary>
|
||
public string yourAnswer;
|
||
/// <summary>
|
||
/// 填空题空格数
|
||
/// </summary>
|
||
public int allspace;
|
||
/// <summary>
|
||
/// 正确空数
|
||
/// </summary>
|
||
public int rightSpace;
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public int result = 0;
|
||
/// <summary>
|
||
/// 得分
|
||
/// </summary>
|
||
public float score= 0;
|
||
/// <summary>
|
||
/// 题目分值
|
||
/// </summary>
|
||
public float total=0;
|
||
|
||
/// <summary>
|
||
/// 是否上传图片
|
||
/// </summary>
|
||
public bool isLoadPic;
|
||
|
||
/// <summary>
|
||
/// 图片路径
|
||
/// </summary>
|
||
public string path;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 答题界面数据类
|
||
/// </summary>
|
||
public class QuestionPanel
|
||
{
|
||
|
||
public static List<QuestionPanelData> questionPanelData;
|
||
public QuestionPanel(XmlNode node)
|
||
{
|
||
|
||
questionPanelData = new List<QuestionPanelData>();
|
||
for (int i = 0; i < node.ChildNodes.Count; i++)
|
||
{
|
||
questionPanelData.Add(new QuestionPanelData(node.ChildNodes[i]));
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 答题界面数据类
|
||
/// </summary>
|
||
public class QuestionPanelData
|
||
{
|
||
public string Panel;
|
||
public List<QuestionData> questionData;
|
||
public QuestionPanelData(XmlNode node)
|
||
{
|
||
Panel = node.Attributes["Task"].InnerText;
|
||
questionData = new List<QuestionData>();
|
||
for (int i = 0; i < node.ChildNodes.Count; i++)
|
||
{
|
||
questionData.Add(new QuestionData(node.ChildNodes[i]));
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 题目数据类
|
||
/// </summary>
|
||
public class QuestionData
|
||
{
|
||
/// <summary>
|
||
/// 是否为单选,true为单选,false为多选
|
||
/// </summary>
|
||
public bool isSingleChoice;
|
||
/// <summary>
|
||
/// 是否为简答题
|
||
/// </summary>
|
||
public bool isShortAnswerChoice;
|
||
|
||
/// <summary>
|
||
/// 题目内容
|
||
/// </summary>
|
||
public string problem;
|
||
/// <summary>
|
||
/// 选择题选项
|
||
/// </summary>
|
||
public List<AnswerData> answerData;
|
||
/// <summary>
|
||
/// 简答题
|
||
/// </summary>
|
||
public List<ShortAnswerData> shortanswerData;
|
||
/// <summary>
|
||
/// 填空题选项
|
||
/// </summary>
|
||
public List<FillData> fillData;
|
||
|
||
public QuestionData(XmlNode node)
|
||
{
|
||
isSingleChoice = bool.Parse(node.Attributes["SelectType"].InnerText);
|
||
isShortAnswerChoice = bool.Parse(node.Attributes["ShortType"].InnerText);
|
||
// if (isSingleChoice)
|
||
// {
|
||
// problem = node["Problem"].InnerText;
|
||
// answerData = new List<AnswerData>();
|
||
// XmlNodeList nodelist = node["Answer"].ChildNodes;
|
||
// for (int i = 0; i < nodelist.Count; i++)
|
||
// {
|
||
// answerData.Add(new AnswerData(nodelist[i]));
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// problem = node["Problem"].InnerText;
|
||
// fillData = new List<FillData>();
|
||
// XmlNodeList nodelist = node["Answer"].ChildNodes;
|
||
// for (int i = 0; i < nodelist.Count; i++)
|
||
// {
|
||
// fillData.Add(new FillData(nodelist[i]));
|
||
// }
|
||
// }
|
||
if(isSingleChoice==false && isShortAnswerChoice==false)//填空题
|
||
{
|
||
problem = node["Problem"].InnerText;
|
||
fillData = new List<FillData>();
|
||
XmlNodeList nodelist = node["Answer"].ChildNodes;
|
||
for (int i = 0; i < nodelist.Count; i++)
|
||
{
|
||
fillData.Add(new FillData(nodelist[i]));
|
||
}
|
||
}
|
||
if (isSingleChoice && isShortAnswerChoice==false) //选择题
|
||
{
|
||
problem = node["Problem"].InnerText;
|
||
answerData = new List<AnswerData>();
|
||
XmlNodeList nodelist = node["Answer"].ChildNodes;
|
||
for (int i = 0; i < nodelist.Count; i++)
|
||
{
|
||
answerData.Add(new AnswerData(nodelist[i]));
|
||
}
|
||
}
|
||
if (isSingleChoice && isShortAnswerChoice)
|
||
{
|
||
problem = node["Problem"].InnerText;
|
||
shortanswerData = new List<ShortAnswerData>();
|
||
XmlNodeList nodelist = node["Answer"].ChildNodes;
|
||
for (int i = 0; i < nodelist.Count; i++)
|
||
{
|
||
shortanswerData.Add(new ShortAnswerData(nodelist[i]));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 选择题答案数据类
|
||
/// </summary>
|
||
public class AnswerData
|
||
{
|
||
/// <summary>
|
||
/// 选项的内容
|
||
/// </summary>
|
||
public string option;
|
||
/// <summary>
|
||
/// 选项对应的分数
|
||
/// </summary>
|
||
public int Score;
|
||
public AnswerData(XmlNode node)
|
||
{
|
||
option = node.Attributes["option"].InnerText;
|
||
Score = int.Parse(node.InnerText);
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 简答题数据类
|
||
/// </summary>
|
||
public class ShortAnswerData
|
||
{
|
||
/// <summary>
|
||
/// 选项的内容
|
||
/// </summary>
|
||
public string option;
|
||
/// <summary>
|
||
/// 选项对应的分数
|
||
/// </summary>
|
||
public int Score;
|
||
/// <summary>
|
||
/// 是否上传图片
|
||
/// </summary>
|
||
public bool isLoadPicture;
|
||
/// <summary>
|
||
/// 标准答案路径
|
||
/// </summary>
|
||
public string path;
|
||
/// <summary>
|
||
/// 上传图片提示
|
||
/// </summary>
|
||
public string tip;
|
||
public ShortAnswerData(XmlNode node)
|
||
{
|
||
option = node.Attributes["option"].InnerText;
|
||
Score = int.Parse(node.InnerText);
|
||
|
||
var at1 = node.Attributes["path"];
|
||
var at2= node.Attributes["tip"];
|
||
if (at1 !=null && at2 !=null)
|
||
{
|
||
isLoadPicture = true;
|
||
path= at1.InnerText;
|
||
tip= at2.InnerText;
|
||
}
|
||
else
|
||
{
|
||
isLoadPicture = false;
|
||
path = "";
|
||
tip = "";
|
||
}
|
||
}
|
||
}
|
||
[Serializable]
|
||
public class FillData
|
||
{
|
||
/// <summary>
|
||
/// 选项的内容
|
||
/// </summary>
|
||
public string option;
|
||
/// <summary>
|
||
/// 一个填空多关键词
|
||
/// </summary>
|
||
public string[] subOptions;
|
||
/// <summary>
|
||
/// 提交判断比对标识
|
||
/// </summary>
|
||
public bool isMatch = false;
|
||
/// <summary>
|
||
/// 选项对应的分数
|
||
/// </summary>
|
||
public int Count;
|
||
public FillData(XmlNode node)
|
||
{
|
||
option = node.Attributes["Answer"].InnerText;
|
||
Count = int.Parse(node.InnerText);
|
||
subOptions = option.Split("||");
|
||
}
|
||
}
|
||
|