mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
refactor(input): 重构Godot输入模块为抽象基类并优化输入处理流程 将 `GodotInputModule` 重命名为 `AbstractGodotInputModule` 并改为抽象类, 以便支持更灵活的输入翻译器注册机制。引入 `GodotInputPhase` 枚举和 `GodotRawInput` 结构体以区分输入处理的不同阶段(捕获与冒泡)。 同时修改 `GodotInputTranslator` 仅在Bubble阶段生成游戏事件,提升输入处理精度。 ```
42 lines
1018 B
C#
42 lines
1018 B
C#
using GFramework.Game.input;
|
||
using Godot;
|
||
|
||
namespace GFramework.Godot.input;
|
||
|
||
/// <summary>
|
||
/// Godot输入桥接类,用于将Godot的输入事件转换为游戏框架的输入事件
|
||
/// </summary>
|
||
public partial class GodotInputBridge : Node
|
||
{
|
||
private InputSystem _inputSystem = null!;
|
||
|
||
/// <summary>
|
||
/// 绑定输入系统
|
||
/// </summary>
|
||
/// <param name="inputSystem">要绑定的输入系统实例</param>
|
||
public void Bind(InputSystem inputSystem)
|
||
{
|
||
_inputSystem = inputSystem;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 捕获阶段:最早
|
||
/// </summary>
|
||
public override void _Input(InputEvent @event)
|
||
{
|
||
_inputSystem.HandleRaw(
|
||
new GodotRawInput(@event, GodotInputPhase.Capture)
|
||
);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 冒泡阶段:UI 未处理
|
||
/// </summary>
|
||
public override void _UnhandledInput(InputEvent @event)
|
||
{
|
||
_inputSystem.HandleRaw(
|
||
new GodotRawInput(@event, GodotInputPhase.Bubble)
|
||
);
|
||
}
|
||
}
|