Advertisement
evelynshilosky

SettingsManager - Part 31

Feb 2nd, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using TMPro;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using static SaveManager;
  8.  
  9. public class SettingsManager : MonoBehaviour
  10. {
  11.     public static SettingsManager Instance { get; set; }
  12.  
  13.     public Button backBTN;
  14.  
  15.  
  16.     public Slider masterSlider;
  17.     public GameObject masterValue;
  18.  
  19.     public Slider musicSlider;
  20.     public GameObject musicValue;
  21.  
  22.     public Slider effectsSlider;
  23.     public GameObject effectsValue;
  24.  
  25.     private void Start()
  26.     {
  27.         backBTN.onClick.AddListener(() =>
  28.         {            
  29.             SaveManager.Instance.SaveVolumeSettings(musicSlider.value, effectsSlider.value, masterSlider.value);
  30.         });
  31.  
  32.         StartCoroutine(LoadAndApplySettings());
  33.  
  34.     }
  35.  
  36.     private IEnumerator LoadAndApplySettings()
  37.     {
  38.         LoadAndSetVolume();
  39.  
  40.         // Load GraphicsSettings
  41.         // Load Key Bindinds
  42.  
  43.         yield return new WaitForSeconds(0.1f);
  44.     }
  45.  
  46.     private void LoadAndSetVolume()
  47.     {
  48.         VolumeSettings volumeSettings = SaveManager.Instance.LoadVolumeSettings();
  49.  
  50.         masterSlider.value = volumeSettings.master;
  51.         musicSlider.value = volumeSettings.music;
  52.         effectsSlider.value = volumeSettings.effects;
  53.  
  54.         print("Volume Settings are Loaded");
  55.     }
  56.  
  57.     private void Awake()
  58.     {
  59.         if (Instance != null && Instance != this)
  60.         {
  61.             Destroy(gameObject);
  62.         }
  63.         else
  64.         {
  65.             Instance = this;
  66.         }
  67.     }
  68.  
  69.     private void Update()
  70.     {
  71.         masterValue.GetComponent<TextMeshProUGUI>().text = "" + (masterSlider.value) + "";
  72.         musicValue.GetComponent<TextMeshProUGUI>().text = "" + (musicSlider.value) + "";
  73.         effectsValue.GetComponent<TextMeshProUGUI>().text = "" + (effectsSlider.value) + "";
  74.     }
  75.  
  76.  
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement