feat: VFS 虚拟仿真实验核心框架 v2
- 加权评分系统:每步独立 ScoreWeight,满分 100,SequenceClick 按子项比例计分 - StepData 新增 DetailedContent(学习模式详细操作说明)和 SubStepCount - 伤情检查步骤扩展为 5 子项序列(视觉检查→肿胀→疼痛→生命体征→神经评估) - 夹板固定模式完整评分(选择夹板→放置衬垫→夹板固定→固定后检查) - Doc/ 文件夹归档三份文档:项目大纲、文案、评分标准 - README 更新评分权重表和夹板固定流程
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 音频管理器:管理背景音乐和步骤语音解说。
|
||||
/// 挂在场景 GameObject 上,通过 AudioSource 组件播放。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public static AudioManager Instance { get; private set; }
|
||||
|
||||
[Header("音频源")]
|
||||
[SerializeField] private AudioSource _bgmSource;
|
||||
[SerializeField] private AudioSource _voiceSource;
|
||||
|
||||
[Header("背景音乐")]
|
||||
public AudioClip BGMClip;
|
||||
[Range(0f, 1f)] public float BGMVolume = 0.3f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null) { Destroy(gameObject); return; }
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (_bgmSource == null) _bgmSource = GetComponent<AudioSource>();
|
||||
if (_voiceSource == null)
|
||||
{
|
||||
_voiceSource = gameObject.AddComponent<AudioSource>();
|
||||
_voiceSource.playOnAwake = false;
|
||||
_voiceSource.loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
PlayBGM();
|
||||
}
|
||||
|
||||
public void PlayBGM()
|
||||
{
|
||||
if (_bgmSource == null || BGMClip == null) return;
|
||||
_bgmSource.clip = BGMClip;
|
||||
_bgmSource.volume = BGMVolume;
|
||||
_bgmSource.loop = true;
|
||||
_bgmSource.Play();
|
||||
}
|
||||
|
||||
public void StopBGM()
|
||||
{
|
||||
if (_bgmSource != null) _bgmSource.Stop();
|
||||
}
|
||||
|
||||
/// <summary>播放一步语音解说,自动打断前一条</summary>
|
||||
public void PlayVoice(AudioClip clip, float volume = 1f)
|
||||
{
|
||||
if (_voiceSource == null || clip == null) return;
|
||||
_voiceSource.Stop();
|
||||
_voiceSource.clip = clip;
|
||||
_voiceSource.volume = volume;
|
||||
_voiceSource.Play();
|
||||
}
|
||||
|
||||
/// <summary>停止语音</summary>
|
||||
public void StopVoice()
|
||||
{
|
||||
if (_voiceSource != null) _voiceSource.Stop();
|
||||
}
|
||||
|
||||
/// <summary>按文件名从 StreamingAssets 加载并播放语音</summary>
|
||||
public void PlayVoiceFromFile(string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName)) return;
|
||||
StartCoroutine(LoadAndPlayVoice(fileName));
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator LoadAndPlayVoice(string fileName)
|
||||
{
|
||||
string path = System.IO.Path.Combine(Application.streamingAssetsPath, "Voice", fileName);
|
||||
using var www = UnityEngine.Networking.UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV);
|
||||
yield return www.SendWebRequest();
|
||||
if (www.result == UnityEngine.Networking.UnityWebRequest.Result.Success)
|
||||
{
|
||||
var clip = UnityEngine.Networking.DownloadHandlerAudioClip.GetContent(www);
|
||||
PlayVoice(clip);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"AudioManager: 加载语音失败 {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user