10#include "Misc/FileHelper.h"
12#include "GenericPlatform/GenericPlatformProcess.h"
14#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
15#include "Misc/FileHelper.h"
19 FString MapName = InMapName;
25 FString CorrectedMapName = MapName;
26 constexpr auto PIEPrefix = TEXT(
"UEDPIE_0_");
27 CorrectedMapName.RemoveFromStart(PIEPrefix);
28 MapName = CorrectedMapName;
32 MapName += TEXT(
".xodr");
34 const FString DefaultFilePath =
35 FPaths::ProjectContentDir() +
36 TEXT(
"Carla/Maps/OpenDrive/") +
39 auto &FileManager = IFileManager::Get();
41 if (FileManager.FileExists(*DefaultFilePath))
43 return DefaultFilePath;
46 TArray<FString> FilesFound;
47 FileManager.FindFilesRecursive(
49 *FPaths::ProjectContentDir(),
55 return FilesFound.Num() > 0 ? FilesFound[0u] : FString{};
60 auto MapName = World->GetMapName();
66 FString CorrectedMapName = MapName;
67 constexpr auto PIEPrefix = TEXT(
"UEDPIE_0_");
68 CorrectedMapName.RemoveFromStart(PIEPrefix);
69 MapName = CorrectedMapName;
76 const auto FolderDir = MapDir +
"/OpenDrive/";
77 const auto FileName = MapDir.EndsWith(MapName) ?
"*" : MapName;
80 TArray<FString> Files;
81 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
87 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
89 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
91 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
95 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *Files[0]);
107 if (FilePath.IsEmpty())
109 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
111 else if (FFileHelper::LoadFileToString(Content, *FilePath))
113 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *FilePath);
117 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *FilePath);
129 FString CorrectedMapName = MapName;
130 constexpr auto PIEPrefix = TEXT(
"UEDPIE_0_");
131 CorrectedMapName.RemoveFromStart(PIEPrefix);
132 MapName = CorrectedMapName;
136 FString FileName = XODRPath.EndsWith(MapName) ?
"*" : MapName;
137 FString FolderDir = XODRPath;
138 FolderDir.RemoveFromEnd(MapName +
".xodr");
141 TArray<FString> Files;
142 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
148 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
150 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
152 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
161 auto XODRContent =
LoadXODR(MapName);
162 if (!XODRContent.IsEmpty())
164 Map = NewObject<UOpenDriveMap>();
165 Map->
Load(XODRContent);
172 UWorld *World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
173 return World !=
nullptr ?
Base class for the CARLA Game Mode.
const FString GetFullMapPath() const
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
将 CARLA OpenDrive API 公开给蓝图的辅助类。
bool Load(const FString &XODRContent)
Load this map with an OpenDrive (XODR) file.
static UOpenDriveMap * LoadCurrentOpenDriveMap(const UObject *WorldContextObject)
Load OpenDriveMap associated to the currently loaded map.
static FString FindPathToXODRFile(const FString &InMapName)
static FString GetXODR(const UWorld *World)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
static FString LoadXODR(const FString &MapName)
static UOpenDriveMap * LoadOpenDriveMap(const FString &MapName)
Load OpenDriveMap associated to the given MapName.
static FString GetXODRByPath(FString XODRPath, FString MapName)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.