C++: 建立DataTable

我的需求:在UE4游戏工程里建立4种自定义表格
参考文档: UE4.11 引擎自带的代码文件 GameplayTagsManager.h

/** Simple struct for a table row in the gameplay tag table */
USTRUCT()
struct FGameplayTagTableRow : public FTableRowBase
{
    GENERATED_USTRUCT_BODY()

    /** Tag specified in the table */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=GameplayTag)
    FString Tag;

    /** Text that describes this category - not all tags have categories */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=GameplayTag)
    FText CategoryText;

    /** Constructors */
    FGameplayTagTableRow() { CategoryText = NSLOCTEXT("TAGCATEGORY", "TAGCATEGORYTESTING", "Category and Category"); }
    FGameplayTagTableRow(FGameplayTagTableRow const& Other);

    /** Assignment/Equality operators */
    FGameplayTagTableRow& operator=(FGameplayTagTableRow const& Other);
    bool operator==(FGameplayTagTableRow const& Other) const;
    bool operator!=(FGameplayTagTableRow const& Other) const;
};

我的头文件 WeaponDataTable.h

#pragma once
#include "WeaponDataTable.generated.h"

USTRUCT()
struct FWeapon_Entry : public FTableRowBase
{
    GENERATED_BODY()
    
        /** Tag specified in the table */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FString Tag;

        /** Text that describes this category - not all tags have categories */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
            FText CategoryText;
    
        /** Text that describes this category - not all tags have categories */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
            FText CategoryText1;

        /** Text that describes this category - not all tags have categories */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
            FText CategoryText2;

        /** Text that describes this category - not all tags have categories */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
            FText CategoryText3;
};


USTRUCT()
struct FWeapon_Client : public FTableRowBase
{
    GENERATED_BODY()

        /** Tag specified in the table */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FString Tag;

    /** Text that describes this category - not all tags have categories */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FText CategoryText;
};

USTRUCT()
struct FWeapon_Spell_Entry : public FTableRowBase
{
    GENERATED_BODY()

        /** Tag specified in the table */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FString Tag;

    /** Text that describes this category - not all tags have categories */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FText CategoryText;
};

USTRUCT()
struct FWeapon_Spell_Client : public FTableRowBase
{
    GENERATED_BODY()

        /** Tag specified in the table */
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FString Tag;

    /** Text that describes this category - not all tags have categories */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = GameplayTag)
        FText CategoryText;
};

我的对应的cpp文件

#include "YourProjName.h" //你的项目头文件
#include "WeaponDataTable.h"

最终效果


看,自定义表格成功

结论:

数据表在代码层面也是结构体,明白这一点,那么就不难理解上面代码结构体名和最终数据表可选类型的对应关系。本帖将要推出

  1. 用蓝图实现数据表
  2. C++细说数据表内容
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 国家电网公司企业标准(Q/GDW)- 面向对象的用电信息数据交换协议 - 报批稿:20170802 前言: 排版 ...
    庭说阅读 11,196评论 6 13
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,014评论 19 139
  • 1.项目经验 2.基础问题 3.指南认识 4.解决思路 ios开发三大块: 1.Oc基础 2.CocoaTouch...
    阳光的大男孩儿阅读 5,047评论 0 13
  • 记得我初中的语文课文中读过朱自清先生的《背影》,那时只记得老师说这篇文章对于考试很重要,是重点课文中的...
    老冯杂谈阅读 1,805评论 4 4
  • 身着军装,手持配枪。这是我童年幻想中的自己。而我的故事也要从那时说起。。。。 。。 而我的梦是要做一位顶天立地的男...
    半世末影阅读 253评论 0 0