using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingsFmod : MonoBehaviour
{
    public Slider sliderMaster, sliderMusic, sliderEffects;

    FMOD.Studio.Bus Masterbus;
    FMOD.Studio.Bus Musicbus;
    FMOD.Studio.Bus Effectbus;

    void Awake()
    {
        Masterbus = FMODUnity.RuntimeManager.GetBus("bus:/");
        Musicbus = FMODUnity.RuntimeManager.GetBus("bus:/MusicBus");
        Effectbus = FMODUnity.RuntimeManager.GetBus("bus:/EffectBus");
        InitSettings();


    }

    private void InitSettings()
    {
        SetMasterVolume(PlayerPrefs.GetFloat("MasterVolume", 80f));
        SetEffectsVolume(PlayerPrefs.GetFloat("EffectsVolume", 80f));
        SetMusicVolume(PlayerPrefs.GetFloat("MusicVolume", 80f));
    }

    public void SetMasterVolume(float percentage)
    {
        //float db = 20 * Mathf.Log10(percentage / 100);
        float db = percentage;

        Masterbus.setVolume(db);

        PlayerPrefs.SetFloat("MasterVolume", percentage);
        PlayerPrefs.Save();
    }

    public void SetEffectsVolume(float percentage)
    {
        //float db = 20 * Mathf.Log10(percentage / 100);
        float db = percentage;

        Effectbus.setVolume(db);

        PlayerPrefs.SetFloat("EffectsVolume", percentage);
        PlayerPrefs.Save();
    }

    public void SetMusicVolume(float percentage)
    {
        //float db = 20 * Mathf.Log10(percentage / 100);
        float db = percentage;

        Musicbus.setVolume(db);

        PlayerPrefs.SetFloat("MusicVolume", percentage);
        PlayerPrefs.Save();
    }
}
