This commit is contained in:
2025-04-21 18:14:22 +08:00
4 changed files with 5 additions and 6 deletions

View File

@@ -80,7 +80,7 @@ namespace Stary.Evo.AudioCore
if (poolDict[type].Count == 0) if (poolDict[type].Count == 0)
{ {
// 如果池为空,动态创建新的 GameObject仅限 SFX 与 Voice // 如果池为空,动态创建新的 GameObject仅限 SFX 与 Voice
if (type == "SFX" && type == "Voice") if (type == "SFX" || type == "Voice")
{ {
CreateAudioSource(type); CreateAudioSource(type);
} }

View File

@@ -21,6 +21,7 @@ namespace Stary.Evo.AudioCore
/// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间]}</param> /// [onComplete:回调行为], [delayOnCompleteTime:延迟回调执行的时间]}</param>
public override void Play(AudioData audioData) public override void Play(AudioData audioData)
{ {
audioData = AudioDataInitialize(audioData);
AudioSource source = audioSourcePool.GetAudioSource("SFX"); AudioSource source = audioSourcePool.GetAudioSource("SFX");
if (source == null) return; if (source == null) return;
@@ -62,9 +63,8 @@ namespace Stary.Evo.AudioCore
private IEnumerator PlaySFXCoroutine(AudioSource source, float delay, System.Action onComplete) private IEnumerator PlaySFXCoroutine(AudioSource source, float delay, System.Action onComplete)
{ {
yield return new WaitForSeconds(source.clip.length + delay); yield return new WaitForSeconds(source.clip.length + delay);
onComplete?.Invoke();
audioSourcePool.ReturnAudioSource("SFX", source.gameObject); audioSourcePool.ReturnAudioSource("SFX", source.gameObject);
onComplete?.Invoke();
activeSources.Remove(source); activeSources.Remove(source);
} }
} }

View File

@@ -66,9 +66,8 @@ namespace Stary.Evo.AudioCore
private IEnumerator PlayVoiceCoroutine(AudioSource source, float delayOnComplete, System.Action onComplete) private IEnumerator PlayVoiceCoroutine(AudioSource source, float delayOnComplete, System.Action onComplete)
{ {
yield return new WaitForSeconds(source.clip.length + delayOnComplete); yield return new WaitForSeconds(source.clip.length + delayOnComplete);
onComplete?.Invoke();
audioSourcePool.ReturnAudioSource("Voice", source.gameObject); audioSourcePool.ReturnAudioSource("Voice", source.gameObject);
onComplete?.Invoke();
currentSource = null; currentSource = null;
myCoroutine = null; myCoroutine = null;
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "com.staryevo.audiocore", "name": "com.staryevo.audiocore",
"version": "1.0.2", "version": "1.0.3",
"displayName": "04.AudioCore", "displayName": "04.AudioCore",
"description": "音频播放工具", "description": "音频播放工具",
"unity": "2021.3", "unity": "2021.3",