增加低通效果开关
- 引入DoTween - 实现功能
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using DG.Tweening;
|
||||
|
||||
namespace OCES.Audio
|
||||
{
|
||||
@@ -19,6 +20,7 @@ namespace OCES.Audio
|
||||
AudioObjectConfig m_audioObjects;
|
||||
AudioGroupConfig m_groups;
|
||||
AudioMixer m_mixer;
|
||||
Tween m_lowpassTween;
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// 公开接口
|
||||
@@ -41,6 +43,34 @@ namespace OCES.Audio
|
||||
// TODO: 按文件名播放
|
||||
}
|
||||
|
||||
public void SetLowpass(bool enable)
|
||||
{
|
||||
float target = enable ? 440f : 22000f;
|
||||
|
||||
// Kill existing tween to avoid stacking
|
||||
if (this.m_lowpassTween != null && this.m_lowpassTween.IsActive())
|
||||
this.m_lowpassTween.Kill();
|
||||
|
||||
// Get current value as start
|
||||
if (!this.m_mixer.GetFloat("LowpassFreq", out float current))
|
||||
current = target;
|
||||
|
||||
float startLog = Mathf.Log10(current);
|
||||
float endLog = Mathf.Log10(target);
|
||||
|
||||
this.m_lowpassTween = DOTween.To(
|
||||
() => startLog,
|
||||
x =>
|
||||
{
|
||||
startLog = x;
|
||||
float value = Mathf.Pow(10f, startLog);
|
||||
this.m_mixer.SetFloat("LowpassFreq", value);
|
||||
},
|
||||
endLog,
|
||||
0.2f // duration in seconds
|
||||
).SetEase(Ease.OutCubic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新游戏状态,驱动音乐与环境音系统切换。
|
||||
/// 调用示例:AudioSystem.Instance.SetState(GameState.Game);
|
||||
|
||||
Reference in New Issue
Block a user