[UE4]引擎自身提供的一種誇平臺讀寫Excel的組件:DataTable

UE4自身提供的一種讀寫文件的組件:UDataTable。好處就是不用本身寫fopen、fclose等 c++ stl API相關的邏輯,避開不一樣平臺的差別;壞處就是你想要的功能DataTable沒有實現,那麼還得用fopen本身發揮。php

 

讀寫excel須要導出爲CSV文件,目前還不支持*.XLS格式。html

 

下面官方文檔中關於用C++代碼定義行結構的用法沒有具體說明:c++

若是是藍圖建立DataTable,那麼行結構Struct也能夠用UE4提供的Struct組件,建立方式是:add new -》 Blueprints -》 Structure,而後再這個Structure中設置行結構。編輯器

若是是用C++代碼建立DataTable,直接new C++ class,選擇繼承DataTable。另外FTableRowBase能夠直接定義在自定義DataTable的頭文件中,例如:ui

#pragma once

#include "Engine/DataTable.h"
#include "CharactersDT.generated.h"

USTRUCT(BlueprintType)
struct FLevelUpData : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()

public:

	FLevelUpData()
		: XPtoLvl(0)
		, AdditionalHP(0)
	{}

	/** The 'Name' column is the same as the XP Level */

	/** XP to get to the given level from the previous level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 XPtoLvl;

	/** Extra HitPoints gained at this level */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		int32 AdditionalHP;

	/** Icon to use for Achivement */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)
		TAssetPtr<UTexture> AchievementIcon;
};

 

 

Using excel to store gameplay data - DataTablesthis

https://wiki.unrealengine.com/Using_excel_to_store_gameplay_data_-_DataTablesexcel

 

Data Driven Gameplay Elementscode

https://docs.unrealengine.com/latest/INT/Gameplay/DataDriven/index.htmlhtm

 

Driving Gameplay with Data from Excel繼承

https://forums.unrealengine.com/showthread.php?12572-Driving-Gameplay-with-Data-from-Excel

 

用藍圖操做DataTable的方法:
Unreal Engine, Datatables for Blueprints (build & Use)

https://www.youtube.com/watch?v=a8jMl69alrg

Excel to Unreal

https://www.youtube.com/watch?v=WLv67ddnzN0

 

如何用C++代碼動態加載*.CSV

若是你的表格不多的話能夠使用這個自帶的DataTable,若是表格不少且會頻繁改動,那麼每次改動後都要手動在UE編輯器中一個一個操做,因此,建議用C++動態加載*.csv:

FString csvFile = FPaths::GameContentDir() + "Downloads\\DownloadedFile.csv";
if (FPaths::FileExists(csvFile ))
{
	FString FileContent;
	//Read the csv file
	FFileHelper::LoadFileToString(FileContent, *csvFile );
	TArray<FString> problems = YourDataTable->CreateTableFromCSVString(FileContent);

	if (problems.Num() > 0)
	{
		for (int32 ProbIdx = 0; ProbIdx < problems.Num(); ProbIdx++)
		{        
			//Log the errors
		}
	}
	else
	{
		//Updated Successfully
	}
}

 參考自:

https://answers.unrealengine.com/questions/156354/how-to-load-the-csv-datatable-dynamically.html

相關文章
相關標籤/搜索