增加低通效果开关

- 引入DoTween
- 实现功能
This commit is contained in:
2026-03-27 17:56:49 +08:00
parent 2248de2dcf
commit e774581bfe
56 changed files with 7053 additions and 2 deletions
@@ -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);
+5
View File
@@ -1,18 +1,21 @@
using UnityEngine;
using UnityEngine.UI;
using OCES.Audio;
using UnityEngine.Audio;
namespace OCES
{
public class ButtonInvoker : MonoBehaviour
{
public GameState targetGameState;
public bool enableLowpass;
Button m_button;
void Awake()
{
this.m_button = GetComponent<Button>();
this.m_button.onClick.AddListener(ButtonPressed);
}
@@ -25,6 +28,8 @@ namespace OCES
private void ButtonPressed()
{
AudioSystem.Instance.SetState(this.targetGameState);
AudioSystem.Instance.SetLowpass(this.enableLowpass);
}
}
}