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

边栏推荐
- How idea starts run dashboard
- 首发!!lancet饿了么官方文档
- Go language self-study series | if else if statement in golang
- 几种常见IO模型的原理
- Reading notes of "micro service design" (Part 2)
- 【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
- 关于网页中的文本选择以及统计选中文本长度
- How to use AAB to APK and APK to AAB of Google play apps on the shelves
- Introduction series of software reverse cracking (1) - common configurations and function windows of xdbg32/64
- How can technology managers quickly improve leadership?
猜你喜欢

Subclass hides the function with the same name of the parent class

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

“用Android复刻Apple产品UI”(3)—优雅的数据统计图表

关于网页中的文本选择以及统计选中文本长度

"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation

MongoDB 的安装和基本操作

App移动端测试【4】apk的操纵

【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
![[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

Myopia: take off or match glasses? These problems must be understood clearly first
随机推荐
用通达信炒股开户安全吗?
Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)
TCP拥塞控制详解 | 3. 设计空间
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
Embedded development: seven reasons to avoid open source software
CString getbuffer and releasebuffer instructions
高等数学(第七版)同济大学 习题2-1 个人解答
Approval process design
[200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
Redis high availability and persistence
Jmeter线程组功能介绍
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
Microservice - Nacos registration center and configuration center
Persisting in output requires continuous learning
Mb10m-asemi rectifier bridge mb10m
Microservice - declarative interface call openfeign
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
记一次jar包冲突解决过程