当前位置:网站首页>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]);
}
最后的最后,如果您觉得这篇文章帮助到您,请资助下这位朋友的粮食,谢谢!

边栏推荐
- Microservices - load balancing ribbon
- Brush questions -- sword finger offer
- 架构实战营 - 第 6 期 毕业总结
- The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)
- 远程文件包含实操
- App移动端测试【4】apk的操纵
- Go语言自学系列 | golang中的if else if语句
- pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
- Mongodb installation and basic operation
- “用Android复刻Apple产品UI”(3)—优雅的数据统计图表
猜你喜欢

近视:摘镜or配镜?这些问题必须先了解清楚

Microservice sentinel flow control degradation

How to thicken the brush in the graphical interface
![[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display](/img/46/c7f566f8fd46d383b055582d680bb7.png)
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display

Mongodb installation and basic operation
![App mobile terminal test [3] ADB command](/img/f1/4bff6e66b77d0f867bf7237019e982.png)
App mobile terminal test [3] ADB command

About text selection in web pages and counting the length of selected text

Secsha system 1- login function

Function introduction of JMeter thread group

Colab works with Google cloud disk
随机推荐
Salary 3000, monthly income 40000 by "video editing": people who can make money never rely on hard work!
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
Driver and application communication
潘多拉 IOT 开发板学习(HAL 库)—— 实验5 外部中断实验(学习笔记)
Detailed explanation of four modes of distributed transaction (Seata)
Pychart error updating package list: connect timed out
[list to map] collectors Tomap syntax sharing (case practice)
pycharm错Error updating package list: connect timed out
Using optimistic lock and pessimistic lock in MySQL to realize distributed lock
First knowledge of database
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
App mobile terminal test [3] ADB command
Microservice API gateway zuul
Go语言自学系列 | golang switch语句
Secsha system 1- login function
Calibre LVL
Win32 create window and button (lightweight)
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
"Everyday Mathematics" serial 56: February 25
《天天数学》连载56:二月二十五日