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:
yangbear
2026-06-24 02:44:58 +08:00
parent f0a6b96da5
commit bf926165c0
5 changed files with 7161 additions and 735 deletions
File diff suppressed because it is too large Load Diff
+25 -47
View File
@@ -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
}
+10 -14
View File
@@ -1,6 +1,5 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// 实验结束后的结果展示面板。
@@ -14,14 +13,14 @@ public class ScoreDisplay : MonoBehaviour
[Header("考核模式")]
[SerializeField] private GameObject _examResultRoot;
[SerializeField] private TMP_Text _scoreTitle;
[SerializeField] private TMP_Text _scoreValue;
[SerializeField] private Text _scoreTitle;
[SerializeField] private Text _scoreValue;
[SerializeField] private Transform _analysisListParent;
[SerializeField] private GameObject _analysisItemPrefab;
[Header("学习模式 - 注意事项")]
[SerializeField] private GameObject _notesRoot;
[SerializeField] private TMP_Text _notesText;
[SerializeField] private Text _notesText;
[Header("底部按钮")]
[SerializeField] private Button _confirmButton;
@@ -35,11 +34,10 @@ public class ScoreDisplay : MonoBehaviour
private void Awake()
{
_confirmButton?.onClick.AddListener(OnConfirm);
if (_confirmButton) _confirmButton.onClick.AddListener(OnConfirm);
if (_panelRoot != null) _panelRoot.SetActive(false);
}
/// <summary>考核模式 - 显示加权成绩</summary>
public void ShowExamScore()
{
if (_panelRoot != null) _panelRoot.SetActive(true);
@@ -52,12 +50,11 @@ public class ScoreDisplay : MonoBehaviour
int score = gm.GetExamScoreRounded();
float pct = gm.GetExamPercentage();
if (_scoreTitle != null) _scoreTitle.text = "成绩显示栏";
if (_scoreValue != null) _scoreValue.text = $"考试成绩:{score} 分({pct:F0}%";
if (_scoreValue != null) _scoreValue.text = "考试成绩:" + score + " 分(" + pct.ToString("F0") + "%";
BuildAnalysisList();
}
/// <summary>学习模式 - 显示注意事项</summary>
public void ShowNotesOnly()
{
if (_panelRoot != null) _panelRoot.SetActive(true);
@@ -80,7 +77,7 @@ public class ScoreDisplay : MonoBehaviour
for (int i = 0; i < gm.StepScores.Length; i++)
{
var item = Instantiate(_analysisItemPrefab, _analysisListParent);
var text = item.GetComponentInChildren<TMP_Text>();
var text = item.GetComponentInChildren<Text>();
if (text == null) continue;
float earned = gm.StepScores[i];
@@ -91,19 +88,18 @@ public class ScoreDisplay : MonoBehaviour
string status;
if (fullScore) status = "<color=#00FF00>正确</color>";
else if (zeroScore) status = "<color=#FF0000>错误</color>";
else status = $"<color=#FFAA00>部分正确</color>";
else status = "<color=#FFAA00>部分正确</color>";
string scorePart = $"{earned:F0}/{max:F0} 分)";
string scorePart = "" + earned.ToString("F0") + "/" + max.ToString("F0") + " 分)";
string fbPart = (!fullScore && !string.IsNullOrEmpty(gm.StepFeedback[i]))
? $"{gm.StepFeedback[i]}" : "";
? "" + gm.StepFeedback[i] : "";
text.text = $"第{i + 1}题:{status} {scorePart}{fbPart}";
text.text = "第" + (i + 1) + "题:" + status + " " + scorePart + fbPart;
}
}
private void OnConfirm()
{
if (_panelRoot != null) _panelRoot.SetActive(false);
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
}
}
+29 -29
View File
@@ -1,10 +1,9 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// UI 中央调度器:引用所有子面板,绑定 StepManager 事件。
/// 挂在 Canvas GameObject 上。
/// 挂在 Canvas GameObject 上。使用原生 Text(非 TMP)。
/// </summary>
public class UIManager : MonoBehaviour
{
@@ -14,15 +13,15 @@ public class UIManager : MonoBehaviour
[Header("=== 顶部提示栏 ===")]
[SerializeField] private GameObject _tipPanel;
[SerializeField] private TMP_Text _tipText;
[SerializeField] private Text _tipText;
[Header("=== 详细操作说明(甲方补充 - 学习模式) ===")]
[Header("=== 详细操作说明面板 ===")]
[SerializeField] private GameObject _detailPanel;
[SerializeField] private TMP_Text _detailText;
[SerializeField] private Text _detailText;
[Header("=== 对话气泡 ===")]
[SerializeField] private GameObject _dialogueBubble;
[SerializeField] private TMP_Text _dialogueText;
[SerializeField] private Text _dialogueText;
[Header("=== 画中画视频 ===")]
[SerializeField] private VideoController _videoController;
@@ -33,17 +32,17 @@ public class UIManager : MonoBehaviour
[SerializeField] private Button _btnNext;
[SerializeField] private Button _btnSwitchMode;
[SerializeField] private Button _btnReturn;
[SerializeField] private TMP_Text _btnSwitchModeLabel;
[SerializeField] private Text _btnSwitchModeLabel;
[Header("=== 底部进度条 ===")]
[SerializeField] private Slider _progressBar;
[SerializeField] private TMP_Text _progressText;
[SerializeField] private Text _progressText;
[Header("=== 弹窗 ===")]
[SerializeField] private ExamPopup _examPopup;
[SerializeField] private ScoreDisplay _scoreDisplay;
[Header("=== 底部主菜单图标 ===")]
[Header("=== 底部图标 ===")]
[SerializeField] private Button _btnCPR;
[SerializeField] private Button _btnFracture;
[SerializeField] private Button _btnSprain;
@@ -57,6 +56,11 @@ public class UIManager : MonoBehaviour
private void Start()
{
if (_stepManager == null)
_stepManager = FindObjectOfType<StepManager>();
if (_interactionSystem == null)
_interactionSystem = FindObjectOfType<InteractionSystem>();
BindEvents();
BindButtons();
}
@@ -78,14 +82,13 @@ public class UIManager : MonoBehaviour
private void BindButtons()
{
_btnFullScreen?.onClick.AddListener(ToggleFullScreen);
_btnPrevious?.onClick.AddListener(OnPreviousClicked);
_btnNext?.onClick.AddListener(OnNextClicked);
_btnSwitchMode?.onClick.AddListener(OnSwitchModeClicked);
_btnReturn?.onClick.AddListener(OnReturnClicked);
_btnLimbFixation?.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.LimbFixation));
_btnSplintFixation?.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.SplintFixation));
if (_btnFullScreen) _btnFullScreen.onClick.AddListener(ToggleFullScreen);
if (_btnPrevious) _btnPrevious.onClick.AddListener(OnPreviousClicked);
if (_btnNext) _btnNext.onClick.AddListener(OnNextClicked);
if (_btnSwitchMode) _btnSwitchMode.onClick.AddListener(OnSwitchModeClicked);
if (_btnReturn) _btnReturn.onClick.AddListener(OnReturnClicked);
if (_btnLimbFixation) _btnLimbFixation.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.LimbFixation));
if (_btnSplintFixation) _btnSplintFixation.onClick.AddListener(() => _stepManager?.SwitchFixation(FixationMethod.SplintFixation));
}
#endregion
@@ -131,17 +134,17 @@ public class UIManager : MonoBehaviour
int cur = _stepManager.CurrentStepIndex + 1;
int total = _stepManager.TotalSteps;
if (_progressBar != null) _progressBar.value = (float)cur / total;
if (_progressText != null) _progressText.text = $"{cur}/{total}";
if (_progressText != null) _progressText.text = cur + "/" + total;
}
private void UpdateNavigationButtons()
{
if (_stepManager == null) return;
_btnPrevious.interactable = _stepManager.CurrentStepIndex > 0;
bool isLast = _stepManager.CurrentStepIndex >= _stepManager.TotalSteps - 1;
if (_btnNext != null)
if (_btnPrevious) _btnPrevious.interactable = _stepManager.CurrentStepIndex > 0;
if (_btnNext)
{
var label = _btnNext.GetComponentInChildren<TMP_Text>();
var label = _btnNext.GetComponentInChildren<Text>();
bool isLast = _stepManager.CurrentStepIndex >= _stepManager.TotalSteps - 1;
if (label != null) label.text = isLast ? "完成" : "下一步";
}
}
@@ -171,13 +174,9 @@ public class UIManager : MonoBehaviour
var gm = GameManager.Instance;
if (gm == null) return;
if (gm.CurrentMode == ExperimentMode.Exam)
{
_scoreDisplay?.ShowExamScore();
}
else
{
_scoreDisplay?.ShowNotesOnly();
}
}
#endregion
@@ -196,17 +195,18 @@ public class UIManager : MonoBehaviour
private void OnNextClicked()
{
if (_stepManager.Mode == ExperimentMode.Exam)
if (_stepManager != null && _stepManager.Mode == ExperimentMode.Exam)
{
var step = _stepManager.GetCurrentStep();
if (step != null && step.CompleteType != StepCompleteType.MultipleChoice)
_stepManager.OnStepInteractionComplete(1f);
}
_stepManager.NextStep();
_stepManager?.NextStep();
}
private void OnSwitchModeClicked()
{
if (_stepManager == null) return;
var newMode = _stepManager.Mode == ExperimentMode.Learn
? ExperimentMode.Exam : ExperimentMode.Learn;
_stepManager.SwitchMode(newMode);
@@ -214,7 +214,7 @@ public class UIManager : MonoBehaviour
private void OnReturnClicked()
{
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
UnityEngine.SceneManagement.SceneManager.LoadScene("main");
}
#endregion