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

25 lines
564 B
C#
Raw Normal View History

2021-03-08 17:26:33 +01:00
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(TMP_Dropdown))]
public class PlayerPrefDropdown : MonoBehaviour
{
private TMP_Dropdown _dropdown;
[SerializeField]
private PlayerPrefValue _playerPref;
private void Awake()
{
_dropdown = GetComponent<TMP_Dropdown>();
_dropdown.onValueChanged.AddListener( _playerPref.SetInt );
}
private void OnEnable()
{
int value = _playerPref.GetInt();
_dropdown.SetValueWithoutNotify( value );
}
}