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

57 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# IPresentationStrategyPlugin
## 基本信息
- **类型**: UINTERFACE + C++ 接口
- **父类**: UInterface
- **源文件**: Plugins/Dialog/Source/Dialog/Public/PresentationStrategyPlugin.h
- **模块**: Dialog
## 功能概述
用于处理对话表现命令的策略接口。单一方法 PerformCommand 接收 FDialogPresentationScriptCommand返回 booltrue 表示已处理。BlueprintNativeEvent支持蓝图实现。
## 设计用意
策略模式,支持多个独立的对话表现插件。一个策略处理 "SetSpeaker",另一个处理 "PlayAnimation"。布尔返回值支持回退路由。可扩展——新的表现能力只需添加新策略,无需修改核心代码。
## 职责范围
处理特定命名命令。按名称注册到 IPresentationScriptExecutor 中。不管理策略注册表,也不编排执行流程。
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| FDialogPresentationScriptCommand | 参数类型 | Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h |
## 对外接口
UInterface / C++ 接口,供蓝图或 C++ 类实现,用于处理特定命名类别的对话脚本命令。
单一方法:
- **PerformCommand** (BlueprintNativeEvent, BlueprintCallable): 接收 `const FDialogPresentationScriptCommand& InCommand`,返回 `bool`
- 返回 `true` 表示该策略识别并成功处理了此命令。
- 返回 `false` 表示未处理(可用于回退路由链)。
设计模式:策略模式。每个策略实现负责一个命令名称空间(如 "SetSpeaker"、"PlayAnimation")。策略通过 `IPresentationScriptExecutor::PlugStrategyIn` 按名称注册到执行器。执行器根据 `CommandName` 将命令路由到对应策略。
注意:策略自身不管理注册,不决定何时被调用。注册和调度由实现 `IPresentationScriptExecutor` 的类负责。
## 使用方法
在 C++ 或蓝图中实现此接口。蓝图中可 override `PerformCommand` 事件:
1. 检查 `InCommand.CommandName` 是否为自己能处理的命令。
2. 读取 `InCommand.Params`,按 Type 字段分发读取正确的值。
3. 执行相应的游戏逻辑(设置角色、播放动画等)。
4. 返回 `true` 表示已处理,或 `false` 表示不处理。
策略类通过执行器的 `PlugStrategyIn(StrategyName, StrategyObject)` 注册自身:
```cpp
// Plugins/Dialog/Source/Dialog/Public/PresentationScriptExecutor.h:28
void PlugStrategyIn(FName StrategyName, const TScriptInterface<class IPresentationStrategyPlugin>& NewStrategy);
```
## 用例
| 文件 | 行号 | 用途 |
|------|------|------|
| Plugins/Dialog/Source/Dialog/Public/PresentationStrategyPlugin.h | 19-27 | 接口定义UInterface 包装类 + C++ 接口类含 PerformCommand 声明 |
| Plugins/Dialog/Source/Dialog/Public/PresentationScriptExecutor.h | 28 | IPresentationScriptExecutor::PlugStrategyIn 以此接口的 TScriptInterface 为参数 |
| Document/Content/Blueprints/WBP_TestUI.md | 10 | WBP_TestUI 实现 IPresentationScriptExecutor负责将命令分发给对应的策略插件 |
注:`PerformCommand` 在 Dialog 插件源码中仅有声明PresentationStrategyPlugin.h:26无 C++ 调用实现;调用发生在实现 `IPresentationScriptExecutor` 的蓝图/运行时中。搜索 `PerformCommand` 仅匹配到接口声明行。