- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Audio;
- public class AudioManager : MonoBehaviour
- {
- public AudioMixer mixer;
- public void SetMasterVolume(float v)
- {
- mixer.SetFloat("_masterVolume", GetValue(v));
- }
- public void SetSfxVolume(float v)
- {
- mixer.SetFloat("_sfxVolume", GetValue(v));
- }
- public void SetUISfxVolume(float v)
- {
- mixer.SetFloat("_uisfxVolume", GetValue(v));
- }
- public void SetMusicVolume(float v)
- {
- mixer.SetFloat("_musicVolume", GetValue(v));
- }
- private float GetValue(float v)
- {
- return Mathf.Log10(v) * 20;
- }
- public void GetMasterVolume(out float v)
- {
- mixer.GetFloat("_masterVolume",out v);
- v = Mathf.Pow(10.0f, v / 20.0f);
- }
- public void GetSfxVolume(out float v)
- {
- mixer.GetFloat("_sfxVolume",out v);
- v = Mathf.Pow(10.0f, v / 20.0f);
- }
- public void GetUISfxVolume(out float v)
- {
- mixer.GetFloat("_uisfxVolume",out v);
- v = Mathf.Pow(10.0f, v / 20.0f);
- }
- public void GetMusicVolume(out float v)
- {
- mixer.GetFloat("_musicVolume", out v);
- v = Mathf.Pow(10.0f, v / 20.0f);
- }
- }