快捷键操作

This commit is contained in:
bob
2025-06-04 12:55:36 +08:00
parent 30836558ae
commit 55f49e1af7
8 changed files with 90 additions and 32 deletions

View File

@@ -57,9 +57,5 @@ namespace NBF
Sort = sort;
}
}
[AttributeUsage(AttributeTargets.Field)]
public class UIInputAttribute : BaseAttribute
{
}
}

View File

@@ -202,5 +202,11 @@ namespace NBF
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
OnInteractiveObjectAction?.Invoke(interactiveObject);
}
public void SendUIInput(string actionName)
{
OnUIPerformed?.Invoke(actionName);
OnUICanceled?.Invoke(actionName);
}
}
}

View File

@@ -9,11 +9,17 @@ namespace NBF
{
public partial class BtnTitleInputControl : GButton
{
public Action OnAction;
public string ActionName;
public string ShowName;
private void OnInited()
{
}
public void SetData(string actionName, string showName)
{
this.ActionName = actionName;
this.ShowName = showName;
}
}
}

View File

@@ -20,7 +20,8 @@ namespace NBF
{
var item = context.data as BtnTitleInputControl;
if (item == null) return;
item.OnAction?.Invoke();
InputManager.Instance.SendUIInput(item.ActionName);
Debug.Log("模拟点击===");
}
public void Use(IUIPanel panel)
@@ -29,38 +30,37 @@ namespace NBF
List.RemoveChildrenToPool();
LeftList.RemoveChildrenToPool();
InputManager.OnUICanceled += OnAction;
// AddButtonItem(OnUse, "");
// AddButtonItem(OnTab, InputDef.UI.Tab);
// AddButtonItem(OnEnter, InputDef.UI.Enter);
// AddButtonItem(OnBack, InputDef.UI.Back);
}
private void AddButtonItem(Action action, string actionName)
public void AddRightButton(string inputName, string showName = "")
{
if (action != null)
AddButton(inputName, string.Empty, true);
}
public void AddLeftButton(string inputName, string showName = "")
{
AddButton(inputName, string.Empty, false);
}
public void AddButton(string inputName, string showName = "", bool isRight = true)
{
if (isRight)
{
if (List.AddItemFromPool() is BtnTitleInputControl item)
{
item.OnAction = action;
item.ActionName = actionName;
item.SetData(inputName, showName);
}
}
}
private void OnAction(string action)
{
if (_panel == null || !_panel.IsShowing || !_panel.IsTop) return;
var children = List.GetChildren();
foreach (var child in children)
else
{
if (child is BtnTitleInputControl item)
if (LeftList.AddItemFromPool() is BtnTitleInputControl item)
{
if (action == item.ActionName)
{
item.OnAction?.Invoke();
}
item.SetData(inputName, showName);
}
}
}

View File

@@ -54,6 +54,7 @@ namespace NBF
HideAnim = UIPanelAnimation.GetCenterScaleBig(this, true);
IsModal = true;
IsDontBack = true;
InputManager.OnUICanceled += OnUICanceled;
}
protected override void OnShow()
@@ -65,6 +66,27 @@ namespace NBF
MessageStyle.selectedIndex = _style;
}
private void OnUICanceled(string action)
{
if (!IsShowing) return;
if (!IsTop) return;
if (action == InputDef.UI.Enter)
{
OnClick(BtnConfirm);
}
else if (action == InputDef.UI.Back)
{
OnClick(BtnCancel);
}
}
protected override void OnDestroy()
{
base.OnDestroy();
InputManager.OnUICanceled -= OnUICanceled;
}
private void OnClick(GComponent btn)
{
_callback?.Invoke(btn == BtnConfirm);

View File

@@ -2,8 +2,6 @@
using System.Collections.Generic;
using FairyGUI;
using NBC;
using UnityEngine;
namespace NBF
{
@@ -26,6 +24,7 @@ namespace NBF
buttons.Add(BtnTest);
navigate = new ButtonNavigate(buttons);
this.AutoListenInput();
}
protected override void OnShow()
@@ -74,6 +73,9 @@ namespace NBF
private void UseBottomMenu()
{
BottomMenu.Use(Panel);
BottomMenu.AddRightButton(InputDef.UI.Enter);
BottomMenu.AddRightButton(InputDef.UI.Back);
}
}
}

View File

@@ -1,7 +1,33 @@
namespace NBF
using System;
using FairyGUI;
using NBC;
using UIPanel = NBC.UIPanel;
namespace NBF
{
[AttributeUsage(AttributeTargets.Method)]
public class UIInputListenAttribute : BaseAttribute
{
}
public static class UIInputExtensions
{
public static void AutoListenInput(this GComponent panel)
{
var ms = Reflection.GetMethodsWithUIInputAttribute(panel.GetType(), typeof(UIInputListenAttribute));
foreach (var method in ms)
{
Log.Error(method.Name);
}
}
public static void AutoListenInput(this UIPanel panel)
{
var ms = Reflection.GetMethodsWithUIInputAttribute(panel.GetType(), typeof(UIInputListenAttribute));
foreach (var method in ms)
{
Log.Error(method.Name);
}
}
}
}

View File

@@ -3,8 +3,8 @@
<displayList>
<list id="n33_9lmc" name="List" xy="980,8" size="891,40" layout="row" colGap="32" defaultItem="ui://6hgkvlaur03uj0" align="right" vAlign="middle" autoClearItems="true">
<relation target="" sidePair="right-right,top-top"/>
<item/>
<item/>
<item title="按钮1"/>
<item title="按钮2"/>
<item/>
<item/>
</list>