分类:UE4 c++
标签:蓝图函数库
新建了一个c++写的蓝图函数类
在项目的build.cs里面添加"JsonUtilities"模块,添加后如下(添加到了"HeadMountedDisplay"后面)
using UnrealBuildTool;
public class UDPProject : ModuleRules
{
public UDPProject(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" , "JsonUtilities" });
}
}
.h头文件(定义了StructToJsonObjectString函数,有两个子函数)
//LFY 2019/9/30 https://blog.csdn.net/qq_29019373/article/details/93474641
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "UStruct2JsonObjString.generated.h"
UCLASS()
class UDPPROJECT_API UUStruct2JsonObjString : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "LFYBPLibrary", CustomThunk, meta = (CustomStructureParam = "Struct"))
static bool StructToJsonObjectString(FString& OutJsonString, const UStruct* Struct);
static bool Generic_StructToJsonObjectString(FString& OutJsonString, const UStruct* StructDefinition, const void* Struct);
//ReWrite exec
DECLARE_FUNCTION(execStructToJsonObjectString) {
P_GET_PROPERTY_REF(UStrProperty, OutJsonString);
Stack.StepCompiledIn<UStructProperty>(NULL);
void* InStruct = Stack.MostRecentPropertyAddress;
P_FINISH;
bool bSuccess = false;
UStructProperty* StructProp = Cast<UStructProperty>(Stack.MostRecentProperty);
if (StructProp && InStruct)
{
UScriptStruct*StructType = StructProp->Struct;
P_NATIVE_BEGIN;
bSuccess = Generic_StructToJsonObjectString(OutJsonString, StructType, InStruct);
P_NATIVE_END;
}
*(bool*)RESULT_PARAM = bSuccess;
}
};
.cpp文件
#include "UStruct2JsonObjString.h"
#include "JsonObjectConverter.h"
bool UUStruct2JsonObjString::StructToJsonObjectString(FString& OutJsonString, const UStruct* Struct)
{
check(0);
return false;
}
bool UUStruct2JsonObjString::Generic_StructToJsonObjectString(FString& OutJsonString, const UStruct* StructDefinition, const void* Struct)
{
FJsonObjectConverter::UStructToJsonObjectString(StructDefinition, Struct, OutJsonString, 0, 0);
return !OutJsonString.IsEmpty();
}
网友评论