3.2 KiB
3.2 KiB
FDialogPresentationScriptData
基本信息
- 类型: USTRUCT(BlueprintType)
- 父类: FTableRowBase
- 源文件: Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h
- 模块: Dialog
功能概述
DataTable 行结构体,用于存储单个对话脚本条目。包含 Choices(JSON 数组,存储选项标识符)、PresentationScript(JSON 数组,存储命令序列)、Comment(设计者注释)和 ScriptID(运行时填充的标识符)。命令以 JSON 编码的 [CommandName, param1, param2, ...] 数组形式存储。
设计用意
将对话数据与执行逻辑解耦。JSON 格式使数据紧凑、便于外部工具编辑,且支持任意长度的参数列表而无需修改结构体定义。继承 FTableRowBase 使其能够存储在 UDataTable 中。
职责范围
单个对话节点的脚本数据容器。ScriptID 由 UDialogPresentationSubsystem 在查找时注入。结构体自身不解析或执行其 JSON 数据(解析工作由 UPresentationJsonLibrary 负责)。
项目内依赖
| 依赖项 | 关系 | 源文件 |
|---|---|---|
| (无项目内依赖) |
对外接口
作为 DataTable 行结构体,供外部代码通过 UDataTable::FindRow<FDialogPresentationScriptData>() 读取。
关键字段:
- Choices (FString): JSON 数组字符串,存储对话选项的标识符名称列表,如
["Choice_A","Choice_B"]。 - PresentationScript (FString): JSON 命令数组字符串,每个命令为
[CommandName, param1, param2, ...]格式的 JSON 数组。 - Comment (FText): 设计者注释,可通过
UPresentationJsonLibrary::GetPresentationScriptComment读取。 - ScriptID (FName): 运行时由
UDialogPresentationSubsystem::GetDialogPresentationScriptData自动填充,值为传入的行查找键名 (StructID)。
外部代码不应直接解析 Choices 和 PresentationScript 的 JSON 字符串,而应通过 UPresentationJsonLibrary 的静态方法(如 GetPresentationScriptChoicesNum、GetPresentationScriptCommandName 等)来访问其中数据。
使用方法
在 C++ 中通过子系统查找行数据:
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationSubsystem.cpp:30
FDialogPresentationScriptData* ScriptData = Table->FindRow<FDialogPresentationScriptData>(StructID, TEXT("DialogPresentationSubsystem"));
在编辑器工具中构造行数据并写入 DataTable:
// Plugins/Dialog/Source/DialogEditor/Private/DialogGraphDataAsset.cpp:481-487
FDialogPresentationScriptData RowData;
FName RowName = DialogNode->NodeID;
RowData.Choices = Result;
RowData.Comment = CommentText;
RowData.PresentationScript = ScriptString;
NewTable->AddRow(RowName, RowData);
用例
| 文件 | 行号 | 用途 |
|---|---|---|
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationSubsystem.cpp | 30 | 从已注册的 DataTable 中按 StructID 查找并返回脚本行数据 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 6,11,24,50,63,98,201,246 | UPresentationJsonLibrary 解析 Choices/PresentationScript JSON 字段 |
| Plugins/Dialog/Source/DialogEditor/Private/DialogGraphDataAsset.cpp | 481-487,489 | 编辑器从对话图节点导出 DataTable 时构造行数据 |