这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

38 行
1004 B

using UnityEngine;
public class MusicPlayer : MonoBehaviour
{
[SerializeField] private VoidEventChannelSO _onSceneReady = default;
[SerializeField] private AudioCueEventChannelSO _playMusicOn = default;
[SerializeField] private GameSceneSO _thisSceneSO = default;
[SerializeField] private AudioConfigurationSO _audioConfig = default;
[Header("Pause menu music")]
[SerializeField] private AudioCueSO _pauseMusic = default;
[SerializeField] private BoolEventChannelSO _onPauseOpened = default;
private void OnEnable()
{
_onPauseOpened.OnEventRaised += PlayPauseMusic;
_onSceneReady.OnEventRaised += PlayMusic;
}
private void OnDisable()
{
_onSceneReady.OnEventRaised -= PlayMusic;
_onPauseOpened.OnEventRaised -= PlayPauseMusic;
}
private void PlayMusic()
{
_playMusicOn.RaisePlayEvent(_thisSceneSO.musicTrack, _audioConfig);
}
private void PlayPauseMusic(bool open)
{
if (open)
_playMusicOn.RaisePlayEvent(_pauseMusic, _audioConfig);
else
PlayMusic();
}
}