| | |
| | | CleanupFinishedAudioSources(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 预热音频(暂时为空,留给移动端优化) |
| | | /// </summary> |
| | | public void PrewarmAudio(params int[] audioIds) |
| | | { |
| | | // TODO: 移动端优化时实现 |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 预热音频(暂时为空,留给移动端优化) |
| | | /// </summary> |
| | | public void PrewarmAudio(List<int> audioIds) |
| | | { |
| | | // TODO: 移动端优化时实现 |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放技能音效 |
| | | /// </summary> |
| | | /// <param name="audioId">音效ID</param> |
| | | public void PlaySkillSound(int audioId) |
| | | { |
| | | if (audioId <= 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | PlaySound(audioId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放特效音效 |
| | | /// </summary> |
| | | /// <param name="audioId">音效ID</param> |
| | | public void PlayEffectSound(int audioId) |
| | | public void PlayEffectSound(int audioId, bool pitchControl = true) |
| | | { |
| | | if (audioId <= 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | PlaySound(audioId); |
| | | PlaySound(audioId, pitchControl); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 核心播放方法 |
| | | /// </summary> |
| | | private void PlaySound(int audioId) |
| | | private void PlaySound(int audioId, bool pitchControl) |
| | | { |
| | | // 检查是否有焦点,无焦点时不播放 |
| | | if (!hasFocus) |
| | |
| | | |
| | | // 设置播放速度,使用pitch来控制 |
| | | // pitch范围建议在0.5-2.0之间以避免失真 |
| | | float pitch = Mathf.Clamp(currentSpeedRatio, 0.5f, 2.0f); |
| | | source.pitch = pitch; |
| | | if (pitchControl) |
| | | { |
| | | float pitch = Mathf.Clamp(currentSpeedRatio, 0.5f, 2.0f); |
| | | source.pitch = pitch; |
| | | } |
| | | else |
| | | { |
| | | source.pitch = 1.0f; |
| | | } |
| | | |
| | | |
| | | // 播放音效 |
| | | source.PlayOneShot(audioClip); |