3.4 KiB
3.4 KiB
EDialogPresentationScriptCommandParamType
基本信息
- 类型: UENUM(BlueprintType)
- 父类: uint8
- 源文件: Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h
- 模块: Dialog
功能概述
对话脚本命令参数类型的枚举:None、Number、String、Boolean、Array、Object。在 FDialogPresentationScriptParam 中作为类型标签使用,实现带标签的联合体语义。
设计用意
由于 USTRUCT 无法持有变体值,因此需要显式的类型鉴别机制。运行时代码通过 switch 该枚举值来读取正确的字段。Array 和 Object 类型以序列化的 JSON 字符串形式存储,以兼容蓝图。
职责范围
类型标签枚举。被 FDialogPresentationScriptParam 和 UPresentationJsonLibrary 引用,用于 JSON 解析和分发。
项目内依赖
| 依赖项 | 关系 | 源文件 |
|---|---|---|
| (无项目内依赖) |
对外接口
BlueprintType 枚举,作为 FDialogPresentationScriptParam 中 Type 字段的类型标签。消费者通过 switch 该枚举来决定读取哪个值字段。
枚举值:
- None: 无类型/空值。构造函数默认值,JSON 解析失败时也为 None。
- Number: 对应 JSON Number 类型,值存储在
FDialogPresentationScriptParam::NumberValue(float)。 - String: 对应 JSON String 类型,值存储在
FDialogPresentationScriptParam::StringValue。 - Boolean: 对应 JSON Boolean 类型,值存储在
FDialogPresentationScriptParam::BooleanValue。 - Array: 对应 JSON Array 类型,整个数组序列化为 JSON 字符串存储在
FDialogPresentationScriptParam::ArrayValue。 - Object: 对应 JSON Object 类型,整个对象序列化为 JSON 字符串存储在
FDialogPresentationScriptParam::ObjectValue。
注意:Array 和 Object 以序列化 JSON 字符串形式存储,而非嵌套结构体。消费者需要在蓝图或 C++ 中自行反序列化。
使用方法
在 JSON 解析中按值类型分发:
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp:163-196
switch (JsonValue->Type)
{
case EJson::String:
Param.Type = EDialogPresentationScriptCommandParamType::String;
Param.StringValue = JsonValue->AsString();
break;
case EJson::Number:
Param.Type = EDialogPresentationScriptCommandParamType::Number;
Param.NumberValue = static_cast<float>(JsonValue->AsNumber());
break;
// ... Boolean, Array, Object cases ...
}
在 JSON 序列化中按类型标签写入:
// Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp:353-389
switch (Param.Type)
{
case EDialogPresentationScriptCommandParamType::String:
return FString::Printf(TEXT("\"%s\""), *lambda(Param.StringValue));
case EDialogPresentationScriptCommandParamType::Number:
return FString::SanitizeFloat(Param.NumberValue);
// ... Boolean, Array, Object, default cases ...
}
用例
| 文件 | 行号 | 用途 |
|---|---|---|
| Plugins/Dialog/Source/Dialog/Public/DialogPresentationScript.h | 43-51,61,69 | 枚举定义;FDialogPresentationScriptParam 构造函数默认值 (None);字段声明 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 155-195 | JsonValueToParam 中按 JSON 类型分发到对应枚举值 |
| Plugins/Dialog/Source/Dialog/Private/DialogPresentationScript.cpp | 355-389 | ParamToJson 中按枚举值序列化到 JSON 字符串 |