// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 using System; using UnityEngine; using FairyGUI; using NBC; using UIPanel = NBC.UIPanel; namespace NBF { public partial class BottomMenu : GComponent { private void OnInited() { List.onClickItem.Add(OnClickItem); // LeftList.onClickItem.Add(OnClickItem); InputManager.OnUIInvokeChange += OnUIInvokeChange; } public override void Dispose() { InputManager.OnUIInvokeChange -= OnUIInvokeChange; base.Dispose(); } private void OnClickItem(EventContext context) { var item = context.data as BtnTitleInputControl; if (item == null) return; InputManager.Instance.SendUIInput(item.ActionName); Debug.Log("模拟点击==="); } private void OnUIInvokeChange() { List.RemoveChildrenToPool(); // LeftList.RemoveChildrenToPool(); var invokes = InputManager.Instance.GetUsableInvokes(); foreach (var uiInputInvoke in invokes) { var invokeData = uiInputInvoke.InputInvoke; if (uiInputInvoke.InputInvoke.Mode == UIInputButtonShowMode.BottomLeft) { AddButton(invokeData.Name, invokeData.Key, false); } else if (uiInputInvoke.InputInvoke.Mode == UIInputButtonShowMode.BottomRight) { AddButton(invokeData.Name, invokeData.Key); } } } public void AddButton(string inputName, string showName = "", bool isRight = true) { if (List.AddItemFromPool() is BtnTitleInputControl item) { item.SetData(inputName, showName); } // if (isRight) // { // } // else // { // if (LeftList.AddItemFromPool() is BtnTitleInputControl item) // { // item.SetData(inputName, showName); // } // } } } }