From 55f49e1af7756a861ea6cb1515eb1d83c524d065 Mon Sep 17 00:00:00 2001 From: bob <605277374@qq.com> Date: Wed, 4 Jun 2025 12:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/Common/Attrobites/Attributes.cs | 6 +-- .../Common/Services/Input/InputManager.cs | 6 +++ .../UI/Common/Button/BtnTitleInputControl.cs | 10 ++++- Assets/Scripts/UI/Common/Menu/BottomMenu.cs | 38 +++++++++---------- Assets/Scripts/UI/Common/Panel/MessageBox.cs | 22 +++++++++++ Assets/Scripts/UI/Home/Pages/HomeMainPage.cs | 6 ++- .../Utils/Extends/UIInputExtensions.cs | 30 ++++++++++++++- .../assets/Common/Com/Menu/BottomMenu.xml | 4 +- 8 files changed, 90 insertions(+), 32 deletions(-) diff --git a/Assets/Scripts/Common/Attrobites/Attributes.cs b/Assets/Scripts/Common/Attrobites/Attributes.cs index ed5a94c6a..b512318ca 100644 --- a/Assets/Scripts/Common/Attrobites/Attributes.cs +++ b/Assets/Scripts/Common/Attrobites/Attributes.cs @@ -57,9 +57,5 @@ namespace NBF Sort = sort; } } - - [AttributeUsage(AttributeTargets.Field)] - public class UIInputAttribute : BaseAttribute - { - } + } \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Input/InputManager.cs b/Assets/Scripts/Common/Services/Input/InputManager.cs index f9409e88f..0805fe885 100644 --- a/Assets/Scripts/Common/Services/Input/InputManager.cs +++ b/Assets/Scripts/Common/Services/Input/InputManager.cs @@ -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); + } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Common/Button/BtnTitleInputControl.cs b/Assets/Scripts/UI/Common/Button/BtnTitleInputControl.cs index abb81e718..4200bb0ff 100644 --- a/Assets/Scripts/UI/Common/Button/BtnTitleInputControl.cs +++ b/Assets/Scripts/UI/Common/Button/BtnTitleInputControl.cs @@ -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; + } } } \ No newline at end of file diff --git a/Assets/Scripts/UI/Common/Menu/BottomMenu.cs b/Assets/Scripts/UI/Common/Menu/BottomMenu.cs index ffcfc030a..53551ecfa 100644 --- a/Assets/Scripts/UI/Common/Menu/BottomMenu.cs +++ b/Assets/Scripts/UI/Common/Menu/BottomMenu.cs @@ -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); } } } diff --git a/Assets/Scripts/UI/Common/Panel/MessageBox.cs b/Assets/Scripts/UI/Common/Panel/MessageBox.cs index 4c3847dc5..f94cb3591 100644 --- a/Assets/Scripts/UI/Common/Panel/MessageBox.cs +++ b/Assets/Scripts/UI/Common/Panel/MessageBox.cs @@ -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); diff --git a/Assets/Scripts/UI/Home/Pages/HomeMainPage.cs b/Assets/Scripts/UI/Home/Pages/HomeMainPage.cs index c7994cbf0..7e3c80f1d 100644 --- a/Assets/Scripts/UI/Home/Pages/HomeMainPage.cs +++ b/Assets/Scripts/UI/Home/Pages/HomeMainPage.cs @@ -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); } } } \ No newline at end of file diff --git a/Assets/Scripts/Utils/Extends/UIInputExtensions.cs b/Assets/Scripts/Utils/Extends/UIInputExtensions.cs index 704bd423a..6bce6fc99 100644 --- a/Assets/Scripts/Utils/Extends/UIInputExtensions.cs +++ b/Assets/Scripts/Utils/Extends/UIInputExtensions.cs @@ -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); + } + } } } \ No newline at end of file diff --git a/FGUIProject/assets/Common/Com/Menu/BottomMenu.xml b/FGUIProject/assets/Common/Com/Menu/BottomMenu.xml index c2dfb9e36..388a3954e 100644 --- a/FGUIProject/assets/Common/Com/Menu/BottomMenu.xml +++ b/FGUIProject/assets/Common/Com/Menu/BottomMenu.xml @@ -3,8 +3,8 @@ - - + +