UE4引擎的夸平台读写Excel的组件:DataTable - 纳金网
联系我们

给我们留言

联系我们

地址:福建省晋江市青阳街道洪山路国际工业设计园纳金网

邮箱:info@narkii.com

电话:0595-82682267

(周一到周五, 周六周日休息)

当前位置:主页 > 3D教程 > 图文教程

UE4引擎的夸平台读写Excel的组件:DataTable

来源: 52vr | 责任编辑:传说的落叶 | 发布时间: 2019-06-04 08:26 | 浏览量:

[UE4]引擎自身提供的一种夸平台读写Excel的组件:DataTable

 

UE4自身提供的一种读写文件的组件:UDataTable。好处就是不用自己写fopen、fclose等 c++ stl API相关的逻辑,避开不同平台的差异;坏处就是你想要的功能DataTable没有实现,那么还得用fopen自己发挥。

 

读写excel需要导出为CSV文件,目前还不支持*.XLS格式。

 

下面官方文档中关于用C++代码定义行结构的用法没有具体说明:

如果是蓝图创建DataTable,那么行结构Struct也可以用UE4提供的Struct组件,创建方式是:add new -》 Blueprints -》 Structure,然后再这个Structure中设置行结构。

如果是用C++代码创建DataTable,直接new C++ class,选择继承DataTable。另外FTableRowBase可以直接定义在自定义DataTable的头文件中,例如:

 
  1. #pragma once  
  2.   
  3. #include "Engine/DataTable.h"  
  4. #include "CharactersDT.generated.h"  
  5.   
  6. USTRUCT(BlueprintType)  
  7. struct FLevelUpData : public FTableRowBase  
  8. {  
  9.     GENERATED_USTRUCT_BODY()  
  10.   
  11. public:  
  12.   
  13.     FLevelUpData()  
  14.         : XPtoLvl(0)  
  15.         , AdditionalHP(0)  
  16.     {}  
  17.   
  18.     /** The 'Name' column is the same as the XP Level */  
  19.   
  20.     /** XP to get to the given level from the previous level */  
  21.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)  
  22.         int32 XPtoLvl;  
  23.   
  24.     /** Extra HitPoints gained at this level */  
  25.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)  
  26.         int32 AdditionalHP;  
  27.   
  28.     /** Icon to use for Achivement */  
  29.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = LevelUp)  
  30.         TAssetPtr<UTexture> AchievementIcon;  
  31. };  
 

 

Using excel to store gameplay data - DataTables

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

 

Data Driven Gameplay Elements

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

 

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:

 
  1. FString csvFile = FPaths::GameContentDir() + "Downloads\\DownloadedFile.csv";  
  2. if (FPaths::FileExists(csvFile ))  
  3. {  
  4.     FString FileContent;  
  5.     //Read the csv file  
  6.     FFileHelper::LoadFileToString(FileContent, *csvFile );  
  7.     TArray<FString> problems = YourDataTable->CreateTableFromCSVString(FileContent);  
  8.   
  9.     if (problems.Num() > 0)  
  10.     {  
  11.         for (int32 ProbIdx = 0; ProbIdx < problems.Num(); ProbIdx++)  
  12.         {          
  13.             //Log the errors  
  14.         }  
  15.     }  
  16.     else  
  17.     {  
  18.         //Updated Successfully  
  19.     }  
  20. }  

 参考自:

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


相关文章
网友评论

您需要登录后才可以发帖 登录 | 立即注册

关闭

全部评论:0条

推荐
热门