软路径通过ue 编辑器找到对应资产复制软路径
//Actor等资产需要在类名后添加_C
FString UPR_AssetPath_Library::GetAssetPath_C(const FString& Path)
{
if (Path.IsEmpty()) return TEXT("");
FString inPath = *Path;
TArray<FString> PathItems;
inPath.ParseIntoArray(PathItems, TEXT("'"));
if (PathItems.Num() == 1)
{
return inPath;
}
else if (PathItems.Num() > 1)
{
inPath = PathItems[1] + "_C";
}
return inPath;
}
//Actor类名
UClass* GetActorClassFromPath(const FString& Path)
{
FString inPath = GetAssetPath_C(Path);
if (inPath.IsEmpty()) return NULL;
const FSoftClassPath ClassPath = FSoftClassPath(inPath);
UClass* ActorClass = ClassPath.TryLoadClass<AActor>();
return ActorClass; /*LoadClass<AActor>(NULL, *Path);*/
}
//纹理
UTexture2D* GetTextureFromPath(const FString& Path)
{
return Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *Path));
}
//材质
UMaterialInterface* GetMaterialBySoftPath(const FString& SoftPath)
{
return Cast<UMaterialInterface>(StaticLoadObject(UMaterialInterface::StaticClass(), NULL, *SoftPath));
}
//Object派生的类名
UClass* GetActorClassFromPath(const FString& Path)
{
if (Path.IsEmpty()) return NULL;
const FSoftClassPath ClassPath = FSoftClassPath(Path);
UClass* objectClass = ClassPath.TryLoadClass<UObect>();
return objectClass ;
}