38 lines
810 B
C#
38 lines
810 B
C#
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UI;
|
|
|
|
public class RebindSaveLoad : MonoBehaviour
|
|
{
|
|
[SerializeField] private InputActionAsset actions;
|
|
[SerializeField] private Button saveButton;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
saveButton.onClick.AddListener(SaveBindings);
|
|
}
|
|
public void OnEnable()
|
|
{
|
|
LoadBindings();
|
|
}
|
|
|
|
public void SaveBindings()
|
|
{
|
|
string rebinds = actions.SaveBindingOverridesAsJson();
|
|
PlayerPrefs.SetString("rebinds", rebinds);
|
|
}
|
|
|
|
private void LoadBindings()
|
|
{
|
|
string rebinds = PlayerPrefs.GetString("rebinds");
|
|
if (!string.IsNullOrEmpty(rebinds))
|
|
actions.LoadBindingOverridesFromJson(rebinds);
|
|
}
|
|
|
|
public void OnDisable()
|
|
{
|
|
SaveBindings();
|
|
}
|
|
}
|