快捷键重构
This commit is contained in:
79
Assets/Scripts/UI/Common/Menu/BottomMenu.cs
Normal file
79
Assets/Scripts/UI/Common/Menu/BottomMenu.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class BottomMenu : GComponent
|
||||
{
|
||||
public event Action OnBack;
|
||||
public event Action OnEnter;
|
||||
public event Action OnTab;
|
||||
public event Action OnUse;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
List.onClickItem.Add(OnClickItem);
|
||||
}
|
||||
|
||||
private void OnClickItem(EventContext context)
|
||||
{
|
||||
var item = context.data as BtnTitleInputControl;
|
||||
if (item == null) return;
|
||||
item.OnAction?.Invoke();
|
||||
}
|
||||
|
||||
public void UnUse()
|
||||
{
|
||||
OnBack = null;
|
||||
OnEnter = null;
|
||||
OnTab = null;
|
||||
OnUse = null;
|
||||
|
||||
InputManager.OnUICanceled -= OnAction;
|
||||
}
|
||||
|
||||
public void Use()
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (action != null)
|
||||
{
|
||||
if (List.AddItemFromPool() is BtnTitleInputControl item)
|
||||
{
|
||||
item.OnAction = action;
|
||||
item.ActionName = actionName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnAction(string action)
|
||||
{
|
||||
var children = List.GetChildren();
|
||||
foreach (var child in children)
|
||||
{
|
||||
if (child is BtnTitleInputControl item)
|
||||
{
|
||||
if (action == item.ActionName)
|
||||
{
|
||||
item.OnAction?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user