当前位置:网站首页>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]);
}
最后的最后,如果您觉得这篇文章帮助到您,请资助下这位朋友的粮食,谢谢!
边栏推荐
- Reflection on some things
- Approval process design
- 首发!!lancet饿了么官方文档
- Go language self-study series | if else statement in golang
- Advanced Mathematics (Seventh Edition) Tongji University exercises 2-1 personal solutions
- Redis在Windows以及Linux系统下的安装
- 2022年Q2加密市场投融资报告:GameFi成为投资关键词
- WinDbg analysis dump file
- [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)
- 请求头不同国家和语言的表示
猜你喜欢
The mixlab editing team is recruiting teammates~~
半监督学习
Embedded development: seven reasons to avoid open source software
Brush questions -- sword finger offer
[redis foundation] understand redis master-slave architecture, sentinel mode and cluster together (Demo detailed explanation)
深度学习之三维重建
Stm32f103c8t6 firmware library lighting
"Remake Apple product UI with Android" (3) - elegant statistical chart
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
Mb10m-asemi rectifier bridge mb10m
随机推荐
Approval process design
Getting started with Message Oriented Middleware
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
[web security] - [SQL injection] - error detection injection
Microservice - Nacos registration center and configuration center
[combinatorics] combinatorial identities (review of eight combinatorial identities | product of combinatorial identities 1 | proof | use scenario | general method for finding combinatorial numbers)
坚持输出需要不断学习
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
"Everyday Mathematics" serial 56: February 25
June to - -------
[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)
Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
Go语言自学系列 | golang中的if else语句
Unity项目优化案例一
App移动端测试【5】文件的写入、读取
Microservice - fuse hystrix
Microservice - declarative interface call openfeign
Distributed task scheduling XXL job
Hibernate的缓存机制/会话级缓存机制
Microservices Seata distributed transactions