按键绑定和重置以及加载功能
This commit is contained in:
@@ -1,36 +1,80 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using System.Globalization;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using NBF.Setting;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class SettingInputItem : GButton
|
||||
{
|
||||
public OptionBase Option;
|
||||
public InputOption Option;
|
||||
private InputActionRebindingExtensions.RebindingOperation rebindingOperation;
|
||||
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
BtnKeyboard.onClick.Set(OnClickRebind);
|
||||
onChanged.Add(SelfChanged);
|
||||
}
|
||||
|
||||
public void SetData(OptionBase option)
|
||||
public void SetData(InputOption option)
|
||||
{
|
||||
Option = option;
|
||||
TextName.SetLanguage(Option.Name);
|
||||
SetShow();
|
||||
UpdateValueText();
|
||||
}
|
||||
|
||||
private void SetShow()
|
||||
public void OnClickRebind()
|
||||
{
|
||||
// InputWaitingPanel.Show(true);
|
||||
// UI.Inst.OpenUI<InputWaitingPanel>();
|
||||
// 取消当前绑定
|
||||
var settingPanel = UI.Inst.GetUI<SettingPanel>();
|
||||
settingPanel.InputWait.visible = true;
|
||||
Option.InputAction.Disable();
|
||||
|
||||
// 开始重绑定操作
|
||||
rebindingOperation = Option.InputAction.PerformInteractiveRebinding(Option.BindingIndex)
|
||||
.OnMatchWaitForAnother(0.1f)
|
||||
.OnComplete(operation => RebindComplete())
|
||||
.OnCancel(operation => RebindCanceled())
|
||||
.Start();
|
||||
}
|
||||
|
||||
private void RebindComplete()
|
||||
{
|
||||
rebindingOperation.Dispose();
|
||||
UpdateValueText();
|
||||
Option.InputAction.Enable();
|
||||
|
||||
var settingPanel = UI.Inst.GetUI<SettingPanel>();
|
||||
settingPanel.InputWait.visible = false;
|
||||
// UI.Inst.HideUI<InputWaitingPanel>();
|
||||
// startRebindObject.SetActive(true);
|
||||
// waitingForInputObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void RebindCanceled()
|
||||
{
|
||||
rebindingOperation.Dispose();
|
||||
Option.InputAction.Enable();
|
||||
// UI.Inst.HideUI<InputWaitingPanel>();
|
||||
}
|
||||
|
||||
|
||||
private void SelfChanged(EventContext context)
|
||||
{
|
||||
if (!selected)
|
||||
{
|
||||
// RebindOver();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateValueText()
|
||||
{
|
||||
BtnKeyboard.SetData(Option as InputOption);
|
||||
BtnKeyboard.SetData(Option);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user