From 3d3813d164cca88294e348f7b13f65b408011cda Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Sun, 17 Dec 2023 20:36:01 +0000
Subject: [PATCH] Added volume settings in settings menu

---
 Assets/Scripts/SoundManager.cs |   43 +++++++++++++++++++++++++------------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/Assets/Scripts/SoundManager.cs b/Assets/Scripts/SoundManager.cs
index 0ecdc0d..a3b8107 100644
--- a/Assets/Scripts/SoundManager.cs
+++ b/Assets/Scripts/SoundManager.cs
@@ -90,6 +90,10 @@
         DontDestroyOnLoad(this);
         PlaySound(SoundName.MusicHappy);
     }
+    private void Start()
+    {
+        LoadAudioSettings();
+    }
 
     public void PlaySound(SoundName _name)
     {
@@ -106,7 +110,7 @@
         }
 
         //no Sound with name
-        Debug.LogWarning("SoundManager: Sounds not found in list: " + _name);
+        Debug.LogWarning("AudioManager: Sounds not found in list, add sound to audiomanager: " + _name);
     }
 
     public void PlaySoundAtPoint(GameObject gObject, SoundName _name)
@@ -129,7 +133,7 @@
         }
 
         //no Sound with name
-        Debug.LogWarning("SoundManager: Sounds not found in list: " + _name);
+        Debug.LogWarning("AudioManager: Sounds not found in list, add sound to audiomanager: " + _name);
     }
 
     private static AudioSource PlayClipAtPointCustom(AudioSource audioSource, Vector3 pos, Sound sound)
@@ -190,7 +194,6 @@
                 return;
             }
         }
-        Debug.Log("No music was playing!");
         PlaySound(_name);
         return;
     }
@@ -200,46 +203,50 @@
         PlayerPrefs.SetFloat("pVolMaster", volMaster);
         PlayerPrefs.SetFloat("pVolMusic", volMusic);
         PlayerPrefs.SetFloat("pVolSFX", volSFX);
+    }
 
-        Debug.Log("Saved Options");
+    public void DiscardAudioSettings()
+    {
+        volMaster = PlayerPrefs.GetFloat("pVolMaster");
+        volMusic = PlayerPrefs.GetFloat("pVolMusic");
+        volSFX = PlayerPrefs.GetFloat("pVolSFX");
+        ChangeMasterVolume(volMaster);
+        ChangeSfxVolume(volSFX);
+        ChangeMusicVolume(volMusic);
     }
 
     public void LoadAudioSettings()
     {
-        GameObject tempGO = new GameObject("TempSlider");
-
         if (PlayerPrefs.HasKey("pVolMaster") == false)
         {
-            PlayerPrefs.SetFloat("pVolMaster", 0.5f);
+            PlayerPrefs.SetFloat("pVolMaster", 1f);
         }
 
         if (PlayerPrefs.HasKey("pVolMusic") == false)
         {
-            PlayerPrefs.SetFloat("pVolMusic", 0.5f);
+            PlayerPrefs.SetFloat("pVolMusic", 1f);
         }
 
         if (PlayerPrefs.HasKey("pVolSFX") == false)
         {
-            PlayerPrefs.SetFloat("pVolSFX", 0.5f);
+            PlayerPrefs.SetFloat("pVolSFX", 1f);
         }
 
         volMaster = PlayerPrefs.GetFloat("pVolMaster");
         volMusic = PlayerPrefs.GetFloat("pVolMusic");
         volSFX = PlayerPrefs.GetFloat("pVolSFX");
 
-        if (GameObject.Find("SliderVolume") == false)
+        if (GameObject.Find("SliderVolume") == true && GameObject.Find("SliderSFX") == true && GameObject.Find("SliderMusic") == true)
         {
-            ChangeMasterVolume(volMaster);
-            ChangeSfxVolume(volSFX);
-            ChangeMusicVolume(volMusic);
-            return;
+            GameObject.Find("SliderVolume").GetComponent<Slider>().value = volMaster;
+            //ChangeMasterVolume(volMaster);
+            GameObject.Find("SliderSFX").GetComponent<Slider>().value = volSFX;
+            //ChangeSfxVolume(volSFX);
+            GameObject.Find("SliderMusic").GetComponent<Slider>().value = volMusic;
+            //ChangeMusicVolume(volMusic);
         }
-
-        GameObject.Find("SliderVolume").GetComponent<Slider>().value = volMaster;
         ChangeMasterVolume(volMaster);
-        GameObject.Find("SliderSFX").GetComponent<Slider>().value = volSFX;
         ChangeSfxVolume(volSFX);
-        GameObject.Find("SliderMusic").GetComponent<Slider>().value = volMusic;
         ChangeMusicVolume(volMusic);
 
     }

--
Gitblit v1.9.3