? 欧洲国产激情在线观看,无遮挡免费h肉动漫在线
聯(lián)系我們

給我們留言

聯(lián)系我們

地址:福建省晉江市青陽街道洪山路國際工業(yè)設(shè)計(jì)園納金網(wǎng)

郵箱:info@narkii.com

電話:0595-82682267

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

當(dāng)前位置:主頁 > 3D教程 > 圖文教程

UE4引擎的夸平臺讀寫Excel的組件:DataTable

來源: 52vr | 責(zé)任編輯:傳說的落葉 | 發(fā)布時(shí)間: 2019-06-04 08:26 | 瀏覽量:

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

 

UE4自身提供的一種讀寫文件的組件:UDataTable。好處就是不用自己寫fopen、fclose等 c++ stl API相關(guān)的邏輯,避開不同平臺的差異;壞處就是你想要的功能DataTable沒有實(shí)現(xiàn),那么還得用fopen自己發(fā)揮。

 

讀寫excel需要導(dǎo)出為CSV文件,目前還不支持*.XLS格式。

 

下面官方文檔中關(guān)于用C++代碼定義行結(jié)構(gòu)的用法沒有具體說明:

如果是藍(lán)圖創(chuàng)建DataTable,那么行結(jié)構(gòu)Struct也可以用UE4提供的Struct組件,創(chuàng)建方式是:add new -》 Blueprints -》 Structure,然后再這個(gè)Structure中設(shè)置行結(jié)構(gòu)。

如果是用C++代碼創(chuàng)建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

 

用藍(lán)圖操作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++代碼動態(tài)加載*.CSV

如果你的表格很少的話可以使用這個(gè)自帶的DataTable,如果表格很多且會頻繁改動,那么每次改動后都要手動在UE編輯器中一個(gè)一個(gè)操作,所以,建議用C++動態(tài)加載*.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


相關(guān)文章
網(wǎng)友評論

您需要登錄后才可以發(fā)帖 登錄 | 立即注冊

關(guān)閉

全部評論:0條

推薦
熱門