AudioCore0.11
This commit is contained in:
@@ -12,21 +12,13 @@ public class SFXPlayer
|
||||
this.audioSourcePool = audioSourcePool;
|
||||
}
|
||||
|
||||
/*public override void Play(AudioClip clip, float volume = 1f)
|
||||
{
|
||||
AudioSource source = audioSourcePool.GetAudioSource("SFX");
|
||||
if (source == null) return;
|
||||
|
||||
source.clip = clip;
|
||||
source.volume = volume;
|
||||
source.Play();
|
||||
|
||||
// 将 AudioSource 加入活动列表
|
||||
activeSources.Add(source);
|
||||
}
|
||||
*/
|
||||
|
||||
// 播放音效
|
||||
/// <summary>
|
||||
/// 播放音效
|
||||
/// </summary>
|
||||
/// <param name="clip">音频</param>
|
||||
/// <param name="volume">音量</param>
|
||||
/// <param name="onComplete">结束行为</param>
|
||||
/// <param name="delay">延迟结束行为时间</param>
|
||||
public void Play(AudioClip clip, float volume = 1f, System.Action onComplete = null, float delay = 0f)
|
||||
{
|
||||
AudioSource source = audioSourcePool.GetAudioSource("SFX");
|
||||
@@ -40,10 +32,12 @@ public class SFXPlayer
|
||||
activeSources.Add(source);
|
||||
|
||||
// 使用协程处理延迟和回调
|
||||
CoroutineHelper.StartCoroutine(PlayCoroutine(source, delay, onComplete));
|
||||
CoroutineHelper.StartCoroutine(PlaySFXCoroutine(source, delay, onComplete));
|
||||
}
|
||||
|
||||
// 停止所有音效
|
||||
/// <summary>
|
||||
/// 停止所有音效
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
foreach (var source in activeSources)
|
||||
@@ -57,8 +51,14 @@ public class SFXPlayer
|
||||
activeSources.Clear();
|
||||
}
|
||||
|
||||
// 播放音效的协程
|
||||
private IEnumerator PlayCoroutine(AudioSource source, float delay, System.Action onComplete)
|
||||
/// <summary>
|
||||
/// 播放音效的协程
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="delay"></param>
|
||||
/// <param name="onComplete"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerator PlaySFXCoroutine(AudioSource source, float delay, System.Action onComplete)
|
||||
{
|
||||
yield return new WaitForSeconds(source.clip.length + delay);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user