This commit is contained in:
meishibiezb
2026-06-04 21:37:53 +08:00
parent b0d2a0e2e7
commit 29a3f77908
63 changed files with 4068 additions and 1 deletions

View File

@@ -0,0 +1,63 @@
# FDialogPresentationScriptParam
## 基本信息
- **类型**: USTRUCT(BlueprintType)
- **父类**: (无)
- **源文件**: Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h
- **模块**: Dialog
## 功能概述
用于单个命令参数的带标签联合体值类型。包含一个 Type 枚举和多个值字段String、Numberfloat、Boolean、ArrayJSON 字符串、ObjectJSON 字符串)。显式构造函数初始化为 None/0.0/false。
## 设计用意
采用带标签的联合体模式来处理异构命令参数。使得单一灵活的命令系统成为可能,各策略根据类型解释参数。对蓝图可用。
## 职责范围
单个命令参数的值容器。消费者通过 switch Type 来读取正确的值字段。不解释或执行参数值。
## 项目内依赖
| 依赖项 | 关系 | 源文件 |
|--------|------|--------|
| EDialogPresentationScriptCommandParamType | 成员类型 | Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h |
## 对外接口
BlueprintType 结构体,作为对话脚本命令参数的带标签联合体值类型。
关键字段:
- **Type** (EDialogPresentationScriptCommandParamType): 类型标签,指示哪个值字段有效。消费者应先检查此字段,然后读取对应的值字段。
- **StringValue** (FString): 字符串值,当 Type == String 时有效。
- **NumberValue** (float): 数值,当 Type == Number 时有效。
- **BooleanValue** (bool): 布尔值,当 Type == Boolean 时有效。
- **ArrayValue** (FString): JSON 数组的序列化字符串,当 Type == Array 时有效。需自行解析为 TArray。
- **ObjectValue** (FString): JSON 对象的序列化字符串,当 Type == Object 时有效。需自行解析为 TSharedPtr<FJsonObject>。
构造函数行为:
- Type 默认为 `EDialogPresentationScriptCommandParamType::None`
- NumberValue 默认为 `0.0f`
- BooleanValue 默认为 `false`
- StringValue、ArrayValue、ObjectValue 默认为空字符串FString 默认构造)
## 使用方法
从 FDialogPresentationScriptData 获取单个参数:
```cpp
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp:201-225
FDialogPresentationScriptParam Param = UPresentationJsonLibrary::GetPresentationScriptCommandParaAt(Data, CommandIndex, ParaIndex);
```
从字符串构建参数对象:
```cpp
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp:228-243
FDialogPresentationScriptParam Param = UPresentationJsonLibrary::BuildPresentationScriptCommandParaFromStr(SourceString);
```
消费者按 Type 分发读取正确的值字段,参见 `ParamToJson` 中的 switch 分发模式DialogPresentationScript.cpp:353-389
## 用例
| 文件 | 行号 | 用途 |
|------|------|------|
| Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h | 54-85 | 结构体定义,包含所有字段和构造函数 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 150-198 | JsonValueToParam 解析 JSON 值并填充字段 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 201-225 | GetPresentationScriptCommandParaAt 获取指定命令的指定参数 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 228-243 | BuildPresentationScriptCommandParaFromStr 从字符串构建参数 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 246-276 | GetPresentationScriptCommandParams 获取某命令的所有参数数组 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 351-389 | ParamToJson 按 Type 序列化为 JSON |