【m】修复背景音乐不播的问题
This commit is contained in:
@@ -22,8 +22,8 @@ namespace Stary.Evo.AudioCore
|
||||
poolObject = new GameObject(GetType().Name);
|
||||
}
|
||||
|
||||
audioSource1 = CreatAudioSource("audioSource1", out AudioSource source1);
|
||||
audioSource2 = CreatAudioSource("audioSource2", out AudioSource source2);
|
||||
CreatAudioSource("audioSource1", out audioSource1);
|
||||
CreatAudioSource("audioSource2", out audioSource2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +41,7 @@ namespace Stary.Evo.AudioCore
|
||||
|
||||
audioData = Initialize(audioData);
|
||||
|
||||
if (!string.IsNullOrEmpty(audioData.packageName) && !string.IsNullOrEmpty(audioData.packageName))
|
||||
if (!string.IsNullOrEmpty(audioData.packageName) && !string.IsNullOrEmpty(audioData.assetName))
|
||||
{
|
||||
var clip = await Resources.LoadAssetAsync<AudioClip>(audioData.packageName, audioData.assetName);
|
||||
if (clip == null)
|
||||
@@ -60,7 +60,7 @@ namespace Stary.Evo.AudioCore
|
||||
return;
|
||||
}
|
||||
|
||||
if (audioSource1 == null)
|
||||
if (audioSource1 != null && audioSource1.isPlaying == false)
|
||||
{
|
||||
audioSource1.clip = audioData.clip;
|
||||
audioSource1.volume = audioData.volume;
|
||||
@@ -93,9 +93,7 @@ namespace Stary.Evo.AudioCore
|
||||
currentAudioSource.Play();
|
||||
FadeMusic(audioSource1, audioData.fadeDuration, audioSource2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (audioSource2 == null)
|
||||
else if (audioSource2 != null && audioSource2.isPlaying == false)
|
||||
{
|
||||
audioSource2.clip = audioData.clip;
|
||||
audioSource2.volume = audioData.volume;
|
||||
@@ -133,7 +131,6 @@ namespace Stary.Evo.AudioCore
|
||||
Debug.LogWarning("UnityEvo:已同时存在两个背景乐在切换");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override UniTask PlayAsync(AudioData audioData)
|
||||
{
|
||||
@@ -215,13 +212,12 @@ namespace Stary.Evo.AudioCore
|
||||
/// 创建一个新的AudioSource对象
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
private AudioSource CreatAudioSource(string name, out AudioSource source)
|
||||
private void CreatAudioSource(string name, out AudioSource source)
|
||||
{
|
||||
source = new GameObject(name).AddComponent<AudioSource>();
|
||||
source.gameObject.transform.SetParent(poolObject.transform);
|
||||
source.transform.SetParent(poolObject.transform); // 将新对象作为当前对象的子对象
|
||||
source.playOnAwake = false; // 添加 AudioSource 组件并禁用自动播放
|
||||
return source;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.audiocore",
|
||||
"version": "1.1.1",
|
||||
"version": "1.1.2",
|
||||
"displayName": "04.AudioCore",
|
||||
"description": "音频播放工具",
|
||||
"unity": "2021.3",
|
||||
|
||||
Reference in New Issue
Block a user