Implement pause menu options

This commit is contained in:
Jens Pitkänen 2020-04-19 23:09:31 +03:00
parent 6dee081ae4
commit cd1c3f27d4
12 changed files with 2545 additions and 81 deletions

View File

@ -32,7 +32,7 @@ AudioMixerGroupController:
m_Send: 00000000000000000000000000000000 m_Send: 00000000000000000000000000000000
m_Effects: m_Effects:
- {fileID: -6119931374106344343} - {fileID: -6119931374106344343}
m_UserColorIndex: 0 m_UserColorIndex: 1
m_Mute: 0 m_Mute: 0
m_Solo: 0 m_Solo: 0
m_BypassEffects: 0 m_BypassEffects: 0
@ -63,7 +63,7 @@ AudioMixerGroupController:
m_Send: 00000000000000000000000000000000 m_Send: 00000000000000000000000000000000
m_Effects: m_Effects:
- {fileID: 3581666672454972537} - {fileID: 3581666672454972537}
m_UserColorIndex: 0 m_UserColorIndex: 8
m_Mute: 0 m_Mute: 0
m_Solo: 0 m_Solo: 0
m_BypassEffects: 0 m_BypassEffects: 0
@ -94,7 +94,7 @@ AudioMixerGroupController:
m_Send: 00000000000000000000000000000000 m_Send: 00000000000000000000000000000000
m_Effects: m_Effects:
- {fileID: 1928862306469247254} - {fileID: 1928862306469247254}
m_UserColorIndex: 0 m_UserColorIndex: 3
m_Mute: 0 m_Mute: 0
m_Solo: 0 m_Solo: 0
m_BypassEffects: 0 m_BypassEffects: 0
@ -116,7 +116,15 @@ AudioMixerController:
m_SuspendThreshold: -80 m_SuspendThreshold: -80
m_EnableSuspend: 1 m_EnableSuspend: 1
m_UpdateMode: 1 m_UpdateMode: 1
m_ExposedParameters: [] m_ExposedParameters:
- guid: f61e9e8888930534e91c19809f219fe6
name: Ambient Volume
- guid: fd01f6bdeaa870c4688fa6fcad7c3e41
name: Campfire Volume
- guid: fb57fa187cc2b4149a071e77ee9f3a45
name: Footstep Volume
- guid: 1dc5725402baaca40b189e10927dfd5f
name: Master Volume
m_AudioMixerGroupViews: m_AudioMixerGroupViews:
- guids: - guids:
- cce571dfddcbc694fa5856a9866157f8 - cce571dfddcbc694fa5856a9866157f8
@ -192,7 +200,7 @@ AudioMixerGroupController:
m_Send: 00000000000000000000000000000000 m_Send: 00000000000000000000000000000000
m_Effects: m_Effects:
- {fileID: 3705997264899357636} - {fileID: 3705997264899357636}
m_UserColorIndex: 0 m_UserColorIndex: 6
m_Mute: 0 m_Mute: 0
m_Solo: 0 m_Solo: 0
m_BypassEffects: 0 m_BypassEffects: 0

File diff suppressed because it is too large Load Diff

View File

