当前位置:网站首页>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]);
}
最后的最后,如果您觉得这篇文章帮助到您,请资助下这位朋友的粮食,谢谢!
边栏推荐
- [系统安全] 四十三.Powershell恶意代码检测系列 (5)抽象语法树自动提取万字详解
- Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (III)
- Principles of several common IO models
- 一些事情的反思
- 近视:摘镜or配镜?这些问题必须先了解清楚
- "Everyday Mathematics" serial 56: February 25
- 面试官:JVM如何分配和回收堆外内存
- Function introduction of JMeter thread group
- EditText request focus - EditText request focus
- Problems of CString in multithreading
猜你喜欢
“用Android复刻Apple产品UI”(2)——丝滑的AppStore卡片转场动画
WinDbg analysis dump file
几种常见IO模型的原理
"Remake Apple product UI with Android" (2) -- silky Appstore card transition animation
Srs4.0+obs studio+vlc3 (environment construction and basic use demonstration)
面试官:JVM如何分配和回收堆外内存
Create gradle project
Initial test of scikit learn Library
From the 18th line to the first line, the new story of the network security industry
The difference between calling by value and simulating calling by reference
随机推荐
Download and install common programs using AUR
Wechat payment -jsapi: code implementation (payment asynchronous callback, Chinese parameter solution)
Reflection on some things
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (4)
Nifi from introduction to practice (nanny level tutorial) - flow
【Proteus仿真】8×8LED点阵屏仿电梯数字滚动显示
【Proteus仿真】74HC595+74LS154驱动显示16X16点阵
pyinstaller不是内部或外部命令,也不是可运行的程序 或批处理文件
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Why can't strings be directly compared with equals; Why can't some integers be directly compared with the equal sign
Stm32f103c8t6 firmware library lighting
Win32 create window and button (lightweight)
Intelij idea efficient skills (III)
Low level version of drawing interface (explain each step in detail)
Project -- high concurrency memory pool
Vs2017 is driven by IP debugging (dual machine debugging)
请求头不同国家和语言的表示
Create gradle project
六月 致 -.-- -..- -
Mixlab编辑团队招募队友啦~~