campfire/Assets/Scripts/PauseMenu.cs

62 lines
1.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CanvasGroup))]
public class PauseMenu : MonoBehaviour {
public GameState GameState;
public Options Options;
[Header("Option inputs")]
public Toggle InvertMouseY;
public Toggle CameraBobbing;
public Slider MouseSensitivity;
public Slider RenderScale;
public Slider MasterVolume;
public Slider CampfireVolume;
public Slider AmbientVolume;
public Slider FootstepVolume;
public Slider DiaryVolume;
private CanvasGroup Canvas;
private bool Paused {
get {
return GameState.Current == State.Paused;
}
}
private void Awake() {
Canvas = GetComponent<CanvasGroup>();
Fade(true);
}
private void Start() {
InvertMouseY.isOn = Options.InvertMouseY;
CameraBobbing.isOn = Options.CameraBobbing;
MouseSensitivity.value = Options.MouseSensitivity;
RenderScale.value = Options.RenderScale;
MasterVolume.value = Options.MasterVolume;
CampfireVolume.value = Options.CampfireVolume;
AmbientVolume.value = Options.AmbientVolume;
FootstepVolume.value = Options.FootstepVolume;
DiaryVolume.value = Options.DiaryVolume;
}
private void Update() {
Fade(false);
}
private void Fade(bool instant) {
Canvas.alpha = Mathf.Lerp(Canvas.alpha, Paused ? 1 : 0, instant ? 1 : 10f * Time.unscaledDeltaTime);
Canvas.blocksRaycasts = Paused;
Canvas.interactable = Paused;
}
public void Resume() {
GameState.Current = State.Playing;
}
public void Quit() {
Application.Quit();
}
}