feat: 场景优化 - 清理重复对象、设置Tags/Colliders、重建Canvas UI、连线Inspector引用
- 删除顶层重复的 GameManager/ExperimentController/InteractionSystem/AnimationController - 移除Canvas上的旧 HUDController(保留 UIManager) - 为14个交互定位点设置Tag并添加SphereCollider - 创建12个自定义Tag(InjuryVisual/Swelling/Pain/VitalSigns/Neuro/BandagePos1-3/Ankle/PaddingPos/SplintLeft/SplintRight) - 完全重建Canvas UI子对象结构以匹配 UIManager 脚本 - 连线 ExperimentFlowCoordinator 和 UIManager 的所有 serialized fields - 编译零错误,游戏画面正常显示
This commit is contained in:
@@ -1,26 +1,24 @@
|
||||
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 Text _questionText;
|
||||
[SerializeField] private Toggle[] _optionToggles;
|
||||
[SerializeField] private TMP_Text[] _optionLabels;
|
||||
[SerializeField] private Text[] _optionLabels;
|
||||
[SerializeField] private Button _confirmButton;
|
||||
[SerializeField] private TMP_Text _feedbackText;
|
||||
[SerializeField] private Text _feedbackText;
|
||||
|
||||
[Header("操作题 UI(点击序列)")]
|
||||
[Header("操作题 UI")]
|
||||
[SerializeField] private GameObject _operationPanel;
|
||||
[SerializeField] private TMP_Text _operationHint;
|
||||
[SerializeField] private Text _operationHint;
|
||||
|
||||
private StepData _currentStep;
|
||||
private Action<float, string> _onAnswerCallback;
|
||||
@@ -28,7 +26,7 @@ public class ExamPopup : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_confirmButton?.onClick.AddListener(OnConfirm);
|
||||
if (_confirmButton) _confirmButton.onClick.AddListener(OnConfirm);
|
||||
if (_popupRoot != null) _popupRoot.SetActive(false);
|
||||
}
|
||||
|
||||
@@ -40,7 +38,7 @@ public class ExamPopup : MonoBehaviour
|
||||
if (_feedbackText != null) _feedbackText.text = "";
|
||||
if (_popupRoot != null) _popupRoot.SetActive(true);
|
||||
|
||||
_questionText?.SetText(step.ExamQuestionText);
|
||||
if (_questionText != null) _questionText.text = step.ExamQuestionText;
|
||||
|
||||
switch (step.CompleteType)
|
||||
{
|
||||
@@ -59,14 +57,12 @@ public class ExamPopup : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
#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++)
|
||||
int optionCount = step.ExamOptions != null ? step.ExamOptions.Length : 0;
|
||||
for (int i = 0; i < (_optionToggles != null ? _optionToggles.Length : 0); i++)
|
||||
{
|
||||
bool active = i < optionCount;
|
||||
_optionToggles[i].gameObject.SetActive(active);
|
||||
@@ -74,10 +70,11 @@ public class ExamPopup : MonoBehaviour
|
||||
_optionToggles[i].onValueChanged.RemoveAllListeners();
|
||||
int idx = i;
|
||||
_optionToggles[i].onValueChanged.AddListener((val) => { if (val) _selectedIndex = idx; });
|
||||
if (active) _optionLabels[i]?.SetText(step.ExamOptions[i]);
|
||||
if (active && _optionLabels != null && i < _optionLabels.Length)
|
||||
_optionLabels[i].text = step.ExamOptions[i];
|
||||
}
|
||||
|
||||
_confirmButton?.gameObject.SetActive(true);
|
||||
if (_confirmButton != null) _confirmButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void SetupClickObject(StepData step)
|
||||
@@ -85,8 +82,8 @@ public class ExamPopup : MonoBehaviour
|
||||
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} 物体");
|
||||
if (_confirmButton != null) _confirmButton.gameObject.SetActive(true);
|
||||
if (_operationHint != null) _operationHint.text = "请点击场景中的 " + step.TargetTag + " 物体";
|
||||
}
|
||||
|
||||
private void SetupSequenceClick(StepData step)
|
||||
@@ -94,8 +91,8 @@ public class ExamPopup : MonoBehaviour
|
||||
if (_operationPanel != null) _operationPanel.SetActive(true);
|
||||
if (_optionToggles != null)
|
||||
foreach (var t in _optionToggles) t.gameObject.SetActive(false);
|
||||
_confirmButton?.gameObject.SetActive(true);
|
||||
_operationHint?.SetText("请按正确顺序点击物体,完成后按确定");
|
||||
if (_confirmButton != null) _confirmButton.gameObject.SetActive(true);
|
||||
if (_operationHint != null) _operationHint.text = "请按正确顺序点击物体,完成后按确定";
|
||||
}
|
||||
|
||||
private void SetupDefault(StepData step)
|
||||
@@ -103,13 +100,9 @@ public class ExamPopup : MonoBehaviour
|
||||
if (_operationPanel != null) _operationPanel.SetActive(false);
|
||||
if (_optionToggles != null)
|
||||
foreach (var t in _optionToggles) t.gameObject.SetActive(false);
|
||||
_confirmButton?.gameObject.SetActive(true);
|
||||
if (_confirmButton != null) _confirmButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 确认与判定
|
||||
|
||||
private void OnConfirm()
|
||||
{
|
||||
if (_currentStep == null) return;
|
||||
@@ -117,30 +110,17 @@ public class ExamPopup : MonoBehaviour
|
||||
float proportion = 1f;
|
||||
string feedback = "";
|
||||
|
||||
switch (_currentStep.CompleteType)
|
||||
if (_currentStep.CompleteType == StepCompleteType.MultipleChoice)
|
||||
{
|
||||
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;
|
||||
bool correct = _selectedIndex == _currentStep.CorrectOptionIndex;
|
||||
proportion = correct ? 1f : 0f;
|
||||
feedback = correct ? "" : _currentStep.ErrorFeedback;
|
||||
if (!correct && _feedbackText != null)
|
||||
_feedbackText.text = feedback;
|
||||
}
|
||||
|
||||
if (proportion <= 0f && !string.IsNullOrEmpty(feedback))
|
||||
{
|
||||
_onAnswerCallback?.Invoke(0f, feedback);
|
||||
Hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
_onAnswerCallback?.Invoke(proportion, feedback);
|
||||
Hide();
|
||||
}
|
||||
_onAnswerCallback?.Invoke(proportion, feedback);
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
@@ -149,6 +129,4 @@ public class ExamPopup : MonoBehaviour
|
||||
_currentStep = null;
|
||||
_onAnswerCallback = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user