按键绑定和重置以及加载功能
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using NBF.Setting;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
@@ -20,7 +18,7 @@ namespace NBF
|
||||
if (option is KeyBoardOption)
|
||||
{
|
||||
TextKeyboard.visible = true;
|
||||
TextKeyboard.text = option.GetDisplayString();
|
||||
TextKeyboard.text = option.GetDisplayString(); // + "- " + string.Join(",", list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ namespace NBF
|
||||
public GImage BottomLine;
|
||||
[AutoFind(Name = "Mask")]
|
||||
public GLabel Mask;
|
||||
[AutoFind(Name = "InputWait")]
|
||||
public GComponent InputWait;
|
||||
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ using UIPanel = NBC.UIPanel;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[UIBind(UIDef.ID.SettingPanel)]
|
||||
public partial class SettingPanel : UIPanel
|
||||
{
|
||||
public override string UIPackName => "Main";
|
||||
@@ -64,7 +65,7 @@ namespace NBF
|
||||
{
|
||||
// TextTitle.text = Lan.Get(_currentGroup);
|
||||
_nowSelectIndex = -1;
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(_currentTab)) return;
|
||||
var options = Settings.Instance.GetOptionsByTab(_currentTab);
|
||||
Dictionary<string, List<OptionBase>> groupOptions = new Dictionary<string, List<OptionBase>>();
|
||||
@@ -82,8 +83,8 @@ namespace NBF
|
||||
_canSelectIndex.Clear();
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
|
||||
|
||||
|
||||
|
||||
var url = UIPackage.GetItemURL(UIPackName, "SettingSubTitleItem");
|
||||
foreach (var key in groupOptions.Keys)
|
||||
{
|
||||
@@ -99,7 +100,7 @@ namespace NBF
|
||||
{
|
||||
if (List.AddItemFromPool(SettingInputItem.URL) is SettingInputItem item)
|
||||
{
|
||||
item.SetData(option);
|
||||
item.SetData(option as InputOption);
|
||||
var index = List.GetChildIndex(item);
|
||||
_canSelectIndex.Add(index);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ namespace NBF
|
||||
private void OnApplySettings()
|
||||
{
|
||||
var options = Settings.Instance.GetOptionsByTab(_currentTab);
|
||||
|
||||
Log.Info("OnApplySettings");
|
||||
foreach (var option in options)
|
||||
{
|
||||
option.Apply();
|
||||
@@ -140,6 +141,8 @@ namespace NBF
|
||||
{
|
||||
option.Reset();
|
||||
}
|
||||
|
||||
ResetSettingList();
|
||||
}
|
||||
|
||||
private void OnUICanceled(string action)
|
||||
@@ -174,6 +177,13 @@ namespace NBF
|
||||
{
|
||||
OnApplySettings();
|
||||
}
|
||||
else if (action == InputDef.UI.Reset)
|
||||
{
|
||||
MessageBox.Show("是否重置为默认?", (ret) =>
|
||||
{
|
||||
if (ret) OnResetSettings();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user