Lots of work on look-at widgets
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
#include "AssetRegistry/AssetData.h"
|
||||
#include "AssetRegistry/AssetRegistryState.h"
|
||||
#include "LuprexGameModeBase.h"
|
||||
#include "Components/Widget.h"
|
||||
#include "WidgetBlueprint.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
|
||||
void UlxAssetLookup::RebuildIndex()
|
||||
{
|
||||
@@ -12,6 +15,7 @@ void UlxAssetLookup::RebuildIndex()
|
||||
IAssetRegistry::GetChecked().WaitForCompletion();
|
||||
ScanTangibles();
|
||||
ScanStaticMeshes();
|
||||
ScanWidgets();
|
||||
}
|
||||
|
||||
void UlxAssetLookup::ScanTangibles()
|
||||
@@ -27,7 +31,7 @@ void UlxAssetLookup::ScanTangibles()
|
||||
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d assets in /Game/Tangibles"), FoundData.Num());
|
||||
for (const FAssetData &Data : FoundData)
|
||||
{
|
||||
FString Path = Data.GetObjectPathString();
|
||||
FString Path = Data.GetObjectPathString() + TEXT("_C");
|
||||
CachedTangibles.Add(Data.AssetName, Path);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +46,7 @@ void UlxAssetLookup::ScanStaticMeshes()
|
||||
AssetFilter.bRecursivePaths = true;
|
||||
IAssetRegistry::GetChecked().GetAssets(AssetFilter, FoundData);
|
||||
|
||||
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d static mesh assets"), FoundData.Num());
|
||||
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d assets in /Game/StaticMeshes"), FoundData.Num());
|
||||
for (const FAssetData &Data : FoundData)
|
||||
{
|
||||
FString Path = Data.GetObjectPathString();
|
||||
@@ -50,10 +54,26 @@ void UlxAssetLookup::ScanStaticMeshes()
|
||||
}
|
||||
}
|
||||
|
||||
void UlxAssetLookup::ScanWidgets()
|
||||
{
|
||||
TArray<FAssetData> FoundData;
|
||||
FARFilter AssetFilter;
|
||||
AssetFilter.PackagePaths.Add(FName(TEXT("/Game/Widgets")));
|
||||
AssetFilter.ClassPaths.Add(UWidgetBlueprint::StaticClass()->GetClassPathName());
|
||||
AssetFilter.bIncludeOnlyOnDiskAssets = true;
|
||||
AssetFilter.bRecursivePaths = true;
|
||||
IAssetRegistry::GetChecked().GetAssets(AssetFilter, FoundData);
|
||||
|
||||
UE_LOG(LogLuprexIntegration, Display, TEXT("Found %d assets in /Game/Widgets"), FoundData.Num());
|
||||
for (const FAssetData &Data : FoundData)
|
||||
{
|
||||
FString Path = Data.GetObjectPathString() + TEXT("_C");
|
||||
CachedWidgets.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;
|
||||
@@ -61,13 +81,18 @@ FString UlxAssetLookup::TangibleLoadPath(const FName &AssetName) const
|
||||
|
||||
FString UlxAssetLookup::StaticMeshLoadPath(const FName &AssetName) const
|
||||
{
|
||||
FScopeLock lock(&Mutex);
|
||||
|
||||
const FString *Result = CachedStaticMeshes.Find(AssetName);
|
||||
if (Result == nullptr) return TEXT("");
|
||||
return *Result;
|
||||
}
|
||||
|
||||
FString UlxAssetLookup::WidgetLoadPath(const FName &AssetName) const
|
||||
{
|
||||
const FString *Result = CachedWidgets.Find(AssetName);
|
||||
if (Result == nullptr) return TEXT("");
|
||||
return *Result;
|
||||
}
|
||||
|
||||
UStaticMesh *UlxAssetLookup::GetStaticMeshByName(const UObject *Context, const FString &Name)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
||||
@@ -77,18 +102,16 @@ UStaticMesh *UlxAssetLookup::GetStaticMeshByName(const UObject *Context, const F
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Static mesh not on search path: %s"), *Name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FString FullPath = Path;
|
||||
UStaticMesh *Result = LoadObject<UStaticMesh>(nullptr, *FullPath);
|
||||
UStaticMesh *Result = LoadObject<UStaticMesh>(nullptr, *Path);
|
||||
if (Result == nullptr) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load static mesh: %s"), *FullPath);
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load static mesh: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
UClass *UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FString &Name) {
|
||||
TSubclassOf<AActor> UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FString &Name) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
||||
FString Path = mode->GetAssetLookup()->TangibleLoadPath(FName(FString("TAN_") + Name));
|
||||
if (Path.IsEmpty())
|
||||
@@ -96,21 +119,61 @@ UClass *UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FSt
|
||||
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);
|
||||
UClass *Result = LoadObject<UClass>(nullptr, *Path);
|
||||
if (Result == nullptr) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load tangible class: %s"), *FullPath);
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load tangible class: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
if (!Result->IsChildOf(AActor::StaticClass())) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible class is not an actor: %s"), *FullPath);
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible class is not an actor: %s"), *Path);
|
||||
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);
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible does not have 'Animation Queue Changed' function: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
TSubclassOf<UUserWidget> UlxAssetLookup::GetWidgetByName(const UObject *Context, const FString &Name) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
||||
FString Path = mode->GetAssetLookup()->WidgetLoadPath(FName(FString("WB_") + Name));
|
||||
if (Path.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Widget not on search path: %s"), *Name);
|
||||
return nullptr;
|
||||
}
|
||||
UClass *Result = LoadObject<UClass>(nullptr, *Path);
|
||||
if (Result == nullptr) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load widget blueprint: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
if (!Result->IsChildOf(UUserWidget::StaticClass())) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Blueprint is not a Widget Blueprint: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
TSubclassOf<UlxLookAtWidget> UlxAssetLookup::GetLookAtWidgetByName(const UObject *Context, const FString &Name) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
|
||||
FString Path = mode->GetAssetLookup()->WidgetLoadPath(FName(FString("WB_") + Name));
|
||||
if (Path.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Widget not on search path: %s"), *Name);
|
||||
return nullptr;
|
||||
}
|
||||
UClass *Result = LoadObject<UClass>(nullptr, *Path);
|
||||
if (Result == nullptr) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load widget blueprint: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
if (!Result->IsChildOf(UlxLookAtWidget::StaticClass())) {
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("Blueprint is not a Luprex Look-At Widget: %s"), *Path);
|
||||
return nullptr;
|
||||
}
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user