fix: 静音功能

This commit is contained in:
2026-08-05 21:13:43 +08:00
parent 69152748b5
commit 9c3c467046
@@ -468,13 +468,19 @@ namespace AibisDream.Kit
public void SetVolume(float normalizedVolume) public void SetVolume(float normalizedVolume)
{ {
// 将 0~1 映射到 minDecibels ~ maxDecibels,再转换为线性幅度 normalizedVolume = Mathf.Clamp01(normalizedVolume);
// 使用对数曲线匹配人耳听觉特性
float db = Mathf.Lerp(minDecibels, maxDecibels, normalizedVolume);
float linearVolume = Mathf.Pow(10f, db / 20f);
var masterVca = RuntimeManager.GetBus("bus:/"); // 最低档需要真正静音;有限的最小分贝值仍会保留可听的线性幅度。
masterVca.setVolume(linearVolume); float linearVolume = 0f;
if (normalizedVolume > 0f)
{
// 将非零音量映射到 minDecibels ~ maxDecibels,保留原有的对数听感曲线。
float db = Mathf.Lerp(minDecibels, maxDecibels, normalizedVolume);
linearVolume = Mathf.Pow(10f, db / 20f);
}
var masterBus = RuntimeManager.GetBus("bus:/");
masterBus.setVolume(linearVolume);
} }
#endregion #endregion