feature: change playing sound property
This commit is contained in:
@@ -179,6 +179,92 @@ namespace OCES.Audio
|
||||
this.m_sfxSystem.Stop(audioId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定音频ID的音量
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
/// <param name="targetVolume">目标音量 (0.0 - 1.0)</param>
|
||||
public void SetVolume(uint audioId, float targetVolume)
|
||||
{
|
||||
if (targetVolume is < 0 or > 1)
|
||||
{
|
||||
Debug.LogWarning($"[AudioSystem] Volume '{targetVolume}' is out of range [0, 1].");
|
||||
return;
|
||||
}
|
||||
this.m_sfxSystem.SetVolume(audioId, targetVolume);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定音频ID的音量
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
/// <param name="targetVolume">目标音量 (0.0 - 1.0)</param>
|
||||
public void SetVolume(int audioId, float targetVolume)
|
||||
{
|
||||
SetVolume((uint)audioId, targetVolume);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定音频ID的音高
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
/// <param name="targetPitch">目标音高 (通常 1.0 为正常音高, -3 ~ 3)</param>
|
||||
public void SetPitch(uint audioId, float targetPitch)
|
||||
{
|
||||
if (targetPitch is < -3 or > 3)
|
||||
{
|
||||
Debug.LogWarning($"[AudioSystem] Pitch '{targetPitch}' is out of range [-3, 3].");
|
||||
return;
|
||||
}
|
||||
this.m_sfxSystem.SetPitch(audioId, targetPitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置指定音频ID的音高
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
/// <param name="targetPitch">目标音高 (通常 1.0 为正常音高)</param>
|
||||
public void SetPitch(int audioId, float targetPitch)
|
||||
{
|
||||
SetPitch((uint)audioId, targetPitch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置指定音频ID的音量为默认值
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
public void ResetVolume(uint audioId)
|
||||
{
|
||||
this.m_sfxSystem.ResetVolume(audioId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置指定音频ID的音量为默认值
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
public void ResetVolume(int audioId)
|
||||
{
|
||||
ResetVolume((uint)audioId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置指定音频ID的音高为默认值
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
public void ResetPitch(uint audioId)
|
||||
{
|
||||
this.m_sfxSystem.ResetPitch(audioId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置指定音频ID的音高为默认值
|
||||
/// </summary>
|
||||
/// <param name="audioId">音频ID</param>
|
||||
public void ResetPitch(int audioId)
|
||||
{
|
||||
ResetPitch((uint)audioId);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// 初始化
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
@@ -99,6 +99,62 @@ namespace OCES.Audio
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetVolume(uint audioId, float targetVolume)
|
||||
{
|
||||
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
|
||||
foreach (ActiveSound target in targets)
|
||||
{
|
||||
target.Volume = targetVolume;
|
||||
if (target.Source)
|
||||
{
|
||||
target.Source.volume = targetVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetPitch(uint audioId, float targetPitch)
|
||||
{
|
||||
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
|
||||
foreach (ActiveSound target in targets)
|
||||
{
|
||||
target.Pitch = targetPitch;
|
||||
if (target.Source)
|
||||
{
|
||||
target.Source.pitch = targetPitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void ResetVolume(uint audioId)
|
||||
{
|
||||
double now = Time.realtimeSinceStartupAsDouble * 1000.0;
|
||||
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
|
||||
foreach (ActiveSound target in targets)
|
||||
{
|
||||
float defaultVolume = this.m_volumeStepResolver.ResolveVolume(target.AudioObject, now);
|
||||
target.Volume = defaultVolume;
|
||||
if (target.Source)
|
||||
{
|
||||
target.Source.volume = defaultVolume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void ResetPitch(uint audioId)
|
||||
{
|
||||
double now = Time.realtimeSinceStartupAsDouble * 1000.0;
|
||||
List<ActiveSound> targets = this.m_activeSounds.FindAll(activeSound => activeSound.AudioObject.Id == audioId);
|
||||
foreach (ActiveSound target in targets)
|
||||
{
|
||||
float defaultPitch = this.m_pitchStepResolver.ResolvePitch(target.AudioObject, now);
|
||||
target.Pitch = defaultPitch;
|
||||
if (target.Source != null)
|
||||
{
|
||||
target.Source.pitch = defaultPitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// 节流 & 调度入口
|
||||
// ─────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user