2025-04-01 22:31:27 -04:00
|
|
|
|
|
|
|
|
#include "AssetLookup.h"
|
|
|
|
|
#include "AssetRegistry/IAssetRegistry.h"
|
|
|
|
|
#include "AssetRegistry/AssetData.h"
|
|
|
|
|
#include "AssetRegistry/AssetRegistryState.h"
|
|
|
|
|
#include "LuprexGameModeBase.h"
|
|
|
|
|
|
|
|
|
|
void UlxAssetLookup::RebuildIndex()
|
|
|
|
|
{
|
|
|
|
|
CachedTangibles.Empty();
|
|
|
|
|
CachedStaticMeshes.Empty();
|
|
|
|
|
IAssetRegistry::GetChecked().WaitForCompletion();
|
|
|
|
|
ScanTangibles();
|
|
|
|
|
ScanStaticMeshes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxAssetLookup::ScanTangibles()
|
|
|
|
|
{
|
|
|
|
|
TArray<FAssetData> FoundData;
|
|
|
|
|
FARFilter AssetFilter;
|
|
|
|
|
AssetFilter.PackagePaths.Add(FName(TEXT("/Game/Tangibles")));
|
|
|
|
|
AssetFilter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
|
|
|
|
|
AssetFilter.bIncludeOnlyOnDiskAssets = true;
|
|
|
|
|
AssetFilter.bRecursivePaths = true;
|
|
|
|
|
IAssetRegistry::GetChecked().GetAssets(AssetFilter, FoundData);
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d assets in /Game/Tangibles"), FoundData.Num());
|
|
|
|
|
for (const FAssetData &Data : FoundData)
|
|
|
|
|
{
|
|
|
|
|
FString Path = Data.GetObjectPathString();
|
|
|
|
|
CachedTangibles.Add(Data.AssetName, Path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UlxAssetLookup::ScanStaticMeshes()
|
|
|
|
|
{
|
|
|
|
|
TArray<FAssetData> FoundData;
|
|
|
|
|
FARFilter AssetFilter;
|
|
|
|
|
AssetFilter.PackagePaths.Add(FName(TEXT("/Game/StaticMeshes")));
|
|
|
|
|
AssetFilter.ClassPaths.Add(UStaticMesh::StaticClass()->GetClassPathName());
|
|
|
|
|
AssetFilter.bIncludeOnlyOnDiskAssets = true;
|
|
|
|
|
AssetFilter.bRecursivePaths = true;
|
|
|
|
|
IAssetRegistry::GetChecked().GetAssets(AssetFilter, FoundData);
|
|
|
|
|
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d static mesh assets"), FoundData.Num());
|
|
|
|
|
for (const FAssetData &Data : FoundData)
|
|
|
|
|
{
|
|
|
|
|
FString Path = Data.GetObjectPathString();
|
|
|
|
|
CachedStaticMeshes.Add(Data.AssetName, Path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString UlxAssetLookup::TangibleLoadPath(const FName &AssetName) const
|
|
|
|
|
{
|
|
|
|
|
FScopeLock lock(&Mutex);
|
|
|
|
|
|
|
|
|
|
const FString *Result = CachedTangibles.Find(AssetName);
|
|
|
|
|
if (Result == nullptr) return TEXT("");
|
|
|
|
|
return *Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString UlxAssetLookup::StaticMeshLoadPath(const FName &AssetName) const
|
|
|
|
|
{
|
|
|
|
|
FScopeLock lock(&Mutex);
|
|
|
|
|
|
|
|
|
|
const FString *Result = CachedStaticMeshes.Find(AssetName);
|
|
|
|
|
if (Result == nullptr) return TEXT("");
|
|
|
|
|
return *Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UStaticMesh *UlxAssetLookup::GetStaticMeshByName(const UObject *Context, const FString &Name)
|
|
|
|
|
{
|
|
|
|
|
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
2025-04-02 19:58:16 -04:00
|
|
|
FString Path = mode->GetAssetLookup()->StaticMeshLoadPath(FName(FString("SM_") + Name));
|
2025-04-01 22:31:27 -04:00
|
|
|
if (Path.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Static mesh not on search path: %s"), *Name);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FString FullPath = Path;
|
|
|
|
|
UStaticMesh *Result = LoadObject<UStaticMesh>(nullptr, *FullPath);
|
|
|
|
|
if (Result == nullptr) {
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load static mesh: %s"), *FullPath);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UClass *UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FString &Name) {
|
|
|
|
|
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
2025-04-02 19:58:16 -04:00
|
|
|
FString Path = mode->GetAssetLookup()->TangibleLoadPath(FName(FString("TAN_") + Name));
|
2025-04-01 22:31:27 -04:00
|
|
|
if (Path.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible not on search path: %s"), *Name);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
FString FullPath = Path + TEXT("_C");
|
|
|
|
|
UClass *Result = LoadObject<UClass>(nullptr, *FullPath);
|
|
|
|
|
if (Result == nullptr) {
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load tangible class: %s"), *FullPath);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (!Result->IsChildOf(AActor::StaticClass())) {
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible class is not an actor: %s"), *FullPath);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
UFunction *aqchanged = Result->FindFunctionByName(FName(TEXT("Animation Queue Changed")));
|
|
|
|
|
if ((aqchanged == nullptr)||(aqchanged->ParmsSize != 0))
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible does not have 'Animation Queue Changed' function: %s"), *FullPath);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
return Result;
|
|
|
|
|
}
|