快捷键操作
This commit is contained in:
@@ -58,8 +58,4 @@ namespace NBF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field)]
|
|
||||||
public class UIInputAttribute : BaseAttribute
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -202,5 +202,11 @@ namespace NBF
|
|||||||
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
|
Debug.LogError($"OnInteractiveObject {interactiveObject != null}");
|
||||||
OnInteractiveObjectAction?.Invoke(interactiveObject);
|
OnInteractiveObjectAction?.Invoke(interactiveObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendUIInput(string actionName)
|
||||||
|
{
|
||||||
|
OnUIPerformed?.Invoke(actionName);
|
||||||
|
OnUICanceled?.Invoke(actionName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,11 +9,17 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
public partial class BtnTitleInputControl : GButton
|
public partial class BtnTitleInputControl : GButton
|
||||||
{
|
{
|
||||||
public Action OnAction;
|
|
||||||
public string ActionName;
|
public string ActionName;
|
||||||
|
public string ShowName;
|
||||||
|
|
||||||
private void OnInited()
|
private void OnInited()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetData(string actionName, string showName)
|
||||||
|
{
|
||||||
|
this.ActionName = actionName;
|
||||||
|
this.ShowName = showName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,8 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
var item = context.data as BtnTitleInputControl;
|
var item = context.data as BtnTitleInputControl;
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
item.OnAction?.Invoke();
|
InputManager.Instance.SendUIInput(item.ActionName);
|
||||||
|
Debug.Log("模拟点击===");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Use(IUIPanel panel)
|
public void Use(IUIPanel panel)
|
||||||
@@ -29,38 +30,37 @@ namespace NBF
|
|||||||
List.RemoveChildrenToPool();
|
List.RemoveChildrenToPool();
|
||||||
LeftList.RemoveChildrenToPool();
|
LeftList.RemoveChildrenToPool();
|
||||||
|
|
||||||
InputManager.OnUICanceled += OnAction;
|
|
||||||
|
|
||||||
// AddButtonItem(OnUse, "");
|
// AddButtonItem(OnUse, "");
|
||||||
// AddButtonItem(OnTab, InputDef.UI.Tab);
|
// AddButtonItem(OnTab, InputDef.UI.Tab);
|
||||||
// AddButtonItem(OnEnter, InputDef.UI.Enter);
|
// AddButtonItem(OnEnter, InputDef.UI.Enter);
|
||||||
// AddButtonItem(OnBack, InputDef.UI.Back);
|
// 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)
|
if (List.AddItemFromPool() is BtnTitleInputControl item)
|
||||||
{
|
{
|
||||||
item.OnAction = action;
|
item.SetData(inputName, showName);
|
||||||
item.ActionName = actionName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
private void OnAction(string action)
|
|
||||||
{
|
|
||||||
if (_panel == null || !_panel.IsShowing || !_panel.IsTop) return;
|
|
||||||
var children = List.GetChildren();
|
|
||||||
foreach (var child in children)
|
|
||||||
{
|
{
|
||||||
if (child is BtnTitleInputControl item)
|
if (LeftList.AddItemFromPool() is BtnTitleInputControl item)
|
||||||
{
|
{
|
||||||
if (action == item.ActionName)
|
item.SetData(inputName, showName);
|
||||||
{
|
|
||||||
item.OnAction?.Invoke();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ namespace NBF
|
|||||||
HideAnim = UIPanelAnimation.GetCenterScaleBig(this, true);
|
HideAnim = UIPanelAnimation.GetCenterScaleBig(this, true);
|
||||||
IsModal = true;
|
IsModal = true;
|
||||||
IsDontBack = true;
|
IsDontBack = true;
|
||||||
|
InputManager.OnUICanceled += OnUICanceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnShow()
|
protected override void OnShow()
|
||||||
@@ -65,6 +66,27 @@ namespace NBF
|
|||||||
MessageStyle.selectedIndex = _style;
|
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)
|
private void OnClick(GComponent btn)
|
||||||
{
|
{
|
||||||
_callback?.Invoke(btn == BtnConfirm);
|
_callback?.Invoke(btn == BtnConfirm);
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using FairyGUI;
|
using FairyGUI;
|
||||||
using NBC;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace NBF
|
namespace NBF
|
||||||
{
|
{
|
||||||
@@ -26,6 +24,7 @@ namespace NBF
|
|||||||
buttons.Add(BtnTest);
|
buttons.Add(BtnTest);
|
||||||
|
|
||||||
navigate = new ButtonNavigate(buttons);
|
navigate = new ButtonNavigate(buttons);
|
||||||
|
this.AutoListenInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnShow()
|
protected override void OnShow()
|
||||||
@@ -74,6 +73,9 @@ namespace NBF
|
|||||||
private void UseBottomMenu()
|
private void UseBottomMenu()
|
||||||
{
|
{
|
||||||
BottomMenu.Use(Panel);
|
BottomMenu.Use(Panel);
|
||||||
|
|
||||||
|
BottomMenu.AddRightButton(InputDef.UI.Enter);
|
||||||
|
BottomMenu.AddRightButton(InputDef.UI.Back);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,8 @@
|
|||||||
<displayList>
|
<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">
|
<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"/>
|
<relation target="" sidePair="right-right,top-top"/>
|
||||||
<item/>
|
<item title="按钮1"/>
|
||||||
<item/>
|
<item title="按钮2"/>
|
||||||
<item/>
|
<item/>
|
||||||
<item/>
|
<item/>
|
||||||
</list>
|
</list>
|
||||||
|
|||||||
Reference in New Issue
Block a user