添加struct管理AudioData
This commit is contained in:
@@ -2,7 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SFXPlayer
|
||||
public class SFXPlayer : AbstractAudio
|
||||
{
|
||||
private AudioSourcePool audioSourcePool;
|
||||
private List<AudioSource> activeSources = new List<AudioSource>(); // 正在播放的 AudioSource 列表
|
||||
@@ -15,30 +15,29 @@ public class SFXPlayer
|
||||
/// <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)
|
||||
/// <param name="audioData">{[clip:音频], [volume:音量],
|
||||
/// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间]}</param>
|
||||
public override void Play(AudioData audioData)
|
||||
{
|
||||
AudioSource source = audioSourcePool.GetAudioSource("SFX");
|
||||
if (source == null) return;
|
||||
|
||||
source.clip = clip;
|
||||
source.volume = volume;
|
||||
source.clip = audioData.clip;
|
||||
source.volume = audioData.volume;
|
||||
source.Play();
|
||||
|
||||
// 将 AudioSource 加入活动列表
|
||||
activeSources.Add(source);
|
||||
|
||||
// 使用协程处理延迟和回调
|
||||
CoroutineHelper.StartCoroutine(PlaySFXCoroutine(source, delay, onComplete));
|
||||
CoroutineHelper.StartCoroutine(PlaySFXCoroutine(source, audioData.delayOnCompleteTime, audioData.onComplete));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止所有音效
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
/// <param name="audioData">{[无可使用变量]}</param>
|
||||
public override void Stop(AudioData audioData)
|
||||
{
|
||||
foreach (var source in activeSources)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user