改动与优化
This commit is contained in:
@@ -113,16 +113,30 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
|
||||
public void Play(Music_Data data)
|
||||
{
|
||||
if (data == null) return;
|
||||
|
||||
Music_Cur = data;
|
||||
|
||||
if (!ShouldPlayInScene(SceneManager.GetActiveScene().name))
|
||||
{
|
||||
StopMusicPlayback();
|
||||
return;
|
||||
}
|
||||
|
||||
Music_Cur = data;
|
||||
if (TryPlayThroughBgmManager(data, true))
|
||||
{
|
||||
StopMusicPlayback();
|
||||
RefreshPlayers(data);
|
||||
return;
|
||||
}
|
||||
|
||||
AudioSource.clip = data.Clip;
|
||||
AudioSource.Play();
|
||||
|
||||
RefreshPlayers(data);
|
||||
}
|
||||
|
||||
private void RefreshPlayers(Music_Data data)
|
||||
{
|
||||
var players = Object.FindObjectsByType<MusicPlayer>(FindObjectsInactive.Include, FindObjectsSortMode.None);
|
||||
foreach (var player in players)
|
||||
{
|
||||
@@ -176,6 +190,18 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
|
||||
return;
|
||||
}
|
||||
|
||||
if (Music_Cur == null && Music_Data_List != null && Music_Data_List.Count > 0)
|
||||
{
|
||||
Music_Cur = Music_Data_List[0];
|
||||
}
|
||||
|
||||
if (Music_Cur != null && TryPlayThroughBgmManager(Music_Cur, false))
|
||||
{
|
||||
StopMusicPlayback();
|
||||
RefreshPlayers(Music_Cur);
|
||||
return;
|
||||
}
|
||||
|
||||
if (AudioSource != null && !AudioSource.isPlaying)
|
||||
{
|
||||
if (Music_Cur != null)
|
||||
@@ -196,4 +222,21 @@ public class Music_Mgr : Singleton_Mono<Music_Mgr>
|
||||
AudioSource.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryPlayThroughBgmManager(Music_Data data, bool restart)
|
||||
{
|
||||
if (data == null || data.Clip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
BgmPlaybackManager bgm = BgmPlaybackManager.Instance;
|
||||
if (bgm == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bgm.PlayExternalClip(data.Clip, restart);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user