revival/game/Assets/Scripts/Settings/PlayerPrefSlider.cs

30 lines
680 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(Slider))]
public class PlayerPrefSlider : MonoBehaviour
{
private Slider _slider;
[SerializeField]
private float _defaultValue;
[SerializeField]
private PlayerPrefValue _playerPref;
private void Awake()
{
_slider = GetComponent<Slider>();
_slider.onValueChanged.AddListener( _playerPref.SetFloat );
}
private void OnEnable()
{
float value = _playerPref.GetFloat(_defaultValue);
_slider.SetValueWithoutNotify( value );
}
}