﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Audio;

public class SetMixerFloatPrefs : MonoBehaviour
{
    [System.Serializable]
    public class Preference
    {
        public string name;
        public float defaultValue = 1;
        public AnimationCurve curve;
    }

    public AudioMixer mixer;
    public Preference[] preferences;

    private void Start()
    {
        foreach (var p in preferences)
        {
            float value = PlayerPrefs.GetFloat(p.name, p.defaultValue);

            if (!PlayerPrefs.HasKey(p.name))
                PlayerPrefs.SetFloat(p.name, value);

            if (p.curve != null && p.curve.keys.Length >= 2)
                value = p.curve.Evaluate(value);

            if (PlayerPrefs.GetInt(p.name + "_mute", 0) > 0)
                value = -80;

            mixer.SetFloat(p.name, value);
        }
    }
}
