Unity SKFramework框架(十三)、Question 问题模块

本文介绍如何创建和编辑问题配置文件,详解QuestionsProfile与QuestionsHandler在问题管理中的作用,包括初始化、导航和根据题号操作,以及使用示例。涵盖了多种题型和QuestionsHandler的实用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、Questions Profile 问题配置文件

1.配置文件的创建

2.配置文件的编辑

二、Questions Handler 问题处理器

1.初始化

2.Last、Next、Switch

3.根据题号获取指定的问题

三、Example 示例


一、Questions Profile 问题配置文件

1.配置文件的创建

通过右键/Create/Question Profile菜单进行创建

2.配置文件的编辑

如图所示,模块中内置了五种题型,可以在配置文件中进行配置,分别是判断题单选题多选题填空题论述题,它们均继承自Question Base基类。

1).判断题

2).单选题

3).多选题

4).填空题

5).论述题

二、Questions Handler 问题处理器

1.初始化

QuestionsHandler包含两个构造函数

/// <summary>
/// 构造函数
/// </summary>
/// <param name="profile">问题配置文件</param>
public QuestionsHandler(QuestionsProfile profile)
/// <summary>
/// 构造函数
/// </summary>
/// <param name="resourcesPath">配置文件的路径</param>
public QuestionsHandler(string resourcesPath)

2.Last、Next、Switch

/// <summary>
/// 上一题
/// </summary>
public QuestionBase Last()
/// <summary>
/// 下一题
/// </summary>
public QuestionBase Next()
/// <summary>
/// 根据题号切换到指定问题
/// </summary>
/// <param name="sequence">题号</param>
public QuestionBase Switch(int sequence)

3.根据题号获取指定的问题

/// <summary>
/// 根据题号获取问题
/// </summary>
/// <typeparam name="T">题型</typeparam>
/// <param name="sequence">题号</param>
public T Get<T>(int sequence) where T : QuestionBase

三、Example 示例

using UnityEngine;
using SK.Framework;

public class Example : MonoBehaviour
{
    private QuestionsHandler handler;
    private QuestionBase question;

    private void Start()
    {
        handler = new QuestionsHandler("New Questions Profile");    
    }

    private void OnGUI()
    {
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Last", GUILayout.Width(200f), GUILayout.Height(50f))) 
            question = handler.Last();
        if (GUILayout.Button("Next", GUILayout.Width(200f), GUILayout.Height(50f))) 
            question = handler.Next();
        GUILayout.EndHorizontal();

        if (question == null) return;

        switch (question.Type)
        {
            case QuestionType.JUDGE: break;
            case QuestionType.SINGLE_CHOICE:
                GUILayout.Label(string.Format(" {0}.{1}", question.Sequence, question.Question));
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("A")) Debug.Log(question.IsCorrect(0));
                if (GUILayout.Button("B")) Debug.Log(question.IsCorrect(1));
                if (GUILayout.Button("C")) Debug.Log(question.IsCorrect(2));
                if (GUILayout.Button("D")) Debug.Log(question.IsCorrect(3));
                GUILayout.EndHorizontal();
                break;
            case QuestionType.MULTIPLE_CHOICE: break;
            case QuestionType.COMPLETION: break;
            case QuestionType.ESSAY: break;
            default: break;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CoderZ1010

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值