Files
VFSUnity/Assets/Scripts/UI/ScoreDisplay.cs
T
yangbear f0a6b96da5 feat: MCP Unity 场景优化 — 完整交互体系搭建
- 删除重复 Ground
- 创建 [Managers] 空物体,挂载 GameManager + StepManager + ExperimentFlowCoordinator + AudioManager
- Main Camera 挂载 InteractionSystem
- 伤者 InjectedPerson 下创建 5 个交互子物体 (InjuryVisual/Swelling/Pain/VitalSigns/Neuro)
- 创建绑带位置、踝关节、衬垫、夹板位置等空物体
- 道具摆放到位:伤者(2,0.05,5) 施救者(3,0,5) 鞋(2.7,0.15,5.5) 绷带/夹板/急救箱在旁
- InjuryLeg Tag 修正,Ground Tag 修正
- 全部新脚本同步导入 (ExperimentTypes/StepData/ExperimentConfig/StepManager/GameManager/ExperimentFlowCoordinator/InteractionSystem/DraggableObject/HighlightEffect/UIManager/ExamPopup/ScoreDisplay/VideoController/AudioManager/CharacterAnimController/StepAnimationHandler)
- 旧脚本 (ExperimentController/ConfigLoader/AnimationController/HUDController/VideoPlayerController/PopupSystem/ModeSelectionUI) 全部兼容修复或 stub
- 编译通过,0 错误
- Canvas 挂载 UIManager
2026-06-24 02:33:48 +08:00

110 lines
3.9 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 UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// 实验结束后的结果展示面板。
/// 考核模式:显示加权成绩 + 错题分析列表(含每步得分/满分)。
/// 学习模式:显示注意事项。
/// </summary>
public class ScoreDisplay : MonoBehaviour
{
[Header("面板根节点")]
[SerializeField] private GameObject _panelRoot;
[Header("考核模式")]
[SerializeField] private GameObject _examResultRoot;
[SerializeField] private TMP_Text _scoreTitle;
[SerializeField] private TMP_Text _scoreValue;
[SerializeField] private Transform _analysisListParent;
[SerializeField] private GameObject _analysisItemPrefab;
[Header("学习模式 - 注意事项")]
[SerializeField] private GameObject _notesRoot;
[SerializeField] private TMP_Text _notesText;
[Header("底部按钮")]
[SerializeField] private Button _confirmButton;
private static readonly string NotesContent =
"1. 下肢损伤选择仰卧位;\n" +
"2. 骨折固定前后要脱掉鞋袜并检查下肢末梢循环、运动、感觉;\n" +
"3. 穿带子时应从健侧穿向伤侧;\n" +
"4. 骨折固定时先固定伤口的近心端,后固定远心端,再由上而下进行固定;\n" +
"5. 固定后尽可能抬高下肢。";
private void Awake()
{
_confirmButton?.onClick.AddListener(OnConfirm);
if (_panelRoot != null) _panelRoot.SetActive(false);
}
/// <summary>考核模式 - 显示加权成绩</summary>
public void ShowExamScore()
{
if (_panelRoot != null) _panelRoot.SetActive(true);
if (_examResultRoot != null) _examResultRoot.SetActive(true);
if (_notesRoot != null) _notesRoot.SetActive(false);
var gm = GameManager.Instance;
if (gm == null) return;
int score = gm.GetExamScoreRounded();
float pct = gm.GetExamPercentage();
if (_scoreTitle != null) _scoreTitle.text = "成绩显示栏";
if (_scoreValue != null) _scoreValue.text = $"考试成绩:{score} 分({pct:F0}%";
BuildAnalysisList();
}
/// <summary>学习模式 - 显示注意事项</summary>
public void ShowNotesOnly()
{
if (_panelRoot != null) _panelRoot.SetActive(true);
if (_examResultRoot != null) _examResultRoot.SetActive(false);
if (_notesRoot != null) _notesRoot.SetActive(true);
if (_notesText != null) _notesText.text = NotesContent;
}
private void BuildAnalysisList()
{
if (_analysisListParent == null || _analysisItemPrefab == null) return;
foreach (Transform child in _analysisListParent)
Destroy(child.gameObject);
var gm = GameManager.Instance;
if (gm == null || gm.StepScores == null) return;
for (int i = 0; i < gm.StepScores.Length; i++)
{
var item = Instantiate(_analysisItemPrefab, _analysisListParent);
var text = item.GetComponentInChildren<TMP_Text>();
if (text == null) continue;
float earned = gm.StepScores[i];
float max = gm.StepMaxScores[i];
bool fullScore = Mathf.Approximately(earned, max);
bool zeroScore = earned <= 0f;
string status;
if (fullScore) status = "<color=#00FF00>正确</color>";
else if (zeroScore) status = "<color=#FF0000>错误</color>";
else status = $"<color=#FFAA00>部分正确</color>";
string scorePart = $"{earned:F0}/{max:F0} 分)";
string fbPart = (!fullScore && !string.IsNullOrEmpty(gm.StepFeedback[i]))
? $"{gm.StepFeedback[i]}" : "";
text.text = $"第{i + 1}题:{status} {scorePart}{fbPart}";
}
}
private void OnConfirm()
{
if (_panelRoot != null) _panelRoot.SetActive(false);
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
}
}