参数 RunUAT内部实际调用的是AutomationTool.exe(EngineBinariesDotNET)。
AutomationTool.exe -help 查看帮助信息。 AutomationTool.exe -list 列出所有可以用的功能。 AutomationTool.exe -help BuildCookRun 查看特定命令帮助信息。UE4 Editor使用python
- 文档 https://docs.unrealengine.com/4.27/zh-CN/ProductionPipelines/scriptingAndAutomation/Python/
- Python API文档 https://api.unrealengine.com/INT/PythonAPI/
# Cmd中运行python脚本 UE4Editor-Cmd.exe "C:projectsMyProject.uproject" -run=pythonscript -script="c:\my_script.py" # 在editor控制台中运行python脚本目录扫描
auto VisitDirectory = [this, &FoundFiles, &ExtensionSearchSet](const TCHAR* InFilenameOrDirectory, const bool bIsDirectory) -> bool { if (!bIsDirectory) { FString Extension = FPaths::GetExtension( InFilenameOrDirectory ).ToLower(); if ( ExtensionSearchSet.Find( Extension ) ) { FoundFiles.Add( FPaths::ConvertRelativePathToFull( InFilenameOrDirectory ) ); } } return true; // continue iteration }; IFileManager::Get().IterateDirectoryRecursively( *FolderPath, VisitDirectory );调用python脚本转换配置
.UE4Editor-Cmd.exe "D:ClientgameGame.uproject" -run=pythonscript -script="D:ClientgameContentPythondatatables_to_json.py"Python脚本内容:
# coding: utf-8 import unreal if __name__ == "__main__": unreal.log_warning("[convert configs] start") bResult = unreal.EditorFunctionLibrary.convert_configs_to_json() if bResult: unreal.log_warning("[convert configs] succeed") else: unreal.log_warning("[convert configs] fail") unreal.log_warning("[convert configs] end")UE4 代码
bool UEditorFunctionLibrary::ConvertConfigsToJson() { // 获取需要转换的DataTables名字(单独配置) TArrayDataTables = {"ddd","dddx"} bool bConvertResult = true; auto AutoToJson = [&DataTables, &bConvertResult](const TCHAR* InFilenameOrDirectory, const bool bIsDirectory) -> bool { // 转换其他文件异常 if (!bConvertResult) { return false; } // 文件夹跳过 if (bIsDirectory) { bConvertResult = true; return true; } FString FilebaseName = FPaths::GetbaseFilename(InFilenameOrDirectory); // 检查是否在转换列表中 if (DataTables.Find(FilebaseName) == INDEX_NONE) { bConvertResult = true; return true; } // 生成资源目录 FString FrontPath = FPaths::GetPath(InFilenameOrDirectory); int32 Pos = FrontPath.Find(TEXT("/GameData")); if (Pos == INDEX_NONE) { bConvertResult = false; return false; } FString MiddlePath = FrontPath.Right(FrontPath.Len() - Pos); // UE4 资源名 FString FileRef = FString::Printf(TEXT("DataTable'/Game%s/%s.%s'"), *MiddlePath, *FilebaseName, *FilebaseName); // 读取资源文件 UDataTable* UserInfoDataTable = LoadObject (nullptr, *FileRef); // 文件转换Json if (UserInfoDataTable) { FString JsonString = UserInfoDataTable->GetTableAsJSON(EDataTableExportFlags::UseJsonObjectsForStructs); FString JsonSavePath = FPaths::ProjectContentDir() / TEXT("../TablesServer/" + FilebaseName + ".json"); FFileHelper::SaveStringToFile(JsonString, *JsonSavePath, FFileHelper::EEncodingOptions::ForceUTF8); bConvertResult = true; } else { bConvertResult = false; return false; } return true; }; FString DataTablesPath = FPaths::ProjectContentDir() / TEXT("GameData"); IFileManager::Get().IterateDirectoryRecursively(*DataTablesPath, AutoToJson); return bConvertResult; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)