当前位置:网站首页>Unreal_DataTable 实现Id自增与设置RowName
Unreal_DataTable 实现Id自增与设置RowName
2022-07-03 16:06:00 【SimpleCloud94】
在编辑器下实现id自增

例如上图,在点击Add时,实现Id自动加1,如何实现呢?
方法如下:
- 在定义如图上述的结构体时,在Id属性列,在结构体属性初始化时赋值

定义一个静态方法,静态方法里动态获取
Datatable表里的数据获取上述表结构里的
Id的属性值的方法有很多,如下只提供一个参考
int32 UDataTableHelperUtils::GetDataTableLastIdNum()
{
int CardId = 0;
UDataTable* DataTable = LoadObject<UDataTable>(nullptr,TEXT("DataTable'/Game/DataTables/DT_Cards.DT_Cards'"));
if(!DataTable) return CardId;
TArray<TArray<FString>> TableData = DataTable->GetTableData();
#if WITH_EDITOR
for(int i=0; i< TableData.Num();i++)
{
FDataTableEditorUtils::RenameRow(DataTable,*TableData[i][0],*TableData[i][1]);
}
#endif
DataTable->Modify();
// UEditorAssetLibrary::SaveAsset(TEXT("DataTable'/Game/DataTables/DT_Cards.DT_Cards'"),false);
const FString RowId = TableData[TableData.Num()-1][1];
CardId = FCString::Atoi(*RowId);
return CardId;
}
其中DataTable->GetTableData()方法里获取的是一个二维数组,行列结构。默认列下标为1是代表id属性的值
其中const FString RowId = TableData[TableData.Num()-1][1];获取就是最后一行Id的属性值
动态修改RowName
如果是使用代码层面,动态添加一条记录。可以使用FDataTableEditorUtils,主要该类属于UnrealEd模块,在运行时是不可以使用的。

FDataTableEditorUtils::AddRow()
在运行时或者Runtime模式下,也可以通过UDataTable的方法AddRow()实现添加,但在运行时没有提供重置RowName的方法。
在上述代码中,该方法修改RowName并不是一个很高效的办法,这个可根据实际情况调整,笔者在编辑器下进行测试,不考虑性能问题
for(int i=0; i< TableData.Num();i++)
{
FDataTableEditorUtils::RenameRow(DataTable,*TableData[i][0],*TableData[i][1]);
}
最后的最后,如果您觉得这篇文章帮助到您,请资助下这位朋友的粮食,谢谢!

边栏推荐
- App移动端测试【3】ADB命令
- 阿飞的期望
- [combinatorics] combinatorial identity (sum of combinatorial identity products 1 | sum of products 1 proof | sum of combinatorial identity products 2 | sum of products 2 proof)
- 分布式事务(Seata) 四大模式详解
- Shell script import and export data
- Expression of request header in different countries and languages
- Break through 1million, sword finger 2million!
- [web security] - [SQL injection] - error detection injection
- EditText request focus - EditText request focus
- 2022年Q2加密市场投融资报告:GameFi成为投资关键词
猜你喜欢

Mongodb installation and basic operation

探索Cassandra的去中心化分布式架构

嵌入式开发:避免开源软件的7个理由
![[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix](/img/d6/3c21c25f1c750f17aeb871124e80f4.png)
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix

Embedded development: seven reasons to avoid open source software

Microservices - load balancing ribbon

Microservices Seata distributed transactions
![App mobile terminal test [4] APK operation](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [4] APK operation
![[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)](/img/1f/3dd95522b8d5f03dd763a6779e3db5.jpg)
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)

半监督学习
随机推荐
MB10M-ASEMI整流桥MB10M
Driver and application communication
Redis high availability and persistence
请做好3年内随时失业的准备?
Chinese translation of Tagore's floating birds (1~10)
nifi从入门到实战(保姆级教程)——flow
Download and install common programs using AUR
[combinatorics] combinatorial identities (sum of variable terms 3 combinatorial identities | sum of variable terms 4 combinatorial identities | binomial theorem + derivation to prove combinatorial ide
How can technology managers quickly improve leadership?
Hibernate的缓存机制/会话级缓存机制
A Fei's expectation
Reflection on some things
Detailed explanation of four modes of distributed transaction (Seata)
阿飞的期望
Use percent sign in CString
Semi supervised learning
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
远程文件包含实操
Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
Large CSV split and merge