[UE4]自定义结构体类数据表

Posted timy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[UE4]自定义结构体类数据表相关的知识,希望对你有一定的参考价值。

自定义数据表:

#pragma once

#include "CoreMinimal.h"
#include "Engine/UserDefinedStruct.h"
#include "Components/CanvasPanel.h"
#include "Blueprint/UserWidget.h"
#include "Runtime/Engine/Classes/Engine/UserDefinedStruct.h"
#include "Runtime/Engine/Classes/Engine/DataTable.h"
#include "Runtime/CoreUObject/Public/UObject/ObjectMacros.h"

#include "MiniMapFlagData.generated.h"


/*BlueprintType:暴露成为蓝图数据类型,蓝图变量可以使用该结构体作为数据类型*/
USTRUCT(BlueprintType)
struct FUMiniMapFlagDataC : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()

    //小图标
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UUserWidget* flag;

    //小图标对应的Actor
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        AActor* Actor;

    //小图标对应的Canvas panel Slot
    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        UCanvasPanelSlot* Slot;

    UPROPERTY(EditAnywhere, BlueprintReadWrite)
        int MyAge;
};

成员变量添加UPROPERTY标签,可以享受到UE4垃圾自动管理机制,不用手动释放变量内存。

自定义类

#pragma once

#include "CoreMinimal.h"
#include "Engine/UserDefinedStruct.h"
#include "Components/CanvasPanel.h"
#include "Blueprint/UserWidget.h"
#include "Runtime/Engine/Classes/Engine/UserDefinedStruct.h"
#include "Runtime/Engine/Classes/Engine/DataTable.h"
#include "Runtime/CoreUObject/Public/UObject/ObjectMacros.h"

#include "MiniMapFlagData.generated.h"

/**
*
*/
UCLASS(BlueprintType)
class PROJ10_0121_API UMiniMapFlagData : public UUserDefinedStruct
{
    GENERATED_BODY()

public:
    UMiniMapFlagData() {}
    UMiniMapFlagData(UUserWidget* flag, AActor* Actor, UCanvasPanelSlot* Slot)
        :flag(flag), Actor(Actor), Slot(Slot)
    {}
    /*
        flag(flag)表示将参数flag赋值给成员参数flag
        使用方法:UMiniMapFlagData data(flag,Actor,Slot);
    */

public:
    //小图标
    UPROPERTY()
        UUserWidget* flag;

    //小图标对应的Actor
    UPROPERTY()
        AActor* Actor;

    //小图标对应的Canvas panel Slot
    UPROPERTY()
        UCanvasPanelSlot* Slot;

    UPROPERTY()
        int MyAge;

};

 

自定义函数添加说明文字,可在蓝图中显示,如果要支持中文,则只要把h和cpp文件以utf-8编码保存就可以了。

注意:EditAnywhere,BlueprintReadWrite等等修饰符不能拼写错误,拼写错误是不会有错误提示的,并且编译出错信息也不会告诉我们是修饰符写错了,只会说编译出错,没有详细的出错信息。

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/CanvasPanel.h"
#include "MiniMap/MiniMapFlagData.h"

#include "StaticMiniMapBase.generated.h"

/**
 * 
 */
UCLASS()
class PROJ10_0121_API UStaticMiniMapBase : public UUserWidget
{
    GENERATED_BODY()

protected:
    UPROPERTY(EditAnywhere,BlueprintReadWrite, Category=myMethods,meta=(ToolTip="小图标容器面板"))
        UCanvasPanel * PanelFlag;
     
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = myMethods,meta=(ToolTip="存放小图标数据机构数组"))
        TArray<UMiniMapFlagData*> ArrayFlag;
    //TArray<TSubclassOf<class UMiniMapFlagData>> FlagArray;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = myVariables,meta=(ToolTip="小地图比例尺"))
        float RatioMap;
    
protected:
    UFUNCTION(BlueprintCallable, Category = myMethods,meta=(ToolTip="初始化UI控件对象"))
        void ini(UCanvasPanel* sFlagPanel);

public:
    UFUNCTION(BlueprintCallable, Category = myMethods,meta=(ToolTip="添加图标到小地图"))
    void Add_Flag(UUserWidget* flag, AActor* actor);
    
};

 技术分享图片

ArrayFlag是在C++定义的函数,可以在蓝图中显示中文说明文字。

 

以上是关于[UE4]自定义结构体类数据表的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段5——HTML元素结构

VSCode自定义代码片段5——HTML元素结构

Swift具体解释之六----------------枚举结构体类

[工作积累] UE4 并行渲染的同步 - Sync between FParallelCommandListSet & FRHICommandListImmediate calls(代码片段

如何在 Toad for Oracle 中使用自定义代码片段?

基于C++代码的UE4学习—— 自定义代理结合Timer实现道具的消失与重生