69 lines
3.6 KiB
Markdown
69 lines
3.6 KiB
Markdown
# FDialogPresentationScriptCommand
|
||
|
||
## 基本信息
|
||
- **类型**: USTRUCT(BlueprintType)
|
||
- **父类**: (无)
|
||
- **源文件**: Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h
|
||
- **模块**: Dialog
|
||
|
||
## 功能概述
|
||
对话表现脚本中的单条可执行命令。包含 CommandName(例如 "SetSpeaker"、"PlayAnimation")和一个有序的 FDialogPresentationScriptParam 数组。CommandName 作为策略路由的分发键。
|
||
|
||
## 设计用意
|
||
命令抽象,用于策略模式的分发。CommandName 是路由键——每个 IPresentationStrategyPlugin 检查自己是否能处理该名称。Params 数组是通用的;每个策略知道自己期望的参数格式。将数据(做什么)与执行器(怎么做)分离。
|
||
|
||
## 职责范围
|
||
单条命令的数据容器。传递给 IPresentationStrategyPlugin::PerformCommand。自身不执行命令。
|
||
|
||
## 项目内依赖
|
||
| 依赖项 | 关系 | 源文件 |
|
||
|--------|------|--------|
|
||
| FDialogPresentationScriptParam | 包含(TArray成员) | Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h |
|
||
|
||
## 对外接口
|
||
BlueprintType 结构体,代表对话脚本中的单条可执行命令。外部代码(策略插件)通过 `IPresentationStrategyPlugin::PerformCommand` 接口接收此结构体。
|
||
|
||
关键字段:
|
||
- **CommandName** (FName): 命令名称,作为策略路由的分发键。IPresentationScriptExecutor 根据此名称将命令分发给对应的 IPresentationStrategyPlugin。
|
||
- **Params** (TArray<FDialogPresentationScriptParam>): 命令参数数组。各策略插件知道如何解释自身命令的参数格式和类型。
|
||
|
||
典型流程:
|
||
1. `UPresentationJsonLibrary` 从 `FDialogPresentationScriptData::PresentationScript` JSON 中解析出命令数组。
|
||
2. 执行器遍历命令,根据 `CommandName` 找到对应策略。
|
||
3. 策略插件的 `PerformCommand` 接收该命令,按 Type 逐个解析 Params 中的参数。
|
||
|
||
## 使用方法
|
||
在编辑器对话图节点中编辑命令:
|
||
```cpp
|
||
// Plugins/Dialog/Source/DialogEditor/Public/DialogGraphNode.h:31
|
||
TArray<FDialogPresentationScriptCommand> PresentationScriptCommands;
|
||
```
|
||
|
||
在编辑器中通过 UPresentationJsonLibrary 将命令数组序列化为 JSON:
|
||
```cpp
|
||
// Plugins/Dialog/Source/DialogEditor/Private/DialogGraphDataAsset.cpp:478
|
||
auto ScriptString = UPresentationJsonLibrary::PresentationScriptToJson(DialogNode->PresentationScriptCommands);
|
||
```
|
||
|
||
在 UPresentationJsonLibrary 内部将命令序列化为 JSON:
|
||
```cpp
|
||
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp:392-402
|
||
FString Result = TEXT("[");
|
||
Result += FString::Printf(TEXT("\"%s\""), *Command.CommandName.ToString());
|
||
for (const FDialogPresentationScriptParam& Param : Command.Params)
|
||
{
|
||
Result += TEXT(",") + ParamToJson(Param);
|
||
}
|
||
Result += TEXT("]");
|
||
```
|
||
|
||
## 用例
|
||
| 文件 | 行号 | 用途 |
|
||
|------|------|------|
|
||
| Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h | 88-98 | 结构体定义 |
|
||
| Plugins/Dialog/Source/DialogEditor/Public/DialogGraphNode.h | 31 | 编辑器对话图节点中存储可编辑的命令列表 |
|
||
| Plugins/Dialog/Source/DialogEditor/Private/DialogGraphDataAsset.cpp | 478 | 编辑器导出时将节点命令序列化为 JSON |
|
||
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 279-290 | PresentationScriptToJson 遍历命令数组并序列化 |
|
||
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 392-402 | CommandToJson 将单条命令序列化为 JSON |
|
||
| Plugins/Dialog/Source/Dialog/Public/PresentationStrategyPlugin.h | 26 | IPresentationStrategyPlugin::PerformCommand 接收此类型参数 |
|