Files
loneseDocument/Plugins/CharacterControl/UEndpointDispatcher.md
meishibiezb 29a3f77908 init
2026-06-04 21:44:13 +08:00

4.0 KiB
Raw Blame History

UEndpointDispatcher

基本信息

  • 类型: UCLASS(BlueprintType)
  • 父类: UObject
  • 源文件: Plugins/CharacterControl/Source/CharacterControl/Public/CommandEndpoint.h
  • 模块: CharacterControl

功能概述

Bridge object exposing endpoint delegates to Blueprint. Holds OnStateChanged and OnCommandOutput delegates, plus CurrentState. Provides NotifyStateChanged/OutputCommand wrapper UFUNCTIONs for Blueprint callers.

设计用意

Glue between C++ delegates and Blueprint VM. Blueprint endpoint implementations return this via GetEndpointDispatcher_BP. The ICommandEndpoint default C++ implementations all route through this dispatcher.

职责范围

Delegate bridge for Blueprint endpoints. Broadcasts state changes and command output to C++ observers. Does NOT implement endpoint logic.

项目内依赖

依赖项 关系 源文件
(none)

对外接口

UEndpointDispatcher 是蓝图端点与 C++ 委托系统之间的桥接对象。它暴露委托引用供 C++ 直接访问,同时提供 UFUNCTION 包装供蓝图调用。

  • OnStateChanged (FOnEndpointStateChanged, public field): C++ 直接访问的委托。当端点状态变更时广播。被 UCommandRouter 通过 BindDynamic 订阅以触发聚合更新
  • OnCommandOutput (FOnCommandOutput, public field): C++ 直接访问的委托。当端点输出命令时广播。被 UCommandRouter 订阅以转发端点产出的命令
  • CurrentState (FEndpointState, EditAnywhere, BlueprintReadWrite): 端点当前状态的副本ICommandEndpoint::GetEndpointState 默认实现返回此字段
  • NotifyStateChanged (UFUNCTION, BlueprintCallable): 蓝图广播入口,调用后执行 OnStateChanged.ExecuteIfBound(NewState)C++ 订阅者收到通知
  • OutputCommand (UFUNCTION, BlueprintCallable): 蓝图广播入口,调用后执行 OnCommandOutput.ExecuteIfBound(Command),将命令推送到路由系统

蓝图端点实现 ICommandEndpoint 时,需重写 GetEndpointDispatcher_BP 返回调度器实例。ICommandEndpoint 的 C++ 默认实现全部通过此调度器工作。

使用方法

UEndpointDispatcher 是 ICommandEndpoint 蓝图实现的内部机制:

  • C++ 默认桥接: Plugins/CharacterControl/Source/CharacterControl/Private/CommandEndpoint.cpp:8-26 -- ICommandEndpoint 的四个纯虚函数默认实现全部通过 GetEndpointDispatcher_BP 获取调度器后委托执行
  • GetEndpointState 默认实现: Plugins/CharacterControl/Source/CharacterControl/Private/CommandEndpoint.cpp:10 -- 返回 Execute_GetEndpointDispatcher_BP(...)->CurrentState
  • ReceiveCommand 默认实现: Plugins/CharacterControl/Source/CharacterControl/Private/CommandEndpoint.cpp:25 -- 调用 Execute_ReceiveCommand_BP(..., Command)
  • GetStateChangedDelegate 默认实现: Plugins/CharacterControl/Source/CharacterControl/Private/CommandEndpoint.cpp:15 -- 返回调度器的 OnStateChanged 引用
  • NotifyStateChanged 内联: Plugins/CharacterControl/Source/CharacterControl/Public/CommandEndpoint.h:140-143 -- 函数体内直接 ExecuteIfBound
  • OutputCommand 内联: Plugins/CharacterControl/Source/CharacterControl/Public/CommandEndpoint.h:146-149 -- 函数体内直接 ExecuteIfBound

用例

  • 蓝图端点状态通知: 蓝图端点实现类调用 NotifyStateChanged调度器转发给所有绑定的 C++ 订阅者(如 UCommandRouter::OnRegisteredEndpointStateChanged触发标签聚合更新
  • 蓝图端点命令输出: 蓝图端点调用 OutputCommand 将命令包推入路由系统,调度器广播 OnCommandOutput由 UCommandRouter::OnRegisteredEndpointOutputCommand 接收处理
  • C++ 端点绕过调度器: Plugins/CharacterControl/Source/CharacterControl/Public/CommandRouter.h:22-25 -- UCommandRouter 作为 C++ 端点直接重写 GetEndpointState/ReceiveCommand 等方法,不使用调度器;Plugins/CharacterControl/Source/CharacterControl/Public/EndpointComponent.h:30-33 -- UEndpointComponent 同样直接重写