Files
UnrealEngineUWP/Engine/Source/Editor/AssetDefinition/Private/AssetDefinition.cpp

169 lines
6.2 KiB
C++
Raw Normal View History

AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "AssetDefinition.h"
#include "AssetDefinitionRegistry.h"
#include "Misc/AssetFilterData.h"
#include "EditorFramework/AssetImportData.h"
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
#define LOCTEXT_NAMESPACE "UAssetDefinition"
FAssetCategoryPath EAssetCategoryPaths::Basic(LOCTEXT("Basic", "Basic"));
FAssetCategoryPath EAssetCategoryPaths::Animation(LOCTEXT("Animation", "Animation"));
FAssetCategoryPath EAssetCategoryPaths::Material(LOCTEXT("Material", "Material"));
FAssetCategoryPath EAssetCategoryPaths::Audio(LOCTEXT("Audio", "Audio"));
FAssetCategoryPath EAssetCategoryPaths::Physics(LOCTEXT("Physics", "Physics"));
FAssetCategoryPath EAssetCategoryPaths::UI(LOCTEXT("UserInterface", "User Interface"));
FAssetCategoryPath EAssetCategoryPaths::Misc(LOCTEXT("Miscellaneous", "Miscellaneous"));
FAssetCategoryPath EAssetCategoryPaths::Gameplay(LOCTEXT("Gameplay", "Gameplay"));
FAssetCategoryPath EAssetCategoryPaths::AI(LOCTEXT("AI", "Artificial Intelligence"));
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
FAssetCategoryPath EAssetCategoryPaths::Blueprint(LOCTEXT("Blueprint", "Blueprint"));
FAssetCategoryPath EAssetCategoryPaths::Texture(LOCTEXT("Texture", "Texture"));
FAssetCategoryPath EAssetCategoryPaths::Foliage(LOCTEXT("Foliage", "Foliage"));
FAssetCategoryPath EAssetCategoryPaths::Input(LOCTEXT("Input", "Input"));
FAssetCategoryPath EAssetCategoryPaths::FX(LOCTEXT("FX", "FX"));
FAssetCategoryPath EAssetCategoryPaths::Cinematics(LOCTEXT("Cinematics", "Cinematics"));
FAssetCategoryPath EAssetCategoryPaths::Media(LOCTEXT("Media", "Media"));
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
FAssetCategoryPath::FAssetCategoryPath(const FText& InCategory)
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
{
CategoryPath = { TPair<FName, FText>(FName(*FTextInspector::GetSourceString(InCategory)), InCategory) };
}
FAssetCategoryPath::FAssetCategoryPath(const FText& InCategory, const FText& InSubCategory)
{
CategoryPath = {
TPair<FName, FText>(FName(*FTextInspector::GetSourceString(InCategory)), InCategory),
TPair<FName, FText>(FName(*FTextInspector::GetSourceString(InSubCategory)), InSubCategory)
};
}
FAssetCategoryPath::FAssetCategoryPath(const FAssetCategoryPath& InCategory, const FText& InSubCategory)
{
CategoryPath.Append(InCategory.CategoryPath);
CategoryPath.Add(TPair<FName, FText>(FName(*FTextInspector::GetSourceString(InSubCategory)), InSubCategory));
}
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
FAssetCategoryPath::FAssetCategoryPath(TConstArrayView<FText> InCategoryPath)
{
check(InCategoryPath.Num() > 0);
for (const FText& CategoryChunk : InCategoryPath)
{
CategoryPath.Add(TPair<FName, FText>(FName(*FTextInspector::GetSourceString(CategoryChunk)), CategoryChunk));
}
}
// UAssetDefinition
//---------------------------------------------------------------------------
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
UAssetDefinition::UAssetDefinition()
{
}
void UAssetDefinition::PostCDOContruct()
{
Super::PostCDOContruct();
if (CanRegisterStatically())
{
UAssetDefinitionRegistry::Get()->RegisterAssetDefinition(this);
}
}
TConstArrayView<FAssetCategoryPath> UAssetDefinition::GetAssetCategories() const
{
static const auto Categories = { EAssetCategoryPaths::Misc };
return Categories;
}
EAssetCommandResult UAssetDefinition::GetSourceFiles(const FAssetSourceFilesArgs& InArgs, TFunctionRef<bool(const FAssetSourceFilesResult& InSourceFile)> SourceFileFunc) const
{
bool bFoundSomeData = false;
FString SourceFileTagData;
FAssetSourceFilesResult Result;
for (const FAssetData& Asset : InArgs.Assets)
{
if (Asset.GetTagValue(UObject::SourceFileTagName(), SourceFileTagData))
{
TOptional<FAssetImportInfo> ImportInfoOptional = FAssetImportInfo::FromJson(SourceFileTagData);
if (ImportInfoOptional.IsSet())
{
bFoundSomeData = true;
FAssetImportInfo& ImportInfo = ImportInfoOptional.GetValue();
for (FAssetImportInfo::FSourceFile& SourceFiles : ImportInfo.SourceFiles)
{
Result.FilePath = MoveTemp(SourceFiles.RelativeFilename);
Result.DisplayLabel = MoveTemp(SourceFiles.DisplayLabelName);
Result.Timestamp = MoveTemp(SourceFiles.Timestamp);
Result.FileHash = MoveTemp(SourceFiles.FileHash);
if (InArgs.FilePathFormat == EPathUse::AbsolutePath)
{
Result.FilePath = UAssetImportData::ResolveImportFilename(FStringView(Result.FilePath), Asset.PackageName.ToString());
}
if (!SourceFileFunc(Result))
{
return EAssetCommandResult::Handled;
}
}
}
}
}
return bFoundSomeData ? EAssetCommandResult::Handled : EAssetCommandResult::Unhandled;
}
EAssetCommandResult UAssetDefinition::GetSourceFiles(const FAssetData& InAsset, TFunctionRef<void(const FAssetImportInfo& AssetImportData)> SourceFileFunc) const
{
FString SourceFileTagData;
if (InAsset.GetTagValue(UObject::SourceFileTagName(), SourceFileTagData))
{
TOptional<FAssetImportInfo> ImportInfo = FAssetImportInfo::FromJson(SourceFileTagData);
if (ImportInfo.IsSet())
{
SourceFileFunc(ImportInfo.GetValue());
return EAssetCommandResult::Handled;
}
}
return EAssetCommandResult::Unhandled;
}
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
bool UAssetDefinition::CanRegisterStatically() const
{
return !GetClass()->HasAnyClassFlags(CLASS_Abstract);
}
void UAssetDefinition::BuildFilters(TArray<FAssetFilterData>& OutFilters) const
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
{
const TSoftClassPtr<UObject> AssetClassPtr = GetAssetClass();
if (const UClass* AssetClass = AssetClassPtr.Get())
{
// If this asset definition doesn't have any categories it can't have any filters. Filters need to have a
// category to be displayed.
if (GetAssetCategories().Num() == 0)
{
return;
}
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
// By default we don't advertise filtering if the class is abstract for the asset definition. Odds are,
// if they've registered an abstract class as an asset definition, they mean to use it for subclasses.
if (IncludeClassInFilter == EIncludeClassInFilter::Always || (IncludeClassInFilter == EIncludeClassInFilter::IfClassIsNotAbstract && !AssetClass->HasAnyClassFlags(CLASS_Abstract)))
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
{
FAssetFilterData DefaultFilter;
DefaultFilter.Name = AssetClassPtr.ToSoftObjectPath().ToString();
DefaultFilter.DisplayText = GetAssetDisplayName();
DefaultFilter.FilterCategories = GetAssetCategories();
AssetDefinition - This is the seed of a long term replacement of IAssetTypeActions. IAssetTypeActions is woefully inadiquit now. It puts a lot of functionality in one place, which wouldn't be a terrible thing, except for the GetActions, and some of the menu stuff being built into this class. We need to make an effort to not have to load every single asset just to open the context menu you have selected, to-wit, a previous CL made it so that summoning the menu no longer *Had* to load the assets, however several remaining issues remained with the Blueprint Utility Actions, and the fact that we don't "KNOW" if we need to call GetActions for an asset. We could introduce a replacement in the class, but that would just get inherited, causing other issues. So instead the parallel UObject based AssetDefinition now exists. In large part it will probably be very similar to the other one, but several things in it probably need to chnage. For now there is a bridging concept in the form of the AssetDefinitionAssetTypeProxy. 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]
2022-11-10 13:13:41 -05:00
DefaultFilter.Filter.ClassPaths.Add(AssetClassPtr.ToSoftObjectPath().GetAssetPath());
DefaultFilter.Filter.bRecursiveClasses = true;
OutFilters.Add(MoveTemp(DefaultFilter));
}
}
}
#undef LOCTEXT_NAMESPACE