EnergyEfficiencyManagement/Assets/Scripts/Test/QuestionExample.cs

88 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SK.Framework;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuestionExample : MonoBehaviour
{
public QuestionsProfile questionsProfile;
public QuestionsHandler questionsHandler;
private QuestionBase currectQuestion;
// Start is called before the first frame update
void Start()
{
questionsHandler = new QuestionsHandler(questionsProfile);
//获取选择内容
currectQuestion = questionsHandler.Switch(1);
//获取问题
Debug.Log(currectQuestion.Question);
GetQuestion();
List<SingleChoiceQuestion> mySingles = questionsProfile.SingleChoices;
}
/// <summary>
/// 具体操作
/// </summary>
void GetQuestion()
{
//第一种获取方式,通过题型和题号获取指定题目
///获取当前题号
int id = questionsHandler.GetCurrentSequence();
///获取当前题型
QuestionType questionType = currectQuestion.Type;
switch (questionType)
{
case QuestionType.SINGLE_CHOICE: //单选
//获取选项内容
Debug.Log(questionsHandler.Get<SingleChoiceQuestion>(id).Choices[1].text);
//传入当前选项判定对错
Debug.Log(questionsHandler.Get<SingleChoiceQuestion>(id).IsCorrect(0));
break;
}
//第二种获取方式。通过整个list获取自行管理
List<SingleChoiceQuestion> mySingles = questionsProfile.SingleChoices;
SingleChoiceQuestion single = mySingles[0];
//获取问题,同理获取题解,选项,是否正确
string que = single.Question;
int index= single.Answer;
bool isRight = single.IsCorrect(0);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
currectQuestion = questionsHandler.Last();
Debug.Log(currectQuestion.Question);
}
if (Input.GetKeyDown(KeyCode.D))
{
currectQuestion = questionsHandler.Next();
Debug.Log(currectQuestion.Question);
}
if (Input.GetKeyDown(KeyCode.S))
{
currectQuestion = questionsHandler.Switch(5);
Debug.Log(currectQuestion.Question);
}
}
}