bf926165c0
- 删除顶层重复的 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 - 编译零错误,游戏画面正常显示
106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
/// <summary>
|
||
/// 实验结束后的结果展示面板。
|
||
/// 考核模式:显示加权成绩 + 错题分析列表(含每步得分/满分)。
|
||
/// 学习模式:显示注意事项。
|
||
/// </summary>
|
||
public class ScoreDisplay : MonoBehaviour
|
||
{
|
||
[Header("面板根节点")]
|
||
[SerializeField] private GameObject _panelRoot;
|
||
|
||
[Header("考核模式")]
|
||
[SerializeField] private GameObject _examResultRoot;
|
||
[SerializeField] private Text _scoreTitle;
|
||
[SerializeField] private Text _scoreValue;
|
||
[SerializeField] private Transform _analysisListParent;
|
||
[SerializeField] private GameObject _analysisItemPrefab;
|
||
|
||
[Header("学习模式 - 注意事项")]
|
||
[SerializeField] private GameObject _notesRoot;
|
||
[SerializeField] private Text _notesText;
|
||
|
||
[Header("底部按钮")]
|
||
[SerializeField] private Button _confirmButton;
|
||
|
||
private static readonly string NotesContent =
|
||
"1. 下肢损伤选择仰卧位;\n" +
|
||
"2. 骨折固定前后要脱掉鞋袜并检查下肢末梢循环、运动、感觉;\n" +
|
||
"3. 穿带子时应从健侧穿向伤侧;\n" +
|
||
"4. 骨折固定时先固定伤口的近心端,后固定远心端,再由上而下进行固定;\n" +
|
||
"5. 固定后尽可能抬高下肢。";
|
||
|
||
private void Awake()
|
||
{
|
||
if (_confirmButton) _confirmButton.onClick.AddListener(OnConfirm);
|
||
if (_panelRoot != null) _panelRoot.SetActive(false);
|
||
}
|
||
|
||
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.ToString("F0") + "%)";
|
||
|
||
BuildAnalysisList();
|
||
}
|
||
|
||
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<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.ToString("F0") + "/" + max.ToString("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);
|
||
}
|
||
}
|