当前位置:网站首页>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]);
}
最后的最后,如果您觉得这篇文章帮助到您,请资助下这位朋友的粮食,谢谢!
边栏推荐
- [200 opencv routines] 217 Mouse interaction to obtain polygon area (ROI)
- Colab works with Google cloud disk
- Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
- Microservice - Nacos registration center and configuration center
- Project -- high concurrency memory pool
- How can technology managers quickly improve leadership?
- Qt插件之自定义插件构建和使用
- Win32 create window and button (lightweight)
- LeetCode1491. Average value of wages after removing the minimum wage and the maximum wage
- [list to map] collectors Tomap syntax sharing (case practice)
猜你喜欢
Reading notes of "micro service design" (Part 2)
Redis installation under windows and Linux systems
Microservice - fuse hystrix
Automatic generation of client code from flask server code -- Introduction to flask native stubs Library
面试官:JVM如何分配和回收堆外内存
App mobile terminal test [3] ADB command
Mixlab编辑团队招募队友啦~~
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (I)
Microservices - load balancing ribbon
Shell script import and export data
随机推荐
[proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
《天天数学》连载56:二月二十五日
Go language self-study series | if else if statement in golang
Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)
Is it safe to open an account with tongdaxin?
Effect of ARP package on FTP dump under vxworks-6.6 system
Project -- high concurrency memory pool
EditText request focus - EditText request focus
[redis foundation] understand redis persistence mechanism together (rdb+aof graphic explanation)
用同花顺炒股开户安全吗?
ASEMI整流桥UMB10F参数,UMB10F规格,UMB10F封装
大csv拆分和合并
Microservice - Nacos registration center and configuration center
Go语言自学系列 | golang switch语句
Large CSV split and merge
Semi supervised learning
Redis installation under windows and Linux systems
App移动端测试【5】文件的写入、读取
From the 18th line to the first line, the new story of the network security industry
The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)