Unity UIItemDetailInfo 禁用键盘操作
如何在Unity中禁用UIItemDetailInfo的键盘操作
以下是一个拾取物品的UI,我需要在打开此UI时禁用键盘操作,请问该怎么修改?
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using Unity.VisualScripting;
using Sirenix.OdinInspector;
namespace QFramework.Escape
{
public class UIItemDetailInfoData : UIPanelData
{
public InventoryItemModel itemModel;
}
public partial class UIItemDetailInfo : UIPanel
{
[LabelText("物品code,优先级低于传参")]
public string DefaultItemCode;
protected override void OnInit(IUIData uiData = null)
{
if (DefaultItemCode != "" && ItemManage.Instance.itemConfig.confDic[DefaultItemCode] != null)
{
mData = new UIItemDetailInfoData()
{
itemModel = ItemManage.Instance.itemConfig.confDic[DefaultItemCode]
};
}
mData = uiData as UIItemDetailInfoData ?? mData;
// 点击关闭按钮关闭窗口
BtnClose.onClick.AddListener(() =>
{
this.CloseSelf();
});
BtnPick.onClick.AddListener(() =>
{
ItemManage.Instance.AddItem(mData.itemModel.code);
GameHandle.PopMsg("取得‘" + mData.itemModel.itemName + "’");
Player.Instance.AddActionPoint(-1);
this.CloseSelf();
});
}
protected override void OnOpen(IUIData uiData = null)
{
UIItemDetailInfoData data = (uiData as UIItemDetailInfoData);
if (data != null)
{
InventoryItemModel item = data.itemModel;
this.ItemName.text = item.itemName;
this.Desc.text = item.description;
if (item.detailImage != null)
{
this.Image.sprite = item.detailImage;
}
else if (item.icon != null)
{
this.Image.sprite = item.icon;
}
}
// 禁用键盘操作
InputManager.Instance.DisableKeyboardInput();
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
// 恢复键盘操作
InputManager.Instance.EnableKeyboardInput();
}
}
}
要禁用键盘操作,可以通过在UIItemDetailInfo类中添加以下代码来实现:
-
在
OnOpen方法中添加InputManager.Instance.DisableKeyboardInput()来禁用键盘操作。 -
在
OnClose方法中添加InputManager.Instance.EnableKeyboardInput()来恢复键盘操作。
请注意,在这个代码片段中,InputManager.Instance代表一个输入管理器的实例,你需要根据你的项目中的实际情况来使用正确的输入管理器。
希望以上解答对您有所帮助!
原文地址: http://www.cveoy.top/t/topic/phcR 著作权归作者所有。请勿转载和采集!