2020-04-19 01:12:29 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Audio;
|
|
|
|
|
|
|
|
|
|
public class AudioMaster : MonoBehaviour {
|
|
|
|
|
public GameState GameState;
|
2020-04-19 22:09:31 +02:00
|
|
|
|
public Options Options;
|
2020-04-19 01:12:29 +02:00
|
|
|
|
|
|
|
|
|
public AudioMixer Mixer;
|
|
|
|
|
public AudioMixerSnapshot PlayingSnapshot;
|
|
|
|
|
public AudioMixerSnapshot PausedSnapshot;
|
|
|
|
|
public AudioMixerSnapshot GameoverSnapshot;
|
|
|
|
|
public float TransitionDuration;
|
|
|
|
|
|
|
|
|
|
void Update() {
|
|
|
|
|
float[] Weights = {
|
|
|
|
|
GameState.Current == State.Playing ? 1 : 0,
|
|
|
|
|
GameState.Current == State.Paused ? 1 : 0,
|
|
|
|
|
GameState.Current == State.GameOver ? 1 : 0,
|
|
|
|
|
};
|
|
|
|
|
AudioMixerSnapshot[] Snapshots = {
|
|
|
|
|
PlayingSnapshot,
|
|
|
|
|
PausedSnapshot,
|
|
|
|
|
GameoverSnapshot,
|
|
|
|
|
};
|
|
|
|
|
Mixer.TransitionToSnapshots(Snapshots, Weights, TransitionDuration);
|
2020-04-19 22:09:31 +02:00
|
|
|
|
|
|
|
|
|
Mixer.SetFloat("Master Volume", ConvertRatioToDecibel(Options.MasterVolume));
|
|
|
|
|
Mixer.SetFloat("Campfire Volume", ConvertRatioToDecibel(Options.CampfireVolume));
|
|
|
|
|
Mixer.SetFloat("Ambient Volume", ConvertRatioToDecibel(Options.AmbientVolume));
|
|
|
|
|
Mixer.SetFloat("Footstep Volume", ConvertRatioToDecibel(Options.FootstepVolume));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private float ConvertRatioToDecibel(float x) {
|
|
|
|
|
return (Mathf.Pow(x, 0.16f) - 1) * 60f;
|
2020-04-19 01:12:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|