输入绑定
输入绑定,通常指的是由外部硬件设备发起的事件,由程序捕获并进行响应的过程。
输入事件类型
IE_Pressed 按下事件
IE_Released 释放事件
IE_DoubleClick 双击事件
IE_Repeat 持续按下事件
绑定按键
IODevice& _device = IODeviceController::Instance()
.GetIODevice("Standard");
_device.BindKey(EKeys::A, IOToolkit::IE_Pressed, []() {
// 按键A被按下
});
_device.BindKey(EKeys::A, IOToolkit::IE_Released, []() {
// 按键A被释放
});
_device.BindKey(EKeys::A, IOToolkit::IE_DoubleClick, []() {
// 按键A双击事件
});
_device.BindKey(EKeys::A, IOToolkit::IE_Repeat, []() {
// 按键A持续按下事件
});
绑定输入动作
IODevice& _device = IODeviceController::Instance()
.GetIODevice("PCI2312A");
_device.BindAction("StartGame", IOToolkit::IE_Pressed, []() {
// 开始游戏逻辑
});
_device.BindAction("PlayVideo", IOToolkit::IE_Pressed, [](FKey InKey) {
if (InKey == EKeys::Button_10) {
// PlayVideo("video1.mp4");
}
else if (InKey == EKeys::Button_11) {
// PlayVideo("video2.mp4");
}
// ...
});
<IORoot>
<Device Name="Standard" Type="Standard" />
<Device Name="PCI2312A" Type="External" DllName="PCI2312A" Index="0">
<Action Name="StartGame">
<Key Name="Button_00"/>
<Key Name="S"/>
</Action>
<Action Name="PlayVideo">
<Key Name="Button_10"/>
<Key Name="Button_11"/>
</Action>
</Device>
</IORoot>
绑定输入动作(携带自定义参数)
class Application
{
public:
void RegisterEvents()
{
IODevice& _device = IODeviceController::Instance()
.GetIODevice("PCI2312A");
_device.BindAction("PlayVideo2", IOToolkit::IE_Pressed,
this, &Application::OnPlayVideo, "video1.mp4");
_device.BindAction("PlayVideo2", IOToolkit::IE_Pressed,
this, &Application::OnPlayVideo, "video2.mp4");
}
void OnPlayVideo(const char* videoName)
{
//PlayVideo(videoName);
}
}
<IORoot>
<Device Name="Standard" Type="Standard" />
<Device Name="PCI2312A" Type="External" DllName="PCI2312A" Index="0">
<Action Name="PlayVideo1">
<Key Name="Button_00"/>
<Key Name="Button_01"/>
<Key Name="Button_02"/>
<Key Name="Button_03"/>
<Key Name="Button_04"/>
</Action>
<Action Name="PlayVideo2">
<Key Name="Button_10"/>
<Key Name="Button_11"/>
<Key Name="Button_12"/>
<Key Name="Button_13"/>
<Key Name="Button_14"/>
</Action>
</Device>
</IORoot>
绑定轴键
IODeviceController::Instance()
.GetIODevice("Standard")
.BindAxisKey(EKeys::MouseX, [](float InDeltaX) {
// 处理鼠标移动时逻辑
});
绑定轴输入
IODeviceController::Instance()
.GetIODevice("Standard")
.BindAxis("MoveHorizontal", [](float InDeltaX) {
// player.transform.position += player.transform.left * InDeltaX;
});
IORoot>
<Device Name="Standard" Type="Standard">
<Axis Name="MoveHorizontal">
<Key Name="Left" Scale="-10"/>
<Key Name="Right" Scale="10"/>
</Axis>
</Device>
</IORoot>
最后更新于
这有帮助吗?