You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Several amounts of effort went into the newer design of UAssetDefinition to make it easier to change over time, more things are structs now for input and output so additional parameters can be added. AssetDefinition module is an editor module instead of being a developer module. AssetDefinition does not include a myraid of things it shouldn't such as the blueprint module and UnrealEd. #jira UE-165574 #preflight 636c0ec4d0174259cca85e37 [CL 23083536 by nick darnell in ue5-main branch]
99 lines
3.0 KiB
C++
99 lines
3.0 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "AssetDefinitionRegistry.h"
|
|
#include "AssetDefinition.h"
|
|
#include "Algo/Accumulate.h"
|
|
#include "AssetRegistry/AssetRegistryHelpers.h"
|
|
#include "Engine/AssetManager.h"
|
|
|
|
UAssetDefinitionRegistry* UAssetDefinitionRegistry::Singleton = nullptr;
|
|
bool UAssetDefinitionRegistry::bHasShutDown = false;
|
|
|
|
UAssetDefinitionRegistry* UAssetDefinitionRegistry::Get()
|
|
{
|
|
if (!Singleton && !bHasShutDown)
|
|
{
|
|
// Required for StartupModule and ShutdownModule to be called and FindModule to list the AssetDefinition module
|
|
FModuleManager::Get().LoadModuleChecked("AssetDefinition");
|
|
|
|
Singleton = NewObject<UAssetDefinitionRegistry>();
|
|
Singleton->AddToRoot();
|
|
check(Singleton);
|
|
}
|
|
|
|
return Singleton;
|
|
}
|
|
|
|
void UAssetDefinitionRegistry::BeginDestroy()
|
|
{
|
|
if (Singleton == this)
|
|
{
|
|
bHasShutDown = true;
|
|
Singleton = nullptr;
|
|
}
|
|
|
|
Super::BeginDestroy();
|
|
}
|
|
|
|
const UAssetDefinition* UAssetDefinitionRegistry::GetAssetDefinitionForAsset(const FAssetData& Asset) const
|
|
{
|
|
const UClass* AssetClass = UAssetRegistryHelpers::FindAssetNativeClass(Asset);
|
|
return GetAssetDefinitionForClass(AssetClass);
|
|
}
|
|
|
|
const UAssetDefinition* UAssetDefinitionRegistry::GetAssetDefinitionForClass(const UClass* Class) const
|
|
{
|
|
while(Class)
|
|
{
|
|
if (const UAssetDefinition* AssetDefinition = AssetDefinitions.FindRef(Class))
|
|
{
|
|
return AssetDefinition;
|
|
}
|
|
|
|
Class = Class->GetSuperClass();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
TArray<TObjectPtr<UAssetDefinition>> UAssetDefinitionRegistry::GetAllAssetDefinitions() const
|
|
{
|
|
TArray<TObjectPtr<UAssetDefinition>> AllAssetDefinitions;
|
|
AssetDefinitions.GenerateValueArray(AllAssetDefinitions);
|
|
return AllAssetDefinitions;
|
|
}
|
|
|
|
void UAssetDefinitionRegistry::RegisterAssetDefinition(UAssetDefinition* AssetDefinition)
|
|
{
|
|
check(AssetDefinition);
|
|
|
|
if (TSoftClassPtr<UObject> SupportedClass = AssetDefinition->GetAssetClass())
|
|
{
|
|
const bool CanAddDefinition =
|
|
!AssetDefinitions.Contains(SupportedClass) ||
|
|
// This hack is basically to ensure that the statically created AssetDefinitions for things like blueprints
|
|
// will work alongside the AssetTypeActions for blueprints until that class can be completely subsumbed.
|
|
(AssetDefinition->CanRegisterStatically() && !AssetDefinitions[SupportedClass]->CanRegisterStatically());
|
|
|
|
// Normally I'd ensure here, we ignore duplicates, but the IAssetTypeActions allowed duplicates.
|
|
if (CanAddDefinition)
|
|
{
|
|
AssetDefinitions.Add(SupportedClass, AssetDefinition);
|
|
}
|
|
else
|
|
{
|
|
UAssetDefinition* ExistingDefinition = AssetDefinitions[SupportedClass];
|
|
//UE_LOG(LogTemp, Warning, TEXT("Unable to register %s for (%s), %s is already registered"), *GetPathNameSafe(AssetDefinition), *SupportedClass.ToString(), *GetPathNameSafe(ExistingDefinition));
|
|
}
|
|
}
|
|
}
|
|
|
|
void UAssetDefinitionRegistry::UnregisterAssetDefinition(UAssetDefinition* AssetDefinition)
|
|
{
|
|
check(AssetDefinition);
|
|
|
|
if (TSoftClassPtr<UObject> SupportedClass = AssetDefinition->GetAssetClass())
|
|
{
|
|
AssetDefinitions.Remove(SupportedClass);
|
|
}
|
|
} |