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;
};

我的對應(yīng)的cpp文件

#include "YourProjName.h" //你的項目頭文件
#include "WeaponDataTable.h"

最終效果


看,自定義表格成功

結(jié)論:

數(shù)據(jù)表在代碼層面也是結(jié)構(gòu)體,明白這一點,那么就不難理解上面代碼結(jié)構(gòu)體名和最終數(shù)據(jù)表可選類型的對應(yīng)關(guān)系。本帖將要推出

  1. 用藍(lán)圖實現(xiàn)數(shù)據(jù)表
  2. C++細(xì)說數(shù)據(jù)表內(nèi)容
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 國家電網(wǎng)公司企業(yè)標(biāo)準(zhǔn)(Q/GDW)- 面向?qū)ο蟮挠秒娦畔?shù)據(jù)交換協(xié)議 - 報批稿:20170802 前言: 排版 ...
    庭說閱讀 12,430評論 6 13
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • 1.項目經(jīng)驗 2.基礎(chǔ)問題 3.指南認(rèn)識 4.解決思路 ios開發(fā)三大塊: 1.Oc基礎(chǔ) 2.CocoaTouch...
    扶光啟玄閱讀 5,205評論 0 13
  • 記得我初中的語文課文中讀過朱自清先生的《背影》,那時只記得老師說這篇文章對于考試很重要,是重點課文中的...
    老馮雜談閱讀 1,846評論 4 4
  • 身著軍裝,手持配槍。這是我童年幻想中的自己。而我的故事也要從那時說起。。。。 。。 而我的夢是要做一位頂天立地的男...
    半世末影閱讀 273評論 0 0

友情鏈接更多精彩內(nèi)容