setting change
This commit is contained in:
73
Assets/Scripts/UI/Settings/SettingWaitInputPanel.cs
Normal file
73
Assets/Scripts/UI/Settings/SettingWaitInputPanel.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
using UnityEngine;
|
||||
using NBC;
|
||||
using NBF.Setting;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class SettingWaitInputPanel : UIPanel
|
||||
{
|
||||
private SettingItem _settingItem;
|
||||
private InputOption _inputOption;
|
||||
private InputActionRebindingExtensions.RebindingOperation rebindingOperation;
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
_settingItem = GetData() as SettingItem;
|
||||
if (_settingItem == null)
|
||||
{
|
||||
Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_settingItem.Option is InputOption inputOption)
|
||||
{
|
||||
_inputOption = inputOption;
|
||||
OnRebinding();
|
||||
}
|
||||
}
|
||||
|
||||
#region 按键绑定
|
||||
|
||||
private void OnRebinding()
|
||||
{
|
||||
// 开始重绑定操作
|
||||
rebindingOperation = _inputOption.InputAction.PerformInteractiveRebinding(_inputOption.BindingIndex)
|
||||
.OnMatchWaitForAnother(0.1f)
|
||||
.OnComplete(operation => RebindComplete())
|
||||
.OnCancel(operation => RebindCanceled())
|
||||
.Start();
|
||||
}
|
||||
|
||||
private void RebindComplete()
|
||||
{
|
||||
rebindingOperation.Dispose();
|
||||
_inputOption.InputAction.Enable();
|
||||
UpdateValueText();
|
||||
}
|
||||
|
||||
private void RebindCanceled()
|
||||
{
|
||||
rebindingOperation.Dispose();
|
||||
_inputOption.InputAction.Enable();
|
||||
Hide();
|
||||
}
|
||||
|
||||
private void UpdateValueText()
|
||||
{
|
||||
_settingItem.UpdateValueText();
|
||||
Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[InputInvoke(InputDef.UI.Back)]
|
||||
private void OnBack()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user