打包
RunUAT.bat(Engine\Build\BatchFiles)实现一键打包
参数 RunUAT内部实际调用的是AutomationTool.exe(Engine\Binaries\DotNET)。
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/
运行python脚本
# Cmd中运行python脚本
UE4Editor-Cmd.exe "C:\projects\MyProject.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:\Client\game\Game.uproject" -run=pythonscript -script="D:\Client\game\Content\Python\datatables_to_json.py"
Python脚本内容:
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名字(单独配置)
TArray<FString> DataTables = {"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<UDataTable>(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;
}
|