完成设置按键绑定和取消绑定

This commit is contained in:
bob
2025-06-23 10:52:47 +08:00
parent 07ebc1a1a7
commit 2024bfb990
4 changed files with 39 additions and 2 deletions

View File

@@ -25,8 +25,8 @@ namespace NBF.Setting
public override void Apply()
{
// 保存绑定
PlayerPrefs.SetString(SaveKey, InputAction.SaveBindingOverridesAsJson());
SaveValue = Value;
InputSaveValue = InputAction.SaveBindingOverridesAsJson();
PlayerPrefs.SetString(SaveKey, InputSaveValue);
OnApply();
}
@@ -66,6 +66,18 @@ namespace NBF.Setting
}
}
public override void Cancel()
{
if (!string.IsNullOrEmpty(InputSaveValue))
{
InputAction.LoadBindingOverridesFromJson(InputSaveValue);
}
else
{
Reset();
}
}
public override string GetDisplayString()
{
if (InputAction != null)

View File

@@ -83,6 +83,12 @@ namespace NBF.Setting
Value = DefaultValue;
}
public virtual void Cancel()
{
}
public virtual string GetDisplayString()
{
return GetValue().ToString();

View File

@@ -131,6 +131,7 @@ namespace NBF
{
option.Apply();
}
Notices.Success("TEXT_OP_SUCCESS");
}
private void OnResetSettings()
@@ -240,6 +241,7 @@ namespace NBF
{
if (b)
{
CancelAndBack();
Hide();
}
});
@@ -250,6 +252,23 @@ namespace NBF
}
}
private void CancelAndBack()
{
var groupNames = Settings.Instance.GetAllTabs();
foreach (var group in groupNames)
{
var options = Settings.Instance.GetOptionsByTab(group);
foreach (var option in options)
{
if (option.HaveNotApple())
{
option.Cancel();
}
}
}
}
protected override void OnHide()
{
base.OnHide();

Binary file not shown.