@ -313,6 +313,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
GameState: {fileID: 834592896} GameState: {fileID: 834592896}
Options: {fileID: 481528468}
Mixer: {fileID: 24100000, guid: 032de345950918c4e89684078c6a7213, type: 2} Mixer: {fileID: 24100000, guid: 032de345950918c4e89684078c6a7213, type: 2}
PlayingSnapshot: {fileID: -3105936107480203619, guid: 032de345950918c4e89684078c6a7213, PlayingSnapshot: {fileID: -3105936107480203619, guid: 032de345950918c4e89684078c6a7213,
type: 2} type: 2}
@ -577,6 +578,18 @@ RectTransform:
type: 3} type: 3}
m_PrefabInstance: {fileID: 531861614376686525} m_PrefabInstance: {fileID: 531861614376686525}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &481528468 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 2837007226937140173, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
m_PrefabInstance: {fileID: 5400695019531174117}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4082236b98d7bfb42b8cd2b342f7f31c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &483093624 --- !u!1001 &483093624
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2388,6 +2401,11 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8651001597528790401, guid: 8ee6eecf5317b4841817712d24763e37,
type: 3}
propertyPath: GameState
value:
objectReference: {fileID: 834592896}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8ee6eecf5317b4841817712d24763e37, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8ee6eecf5317b4841817712d24763e37, type: 3}
--- !u!1 &1585922906 stripped --- !u!1 &1585922906 stripped
@ -3500,16 +3518,81 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 1921606960} m_TransformParent: {fileID: 1921606960}
m_Modifications: m_Modifications:
- target: {fileID: 226479021477264902, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 226479021477264902, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 60
objectReference: {fileID: 0}
- target: {fileID: 317676106527232818, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 410328268247982429, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 519962654072447509, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -100
objectReference: {fileID: 0}
- target: {fileID: 1470294652521727049, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1717919654148306914, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1717919654148306914, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 240
objectReference: {fileID: 0}
- target: {fileID: 2859368322435670320, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3479557468769067426, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3479557468769067426, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 120
objectReference: {fileID: 0}
- target: {fileID: 3588221716476260827, guid: 2cd64e49ad7ad1c4bb4a4264703d7915, - target: {fileID: 3588221716476260827, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3} type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3682198691915602031, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3965423868489175230, guid: 2cd64e49ad7ad1c4bb4a4264703d7915, - target: {fileID: 3965423868489175230, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3} type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4127888187077662439, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -150
objectReference: {fileID: 0}
- target: {fileID: 5400695020334462788, guid: 2cd64e49ad7ad1c4bb4a4264703d7915, - target: {fileID: 5400695020334462788, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3} type: 3}
propertyPath: m_Alpha propertyPath: m_Alpha
@ -3555,11 +3638,51 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Pause Menu value: Pause Menu
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5638636099959851731, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6081099778283769688, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: -50
objectReference: {fileID: 0}
- target: {fileID: 6723009973072559076, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6793835621275301599, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7379875903275102228, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7379875903275102228, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchoredPosition.y
value: 180
objectReference: {fileID: 0}
- target: {fileID: 7729775465812122422, guid: 2cd64e49ad7ad1c4bb4a4264703d7915, - target: {fileID: 7729775465812122422, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3} type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 8362288861398798554, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8596077905715532586, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8904450836871494407, guid: 2cd64e49ad7ad1c4bb4a4264703d7915, - target: {fileID: 8904450836871494407, guid: 2cd64e49ad7ad1c4bb4a4264703d7915,
type: 3} type: 3}
propertyPath: m_AnchorMax.y propertyPath: m_AnchorMax.y
@ -3584,6 +3707,11 @@ PrefabInstance:
propertyPath: GameState propertyPath: GameState
value: value:
objectReference: {fileID: 834592896} objectReference: {fileID: 834592896}
- target: {fileID: 6125707630481988370, guid: 558201eae20fa5540a826edb23937665,
type: 3}
propertyPath: Options
value:
objectReference: {fileID: 481528468}
- target: {fileID: 6125707630481988396, guid: 558201eae20fa5540a826edb23937665, - target: {fileID: 6125707630481988396, guid: 558201eae20fa5540a826edb23937665,
type: 3} type: 3}
propertyPath: m_LocalPosition.x propertyPath: m_LocalPosition.x

View File

@ -3,6 +3,7 @@ using UnityEngine.Audio;
public class AudioMaster : MonoBehaviour { public class AudioMaster : MonoBehaviour {
public GameState GameState; public GameState GameState;
public Options Options;
public AudioMixer Mixer; public AudioMixer Mixer;
public AudioMixerSnapshot PlayingSnapshot; public AudioMixerSnapshot PlayingSnapshot;
@ -22,5 +23,14 @@ public class AudioMaster : MonoBehaviour {
GameoverSnapshot, GameoverSnapshot,
}; };
Mixer.TransitionToSnapshots(Snapshots, Weights, TransitionDuration); Mixer.TransitionToSnapshots(Snapshots, Weights, TransitionDuration);
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;
} }
} }

View File

@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteAlways]
public class AutoListPositioner : MonoBehaviour {
public float Padding;
public List<float> SpecificPaddings;
private void Update() {
if (Application.isEditor) {
for (int Index = SpecificPaddings.Count; Index < transform.childCount - 1; Index++) {
SpecificPaddings.Add(Padding);
}
RectTransform Parent = GetComponent<RectTransform>();
float Y = Parent.position.y;
for (int Index = 0; Index < transform.childCount; Index++) {
RectTransform Child = transform.GetChild(Index).GetComponent<RectTransform>();
if (Child) {
Child.position = new Vector2(Child.position.x, Y);
if (Index < SpecificPaddings.Count) {
Y -= Child.rect.height + SpecificPaddings[Index];
}
} else {
Debug.LogWarning($"AutoListPositioner {name} has non-UI children!");
}
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 47037e59030599a45aa61a1248c05e3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,6 +4,7 @@ using UnityEngine;
public class CameraController : MonoBehaviour { public class CameraController : MonoBehaviour {
public GameState GameState; public GameState GameState;
public Options Options;
public Transform BodyTransform; public Transform BodyTransform;
public Transform HeadTransform; public Transform HeadTransform;
@ -19,11 +20,11 @@ public class CameraController : MonoBehaviour {
Cursor.lockState = CursorLockMode.Locked; Cursor.lockState = CursorLockMode.Locked;
Vector3 Eulers = BodyTransform.localEulerAngles; Vector3 Eulers = BodyTransform.localEulerAngles;
Eulers.y += Input.GetAxis("Mouse X"); Eulers.y += Input.GetAxis("Mouse X") * Options.MouseSensitivity * (Options.InvertMouseX ? -1 : 1);
BodyTransform.localEulerAngles = Eulers; BodyTransform.localEulerAngles = Eulers;
Eulers = HeadTransform.localEulerAngles; Eulers = HeadTransform.localEulerAngles;
Eulers.x -= Input.GetAxis("Mouse Y"); Eulers.x -= Input.GetAxis("Mouse Y") * Options.MouseSensitivity * (Options.InvertMouseY ? -1 : 1);
if (Eulers.x > 90 && Eulers.x < 180) { if (Eulers.x > 90 && Eulers.x < 180) {
Eulers.x = 90; Eulers.x = 90;
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CampfireSfx : MonoBehaviour { public class CampfireSfx : MonoBehaviour {
public GameState GameState;
public AudioSource ActiveBurnSource; public AudioSource ActiveBurnSource;
public AudioSource AmbientSource; public AudioSource AmbientSource;
public AudioSource IntenseAmbientSource; public AudioSource IntenseAmbientSource;
@ -18,10 +19,6 @@ public class CampfireSfx : MonoBehaviour {
private void Update() { private void Update() {
ActiveBurn = Mathf.Max(0, ActiveBurn - Time.deltaTime); ActiveBurn = Mathf.Max(0, ActiveBurn - Time.deltaTime);
ActiveBurnSource.pitch = Time.timeScale;
AmbientSource.pitch = Time.timeScale;
IntenseAmbientSource.pitch = Time.timeScale;
if (Campfire.TimeToEnd <= 0) { if (Campfire.TimeToEnd <= 0) {
IntenseAmbientSource.volume = Mathf.Lerp(IntenseAmbientSource.volume, 0, 10f * Time.deltaTime); IntenseAmbientSource.volume = Mathf.Lerp(IntenseAmbientSource.volume, 0, 10f * Time.deltaTime);
ActiveBurnSource.volume = Mathf.Lerp(ActiveBurnSource.volume, 0, 10f * Time.deltaTime); ActiveBurnSource.volume = Mathf.Lerp(ActiveBurnSource.volume, 0, 10f * Time.deltaTime);
@ -33,9 +30,8 @@ public class CampfireSfx : MonoBehaviour {
AmbientSource.volume = Mathf.Lerp(AmbientSource.volume, 1, 10f * Time.deltaTime); AmbientSource.volume = Mathf.Lerp(AmbientSource.volume, 1, 10f * Time.deltaTime);
} }
bool StartEndClip = Campfire.TimeToEnd <= EndClip.length && AmbientSource.clip != EndClip; bool StartEndClip = Campfire.TimeToEnd <= EndClip.length && AmbientSource.clip != EndClip;
bool StopEndClip = Campfire.TimeToEnd > EndClip.length && AmbientSource.clip == EndClip; bool StopEndClip = AmbientSource.clip == EndClip && (Campfire.TimeToEnd > EndClip.length || GameState.Current == State.Paused);
if (StartEndClip) { if (StartEndClip) {
AmbientSource.clip = EndClip; AmbientSource.clip = EndClip;
AmbientSource.time = Mathf.Clamp(EndClip.length - Campfire.TimeToEnd, 0, EndClip.length - 0.01f); AmbientSource.time = Mathf.Clamp(EndClip.length - Campfire.TimeToEnd, 0, EndClip.length - 0.01f);

View File

@ -22,10 +22,6 @@ public class GameOverMenu : MonoBehaviour {
Canvas.blocksRaycasts = IsGameOver; Canvas.blocksRaycasts = IsGameOver;
} }
public void Resume() {
GameState.Current = State.Playing;
}
public void Replay() { public void Replay() {
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
} }

23
Assets/Scripts/Options.cs Normal file
View File

@ -0,0 +1,23 @@
using UnityEngine;
public class Options : MonoBehaviour {
public bool InvertMouseX { get; set; }
public bool InvertMouseY { get; set; }
public bool CameraBobbing { get; set; }
public float MouseSensitivity { get; set; }
public float MasterVolume { get; set; }
public float CampfireVolume { get; set; }
public float AmbientVolume { get; set; }
public float FootstepVolume { get; set; }
private void Awake() {
InvertMouseX = false;
InvertMouseY = false;
CameraBobbing = false;
MouseSensitivity = 2f;
MasterVolume = 0.3f;
CampfireVolume = 1f;
AmbientVolume = 1f;
FootstepVolume = 1f;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4082236b98d7bfb42b8cd2b342f7f31c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +1,20 @@
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(CanvasGroup))] [RequireComponent(typeof(CanvasGroup))]
public class PauseMenu : MonoBehaviour { public class PauseMenu : MonoBehaviour {
public GameState GameState; public GameState GameState;
public Options Options;
[Header("Option inputs")]
public Toggle InvertMouseX;
public Toggle InvertMouseY;
public Toggle CameraBobbing;
public Slider MouseSensitivity;
public Slider MasterVolume;
public Slider CampfireVolume;
public Slider AmbientVolume;
public Slider FootstepVolume;
private CanvasGroup Canvas; private CanvasGroup Canvas;
private bool Paused { private bool Paused {
@ -16,6 +28,17 @@ public class PauseMenu : MonoBehaviour {
Fade(true); Fade(true);
} }
private void Start() {
InvertMouseX.isOn = Options.InvertMouseX;
InvertMouseY.isOn = Options.InvertMouseY;
CameraBobbing.isOn = Options.CameraBobbing;
MouseSensitivity.value = Options.MouseSensitivity;
MasterVolume.value = Options.MasterVolume;
CampfireVolume.value = Options.CampfireVolume;
AmbientVolume.value = Options.AmbientVolume;
FootstepVolume.value = Options.FootstepVolume;
}
private void Update() { private void Update() {
Fade(false); Fade(false);
} }
@ -24,4 +47,8 @@ public class PauseMenu : MonoBehaviour {
Canvas.alpha = Mathf.Lerp(Canvas.alpha, Paused ? 1 : 0, instant ? 1 : 10f * Time.unscaledDeltaTime); Canvas.alpha = Mathf.Lerp(Canvas.alpha, Paused ? 1 : 0, instant ? 1 : 10f * Time.unscaledDeltaTime);
Canvas.blocksRaycasts = Paused; Canvas.blocksRaycasts = Paused;
} }
public void Resume() {
GameState.Current = State.Playing;
}
} }