修复音频播放错误

This commit is contained in:
2026-07-05 01:36:58 +08:00
parent 00499e552f
commit 904f854774
4 changed files with 64 additions and 14 deletions
+2 -12
View File
@@ -4,16 +4,6 @@ using UnityEngine;
namespace GameFramework
{
/// <summary>
/// 音频片段数据,可挂到 ScriptableObject 或直接 SerializeField。
/// </summary>
[System.Serializable]
public class AudioData
{
public AudioClip audioClip;
[Range(0f, 1f)] public float volume = 1f;
}
/// <summary>
/// 全局音频管理器(持久单例)。
/// 管理 BGM(背景音乐,循环)和 SFX(音效,一次性)。
@@ -93,11 +83,11 @@ namespace GameFramework
/// </summary>
public void PlaySFX(AudioData data)
{
if (data == null || data.audioClip == null) return;
if (data == null || data.clip == null) return;
// sfxPlayer.volume 已在 Awake 中设为 sfxVolume
// PlayOneShot 的 volumeScale 再乘以 data.volume
// 最终音量 = sfxVolume * data.volume
sfxPlayer.PlayOneShot(data.audioClip, data.volume);
sfxPlayer.PlayOneShot(data.clip, data.volume);
}
/// <summary>