Browse Source

Add sliders to control the volume of the game.

master
Cidney Hamilton 6 months ago
parent
commit
dbdf09648e
  1. 4
      Assets/Audio/Music.mixer
  2. 9
      Assets/Audio/SFX.mixer
  3. 66
      Assets/Scenes/_Options.unity
  4. 8
      Assets/Scripts/Settings.meta
  5. 0
      Assets/Scripts/Settings/SettingsView.cs
  6. 0
      Assets/Scripts/Settings/SettingsView.cs.meta
  7. 27
      Assets/Scripts/Settings/Slider.cs
  8. 11
      Assets/Scripts/Settings/Slider.cs.meta
  9. 54
      Assets/Scripts/Settings/VolumeSlider.cs
  10. 11
      Assets/Scripts/Settings/VolumeSlider.cs.meta

4
Assets/Audio/Music.mixer

@ -15,7 +15,9 @@ AudioMixerController:
m_SuspendThreshold: -80
m_EnableSuspend: 1
m_UpdateMode: 0
m_ExposedParameters: []
m_ExposedParameters:
- guid: 8ccde8d22824f310788148404a4e2320
name: volume
m_AudioMixerGroupViews:
- guids:
- 5887fedcdfeeaeb7684dc13ef74b31b9

9
Assets/Audio/SFX.mixer

@ -15,8 +15,13 @@ AudioMixerController:
m_SuspendThreshold: -80
m_EnableSuspend: 1
m_UpdateMode: 0
m_ExposedParameters: []
m_AudioMixerGroupViews: []
m_ExposedParameters:
- guid: 19d6f3c41959cc8f28cc0cc9e3bb56f5
name: volume
m_AudioMixerGroupViews:
- guids:
- 7469c42513e36b504ae091ca62237fa7
name: View
m_CurrentViewIndex: 0
m_TargetSnapshot: {fileID: 24500006}
--- !u!243 &24300002

66
Assets/Scenes/_Options.unity

@ -135,7 +135,7 @@ GameObject:
- component: {fileID: 100352437}
- component: {fileID: 100352441}
m_Layer: 5
m_Name: Canvas
m_Name: OptionsCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
@ -243,6 +243,7 @@ GameObject:
m_Component:
- component: {fileID: 102700373}
- component: {fileID: 102700374}
- component: {fileID: 102700375}
m_Layer: 5
m_Name: Slider
m_TagString: Untagged
@ -315,13 +316,38 @@ MonoBehaviour:
m_FillRect: {fileID: 1543169955}
m_HandleRect: {fileID: 1185981088}
m_Direction: 0
m_MinValue: 0
m_MinValue: 0.001
m_MaxValue: 1
m_WholeNumbers: 0
m_Value: 0
m_Value: 0.75
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 102700375}
m_MethodName: UpdateSlider
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &102700375
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 102700372}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a8f52b50b045653bebcce8d08b44a1ee, type: 3}
m_Name:
m_EditorClassIdentifier:
slider: {fileID: 102700374}
volumeMixer: {fileID: 24100000, guid: 9bed33fc93df51c228bcfa39e8cfbc38, type: 2}
--- !u!1 &278035152
GameObject:
m_ObjectHideFlags: 0
@ -1278,6 +1304,7 @@ GameObject:
m_Component:
- component: {fileID: 1380099119}
- component: {fileID: 1380099120}
- component: {fileID: 1380099121}
m_Layer: 5
m_Name: Slider
m_TagString: Untagged
@ -1350,13 +1377,38 @@ MonoBehaviour:
m_FillRect: {fileID: 808624491}
m_HandleRect: {fileID: 1518862530}
m_Direction: 0
m_MinValue: 0
m_MinValue: 0.001
m_MaxValue: 1
m_WholeNumbers: 0
m_Value: 0
m_Value: 0.75
m_OnValueChanged:
m_PersistentCalls:
m_Calls: []
m_Calls:
- m_Target: {fileID: 1380099121}
m_MethodName: UpdateSlider
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
--- !u!114 &1380099121
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1380099118}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a8f52b50b045653bebcce8d08b44a1ee, type: 3}
m_Name:
m_EditorClassIdentifier:
slider: {fileID: 1380099120}
volumeMixer: {fileID: 24100000, guid: 0b657966100da7e5d98afdc186ba2d4d, type: 2}
--- !u!1 &1396554749
GameObject:
m_ObjectHideFlags: 0

8
Assets/Scripts/Settings.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6ef7ea4d23df1b129949fe92ec3128d2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

0
Assets/Scripts/SettingsView.cs → Assets/Scripts/Settings/SettingsView.cs

0
Assets/Scripts/SettingsView.cs.meta → Assets/Scripts/Settings/SettingsView.cs.meta

27
Assets/Scripts/Settings/Slider.cs

@ -0,0 +1,27 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Cyborg.Clinic {
// A slider with two buttons to toggle up and down
public abstract class Slider : MonoBehaviour
{
public UnityEngine.UI.Slider slider;
public virtual void Up() {
if (slider != null) {
slider.value = Mathf.Clamp(slider.value + 1f, slider.minValue, slider.maxValue);
}
}
public virtual void Down() {
if (slider != null) {
slider.value = Mathf.Clamp(slider.value - 1f, slider.minValue, slider.maxValue);
}
}
}
}

11
Assets/Scripts/Settings/Slider.cs.meta

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

54
Assets/Scripts/Settings/VolumeSlider.cs

@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;
using Cyborg.Audio;
namespace Cyborg.Clinic {
// Slider to adjust the in-game volume
public class VolumeSlider : Slider
{
const float SCALE_FACTOR = 10f;
public AudioMixer volumeMixer;
const string VOLUME = "volume";
float mixerVolume;
void Start()
{
volumeMixer.GetFloat(VOLUME, out mixerVolume);
slider.value = VolumeToSliderValue(mixerVolume);
}
private float VolumeToSliderValue(float volume) {
return Mathf.Pow(10, volume/20);
}
private float SliderValueToVolume(float value) {
return Mathf.Log10(value) * 20;
}
public void UpdateSlider() {
if (slider != null) {
volumeMixer.SetFloat(VOLUME, SliderValueToVolume(slider.value));
}
}
public override void Up() {
base.Up();
UpdateSlider();
AudioEvents.PlaySound("click");
}
public override void Down() {
base.Down();
UpdateSlider();
AudioEvents.PlaySound("click");
}
}
}

11
Assets/Scripts/Settings/VolumeSlider.cs.meta

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a8f52b50b045653bebcce8d08b44a1ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save