# FDiscreteMeta ## 基本信息 - **类型**: USTRUCT(BlueprintType) - **父类**: (none) - **源文件**: Plugins/CharacterControl/Source/CharacterControl/Public/CommandEndpoint.h - **模块**: CharacterControl ## 功能概述 Routing metadata for discrete (one-shot) commands. Contains CommandTags (FGameplayTagContainer, semantic IDs for endpoint matching) and bIsAll (bool, match mode: ALL tags must match vs ANY tag). ## 设计用意 Bridges raw input events to tag-based subscription model. Defines matching semantics. TInstancedStruct in FCommandPacket allows this to be subclassed for specialized routing logic. ## 职责范围 Defines subscription matching rules for one discrete command. Used by UCommandRouter::IsEndpointMatched for endpoint filtering. ## 项目内依赖 | 依赖项 | 关系 | 源文件 | |--------|------|--------| | (none) | | | ## 对外接口 FDiscreteMeta 定义离散命令的订阅匹配规则。作为 TInstancedStruct 嵌入在 FCommandPacket::DiscretePayload 和 FInputCommand::DiscreteCommandMeta 中。所有字段为 BlueprintReadWrite。 - **CommandTags** (FGameplayTagContainer, BlueprintReadWrite): 离散命令携带的语义标签集合,路由时与端点 InterestedTags 进行匹配 - **bIsAll** (bool, BlueprintReadWrite): 匹配模式开关。true = ALL 模式(端点必须包含所有 CommandTags),false = ANY 模式(端点包含任意一个即可) 调用者在 UInputCommandData 资产中配置每个 FInputCommand 的 DiscreteCommandMeta。运行时由 UCommandRouter::IsEndpointMatched 读取并执行匹配逻辑。因为有 TInstancedStruct 支持,可子类化 FDiscreteMeta 添加自定义路由字段。 ## 使用方法 FDiscreteMeta 在 InputCommandData 资产中配置,运行时由路由器使用: - **配置定义**: `Plugins/CharacterControl/Source/CharacterControl/Public/InputCommandData.h:24` -- FInputCommand::DiscreteCommandMeta 字段类型为 `TInstancedStruct` - **包构建**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandInputComponent.cpp:76-78` -- 离散命令时 DiscretePayload 直接取用 Command.DiscreteCommandMeta - **提取验证**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:221-249` -- ExtractDiscreteMeta 验证 bIsContinuous、有效性、类型兼容性后提取 - **匹配判断**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:301-327` -- IsEndpointMatched 根据 bIsAll 使用 HasAll 或 HasAny 匹配 ## 用例 - **ALL 模式匹配**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:308-318` -- 当 bIsAll 为 true 时,端点必须用 HasAll 完全包含命令的所有 CommandTags 才会被投递 - **ANY 模式匹配**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:322-323` -- 当 bIsAll 为 false 时,端点 InterestedTags 中包含任意一个 CommandTags 即命中 - **类型兼容性检查**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:240-245` -- ExtractDiscreteMeta 运行时检查 DiscretePayload 的 ScriptStruct 是否为 FDiscreteMeta 的子类,确保 TInstancedStruct 扩展安全 - **空命令防护**: `Plugins/CharacterControl/Source/CharacterControl/Private/CommandRouter.cpp:311-315` -- CommandTags 为空时不匹配任何端点,避免无标签命令广播给所有端点