Newer
Older
Dreamsturbia-Project-IADE-Unity3D / Assets / Scripts / Sound / AudioManager.cs
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Audio;
  5. public class AudioManager : MonoBehaviour
  6. {
  7. public AudioMixer mixer;
  8. public void SetMasterVolume(float v)
  9. {
  10. mixer.SetFloat("_masterVolume", GetValue(v));
  11. }
  12. public void SetSfxVolume(float v)
  13. {
  14. mixer.SetFloat("_sfxVolume", GetValue(v));
  15. }
  16. public void SetUISfxVolume(float v)
  17. {
  18. mixer.SetFloat("_uisfxVolume", GetValue(v));
  19. }
  20. public void SetMusicVolume(float v)
  21. {
  22. mixer.SetFloat("_musicVolume", GetValue(v));
  23. }
  24. private float GetValue(float v)
  25. {
  26. return Mathf.Log10(v) * 20;
  27. }
  28. public void GetMasterVolume(out float v)
  29. {
  30. mixer.GetFloat("_masterVolume",out v);
  31. v = Mathf.Pow(10.0f, v / 20.0f);
  32. }
  33. public void GetSfxVolume(out float v)
  34. {
  35. mixer.GetFloat("_sfxVolume",out v);
  36. v = Mathf.Pow(10.0f, v / 20.0f);
  37. }
  38. public void GetUISfxVolume(out float v)
  39. {
  40. mixer.GetFloat("_uisfxVolume",out v);
  41. v = Mathf.Pow(10.0f, v / 20.0f);
  42. }
  43. public void GetMusicVolume(out float v)
  44. {
  45. mixer.GetFloat("_musicVolume", out v);
  46. v = Mathf.Pow(10.0f, v / 20.0f);
  47. }
  48. }