54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using AlicizaX;
|
|
using UnityEngine;
|
|
using UnityEngine.Audio;
|
|
|
|
namespace AlicizaX.Audio.Runtime
|
|
{
|
|
[DisallowMultipleComponent]
|
|
[AddComponentMenu("Game Framework/Audio")]
|
|
public sealed class AudioComponent : MonoBehaviour
|
|
{
|
|
[SerializeField] private AudioMixer m_AudioMixer;
|
|
[SerializeField] private AudioListener m_AudioListener;
|
|
[SerializeField] private AudioGroupConfigCollection m_AudioGroupConfigs;
|
|
|
|
private IAudioService _audioService;
|
|
|
|
private void Awake()
|
|
{
|
|
_audioService = AppServices.RegisterApp(new AudioService());
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (m_AudioMixer == null)
|
|
{
|
|
throw new GameFrameworkException("AudioMixer is not assigned. Please assign an AudioMixer in the inspector.");
|
|
}
|
|
|
|
AudioGroupConfig[] configs = m_AudioGroupConfigs != null ? m_AudioGroupConfigs.GroupConfigs : null;
|
|
_audioService.Initialize(configs, transform, m_AudioMixer);
|
|
if (m_AudioListener != null)
|
|
{
|
|
_audioService.RegisterListener(m_AudioListener);
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_audioService != null && m_AudioListener != null)
|
|
{
|
|
_audioService.RegisterListener(m_AudioListener);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (_audioService != null && m_AudioListener != null)
|
|
{
|
|
_audioService.UnregisterListener(m_AudioListener);
|
|
}
|
|
}
|
|
}
|
|
}
|