a11e003fcd
- 加权评分系统:每步独立 ScoreWeight,满分 100,SequenceClick 按子项比例计分 - StepData 新增 DetailedContent(学习模式详细操作说明)和 SubStepCount - 伤情检查步骤扩展为 5 子项序列(视觉检查→肿胀→疼痛→生命体征→神经评估) - 夹板固定模式完整评分(选择夹板→放置衬垫→夹板固定→固定后检查) - Doc/ 文件夹归档三份文档:项目大纲、文案、评分标准 - README 更新评分权重表和夹板固定流程
155 lines
4.8 KiB
C#
155 lines
4.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// 考核弹窗:选择题 + 操作确认。
|
|
/// 挂在弹窗 Panel 上,由 UIManager 调用 Show()。
|
|
/// 回调返回 proportion (0~1 得分比例) 和 feedback。
|
|
/// </summary>
|
|
public class ExamPopup : MonoBehaviour
|
|
{
|
|
[Header("UI 组件")]
|
|
[SerializeField] private GameObject _popupRoot;
|
|
[SerializeField] private TMP_Text _questionText;
|
|
[SerializeField] private Toggle[] _optionToggles;
|
|
[SerializeField] private TMP_Text[] _optionLabels;
|
|
[SerializeField] private Button _confirmButton;
|
|
[SerializeField] private TMP_Text _feedbackText;
|
|
|
|
[Header("操作题 UI(点击序列)")]
|
|
[SerializeField] private GameObject _operationPanel;
|
|
[SerializeField] private TMP_Text _operationHint;
|
|
|
|
private StepData _currentStep;
|
|
private Action<float, string> _onAnswerCallback;
|
|
private int _selectedIndex = -1;
|
|
|
|
private void Awake()
|
|
{
|
|
_confirmButton?.onClick.AddListener(OnConfirm);
|
|
if (_popupRoot != null) _popupRoot.SetActive(false);
|
|
}
|
|
|
|
public void Show(StepData step, Action<float, string> onAnswer)
|
|
{
|
|
_currentStep = step;
|
|
_onAnswerCallback = onAnswer;
|
|
_selectedIndex = -1;
|
|
if (_feedbackText != null) _feedbackText.text = "";
|
|
if (_popupRoot != null) _popupRoot.SetActive(true);
|
|
|
|
_questionText?.SetText(step.ExamQuestionText);
|
|
|
|
switch (step.CompleteType)
|
|
{
|
|
case StepCompleteType.MultipleChoice:
|
|
SetupMultipleChoice(step);
|
|
break;
|
|
case StepCompleteType.ClickObject:
|
|
SetupClickObject(step);
|
|
break;
|
|
case StepCompleteType.SequenceClick:
|
|
SetupSequenceClick(step);
|
|
break;
|
|
default:
|
|
SetupDefault(step);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#region 题型配置
|
|
|
|
private void SetupMultipleChoice(StepData step)
|
|
{
|
|
if (_operationPanel != null) _operationPanel.SetActive(false);
|
|
|
|
int optionCount = step.ExamOptions?.Length ?? 0;
|
|
for (int i = 0; i < _optionToggles.Length; i++)
|
|
{
|
|
bool active = i < optionCount;
|
|
_optionToggles[i].gameObject.SetActive(active);
|
|
_optionToggles[i].isOn = false;
|
|
_optionToggles[i].onValueChanged.RemoveAllListeners();
|
|
int idx = i;
|
|
_optionToggles[i].onValueChanged.AddListener((val) => { if (val) _selectedIndex = idx; });
|
|
if (active) _optionLabels[i]?.SetText(step.ExamOptions[i]);
|
|
}
|
|
|
|
_confirmButton?.gameObject.SetActive(true);
|
|
}
|
|
|
|
private void SetupClickObject(StepData step)
|
|
{
|
|
if (_operationPanel != null) _operationPanel.SetActive(true);
|
|
if (_optionToggles != null)
|
|
foreach (var t in _optionToggles) t.gameObject.SetActive(false);
|
|
_confirmButton?.gameObject.SetActive(true);
|
|
_operationHint?.SetText($"请点击场景中的 {step.TargetTag} 物体");
|
|
}
|
|
|
|
private void SetupSequenceClick(StepData step)
|
|
{
|
|
if (_operationPanel != null) _operationPanel.SetActive(true);
|
|
if (_optionToggles != null)
|
|
foreach (var t in _optionToggles) t.gameObject.SetActive(false);
|
|
_confirmButton?.gameObject.SetActive(true);
|
|
_operationHint?.SetText("请按正确顺序点击物体,完成后按确定");
|
|
}
|
|
|
|
private void SetupDefault(StepData step)
|
|
{
|
|
if (_operationPanel != null) _operationPanel.SetActive(false);
|
|
if (_optionToggles != null)
|
|
foreach (var t in _optionToggles) t.gameObject.SetActive(false);
|
|
_confirmButton?.gameObject.SetActive(true);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 确认与判定
|
|
|
|
private void OnConfirm()
|
|
{
|
|
if (_currentStep == null) return;
|
|
|
|
float proportion = 1f;
|
|
string feedback = "";
|
|
|
|
switch (_currentStep.CompleteType)
|
|
{
|
|
case StepCompleteType.MultipleChoice:
|
|
bool correct = _selectedIndex == _currentStep.CorrectOptionIndex;
|
|
proportion = correct ? 1f : 0f;
|
|
feedback = correct ? "" : _currentStep.ErrorFeedback;
|
|
if (!correct && _feedbackText != null)
|
|
_feedbackText.text = feedback;
|
|
break;
|
|
default:
|
|
proportion = 1f;
|
|
break;
|
|
}
|
|
|
|
if (proportion <= 0f && !string.IsNullOrEmpty(feedback))
|
|
{
|
|
_onAnswerCallback?.Invoke(0f, feedback);
|
|
Hide();
|
|
}
|
|
else
|
|
{
|
|
_onAnswerCallback?.Invoke(proportion, feedback);
|
|
Hide();
|
|
}
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (_popupRoot != null) _popupRoot.SetActive(false);
|
|
_currentStep = null;
|
|
_onAnswerCallback = null;
|
|
}
|
|
|
|
#endregion
|
|
}
|