76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 全局单例管理器:持有当前实验的类型、模式、固定方式与加权分数。
|
||
|
|
/// 挂在场景第一个 GameObject 上,设置 DontDestroyOnLoad。
|
||
|
|
/// </summary>
|
||
|
|
public class GameManager : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static GameManager Instance { get; private set; }
|
||
|
|
|
||
|
|
[Header("当前实验设置(运行时赋值)")]
|
||
|
|
public ExperimentType CurrentExperimentType = ExperimentType.FractureFixation;
|
||
|
|
public ExperimentMode CurrentMode = ExperimentMode.Learn;
|
||
|
|
public FixationMethod CurrentFixationMethod = FixationMethod.LimbFixation;
|
||
|
|
|
||
|
|
[Header("加权评分")]
|
||
|
|
public float TotalWeightedScore; // 实际得分(加权累加)
|
||
|
|
public float MaxWeightedScore = 100f; // 总分
|
||
|
|
|
||
|
|
[Header("考核记录")]
|
||
|
|
public float[] StepScores; // 每步实际得分(含权重)
|
||
|
|
public float[] StepMaxScores; // 每步满分(权重值)
|
||
|
|
public string[] StepFeedback; // 每题错误反馈文本
|
||
|
|
public bool[] StepCorrect; // 每题是否有任何得分
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
if (Instance != null && Instance != this)
|
||
|
|
{
|
||
|
|
Destroy(gameObject);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
Instance = this;
|
||
|
|
DontDestroyOnLoad(gameObject);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>初始化考核记录数组</summary>
|
||
|
|
public void InitExamRecord(int stepCount)
|
||
|
|
{
|
||
|
|
StepScores = new float[stepCount];
|
||
|
|
StepMaxScores = new float[stepCount];
|
||
|
|
StepFeedback = new string[stepCount];
|
||
|
|
StepCorrect = new bool[stepCount];
|
||
|
|
TotalWeightedScore = 0f;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 记录一个考核步骤的结果。
|
||
|
|
/// proportion 为 0~1,表示得分比例(SequenceClick 类型部分正确时用到)。
|
||
|
|
/// </summary>
|
||
|
|
public void RecordExamResult(int stepIndex, float maxScore, float proportion, string feedback)
|
||
|
|
{
|
||
|
|
if (StepScores == null || stepIndex >= StepScores.Length) return;
|
||
|
|
|
||
|
|
StepMaxScores[stepIndex] = maxScore;
|
||
|
|
float earned = maxScore * Mathf.Clamp01(proportion);
|
||
|
|
StepScores[stepIndex] = earned;
|
||
|
|
StepFeedback[stepIndex] = feedback;
|
||
|
|
StepCorrect[stepIndex] = proportion > 0f;
|
||
|
|
TotalWeightedScore += earned;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>按百分比返回考核分数</summary>
|
||
|
|
public float GetExamPercentage()
|
||
|
|
{
|
||
|
|
if (MaxWeightedScore <= 0f) return 0f;
|
||
|
|
return TotalWeightedScore / MaxWeightedScore * 100f;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>获取总分(整数)</summary>
|
||
|
|
public int GetExamScoreRounded()
|
||
|
|
{
|
||
|
|
return Mathf.RoundToInt(TotalWeightedScore);
|
||
|
|
}
|
||
|
|
}
|