Update audio manager
This commit is contained in:
@@ -30,6 +30,11 @@ namespace Hallucinate.Audio
|
||||
if (database != null) database.Initialize();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ApplyAllVolumes();
|
||||
}
|
||||
|
||||
private void InitializePool()
|
||||
{
|
||||
_pool = new List<AudioSource>();
|
||||
@@ -43,6 +48,27 @@ namespace Hallucinate.Audio
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyAllVolumes()
|
||||
{
|
||||
SetVolume("MasterVolume", PlayerPrefs.GetFloat("MasterVolume", 80f));
|
||||
SetVolume("MusicVolume", PlayerPrefs.GetFloat("MusicVolume", 80f));
|
||||
SetVolume("VFXVolume", PlayerPrefs.GetFloat("VFXVolume", 80f));
|
||||
SetVolume("PlayerVolume", PlayerPrefs.GetFloat("PlayerVolume", 80f));
|
||||
SetVolume("UIVolume", PlayerPrefs.GetFloat("UIVolume", 80f));
|
||||
}
|
||||
|
||||
public void SetVolume(string key, float volume)
|
||||
{
|
||||
if (defaultGroup == null || defaultGroup.audioMixer == null) return;
|
||||
|
||||
// Chuyển đổi từ 0-100 sang dB (-80f đến 0f hoặc 20f tùy mixer)
|
||||
// Công thức: dB = 20 * log10(volume / 100)
|
||||
float db = volume <= 0.001f ? -80f : Mathf.Log10(volume / 100f) * 20f;
|
||||
|
||||
// Đảm bảo Parameter đã được EXPOSE trong AudioMixer với tên tương ứng (MasterVolume, MusicVolume, etc.)
|
||||
defaultGroup.audioMixer.SetFloat(key, db);
|
||||
}
|
||||
|
||||
public void Play(string sampleName, float volumeMult = 1f, float pitchMult = 1f, Vector3? position = null)
|
||||
{
|
||||
if (database == null) return;
|
||||
|
||||
Reference in New Issue
Block a user