64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using System.Collections.Generic;
|
||
using AK.Wwise;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
using Event = AK.Wwise.Event;
|
||
|
||
namespace SLSUtilities.WwiseAssistance
|
||
{
|
||
public class BackgroundMusicManager : SerializedMonoBehaviour
|
||
{
|
||
public Dictionary<string, State> baseMusicDictionary; // 背景音乐事件字典
|
||
public Event playMusicEvent; // 播放背景音乐的事件
|
||
public Event stopMusicEvent; // 停止播放背景音乐的事件
|
||
|
||
/// <summary>
|
||
/// 是否被外部系统(如 MusicBeatSystem)覆盖中
|
||
/// </summary>
|
||
[ShowInInspector, ReadOnly]
|
||
private bool isOverridden;
|
||
|
||
/// <summary>
|
||
/// 最后一次播放请求的音乐 State 名称,用于恢复
|
||
/// </summary>
|
||
private string lastMusicStateName;
|
||
|
||
private void Start()
|
||
{
|
||
PlayMusic("NormalMusic");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 播放指定 State 的背景音乐。被覆盖期间调用会被静默忽略
|
||
/// </summary>
|
||
public void PlayMusic(string musicStateName)
|
||
{
|
||
if (isOverridden)
|
||
{
|
||
lastMusicStateName = musicStateName;
|
||
return;
|
||
}
|
||
|
||
lastMusicStateName = musicStateName;
|
||
stopMusicEvent.Post(gameObject);
|
||
playMusicEvent.Post(gameObject);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 停止背景音乐
|
||
/// </summary>
|
||
public void StopMusic()
|
||
{
|
||
stopMusicEvent.Post(gameObject);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置覆盖状态。被覆盖期间,常规 PlayMusic 调用将被静默忽略
|
||
/// </summary>
|
||
public void SetOverride(bool overridden)
|
||
{
|
||
isOverridden = overridden;
|
||
}
|
||
}
|
||
}
|