【m】音乐播放和音效打断造成问题修改
This commit is contained in:
@@ -29,7 +29,7 @@ namespace Stary.Evo.AudioCore
|
||||
audioSource1.volume = audioData.volume;
|
||||
currentAudioSource = audioSource1;
|
||||
currentAudioSource.Play();
|
||||
CoroutineHelper.StartCoroutine(FadeMusic(audioSource1, audioData.fadeDuration, audioSource2));
|
||||
FadeMusic(audioSource1, audioData.fadeDuration, audioSource2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace Stary.Evo.AudioCore
|
||||
audioSource2.volume = audioData.volume;
|
||||
currentAudioSource = audioSource2;
|
||||
currentAudioSource.Play();
|
||||
CoroutineHelper.StartCoroutine(FadeMusic(audioSource2, audioData.fadeDuration, audioSource1));
|
||||
FadeMusic(audioSource2, audioData.fadeDuration, audioSource1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -56,8 +56,9 @@ namespace Stary.Evo.AudioCore
|
||||
/// <param name="audioData">{[fadeDuration:自然过渡时间]}</param>
|
||||
public override void Stop(AudioData audioData)
|
||||
{
|
||||
audioData = AudioDataInitialize(audioData);
|
||||
CoroutineHelper.StartCoroutine(FadeOutMusic(currentAudioSource, audioData.fadeDuration));
|
||||
//audioData = AudioDataInitialize(audioData);
|
||||
//CoroutineHelper.StartCoroutine(FadeOutMusic(currentAudioSource, audioData.fadeDuration));
|
||||
FadeAllMusic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,13 +68,13 @@ namespace Stary.Evo.AudioCore
|
||||
/// <param name="fadeDuration">变化时间</param>
|
||||
/// <param name="source2">停止的音频</param>
|
||||
/// <returns></returns>
|
||||
private IEnumerator FadeMusic(AudioSource source1, float fadeDuration, AudioSource source2 = null)
|
||||
private void FadeMusic(AudioSource source1, float fadeDuration, AudioSource source2 = null)
|
||||
{
|
||||
yield return FadeInMusic(source1, fadeDuration);
|
||||
CoroutineHelper.StartCoroutine(FadeInMusic(source1, fadeDuration));
|
||||
|
||||
if (source2 != null)
|
||||
{
|
||||
yield return FadeOutMusic(source2, fadeDuration);
|
||||
CoroutineHelper.StartCoroutine(FadeOutMusic(source2, fadeDuration));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -86,6 +87,7 @@ namespace Stary.Evo.AudioCore
|
||||
/// <returns></returns>
|
||||
private IEnumerator FadeOutMusic(AudioSource source, float fadeDuration)
|
||||
{
|
||||
if (source == null) yield break;
|
||||
float startVolume = source.volume;
|
||||
|
||||
while (source.volume > 0)
|
||||
@@ -95,16 +97,42 @@ namespace Stary.Evo.AudioCore
|
||||
}
|
||||
|
||||
source.Stop();
|
||||
if (audioSource1 == source)
|
||||
{
|
||||
audioSource1 = null;
|
||||
}
|
||||
else if (audioSource2 == source)
|
||||
{
|
||||
audioSource2 = null;
|
||||
}
|
||||
audioSourcePool.ReturnAudioSource("Music", source.gameObject);
|
||||
|
||||
if (currentAudioSource == audioSource1)
|
||||
/*if (currentAudioSource == audioSource1)
|
||||
{
|
||||
audioSource2 = null;
|
||||
}
|
||||
else if (currentAudioSource == audioSource2)
|
||||
{
|
||||
audioSource1 = null;
|
||||
}*/
|
||||
}
|
||||
|
||||
private void FadeAllMusic()
|
||||
{
|
||||
if (currentAudioSource != null && currentAudioSource.isPlaying)
|
||||
{
|
||||
if (currentAudioSource == audioSource1)
|
||||
{
|
||||
audioSource1 = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
audioSource2 = null;
|
||||
}
|
||||
audioSourcePool.ReturnAudioSource("Music", currentAudioSource.gameObject);
|
||||
currentAudioSource = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,6 +22,12 @@ namespace Stary.Evo.AudioCore
|
||||
public override void Play(AudioData audioData)
|
||||
{
|
||||
audioData = AudioDataInitialize(audioData);
|
||||
if (audioData.clip == null)
|
||||
{
|
||||
Debug.LogError("播放的音效音频片段为空");
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSource source = audioSourcePool.GetAudioSource("SFX");
|
||||
if (source == null) return;
|
||||
|
||||
@@ -42,6 +48,7 @@ namespace Stary.Evo.AudioCore
|
||||
/// <param name="audioData">{[无可使用变量]}</param>
|
||||
public override void Stop(AudioData audioData)
|
||||
{
|
||||
if (activeSources == null) return;
|
||||
foreach (var source in activeSources)
|
||||
{
|
||||
if (source.isPlaying)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.audiocore",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"displayName": "04.AudioCore",
|
||||
"description": "音频播放工具",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user