123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // Copyright 2017-2021 marynate. All Rights Reserved.
- #pragma once
- #include "CoreMinimal.h"
- #include "AssetRegistry/ARFilter.h"
- #include "CollectionManagerTypes.h"
- #include "ICollectionManager.h"
- #include "CollectionManagerModule.h"
- struct FSourcesData
- {
- TArray<FName> PackagePaths;
- TArray<FCollectionNameType> Collections;
- FSourcesData()
- : PackagePaths()
- , Collections()
- {
- }
- explicit FSourcesData(FName InPackagePath)
- : PackagePaths()
- , Collections()
- {
- PackagePaths.Add(InPackagePath);
- }
- explicit FSourcesData(FCollectionNameType InCollection)
- : PackagePaths()
- , Collections()
- {
- Collections.Add(InCollection);
- }
- FSourcesData(TArray<FName> InPackagePaths, TArray<FCollectionNameType> InCollections)
- : PackagePaths(MoveTemp(InPackagePaths))
- , Collections(MoveTemp(InCollections))
- {
- }
- FSourcesData(const FSourcesData& Other)
- : PackagePaths(Other.PackagePaths)
- , Collections(Other.Collections)
- {
- }
- FSourcesData(FSourcesData&& Other)
- : PackagePaths(MoveTemp(Other.PackagePaths))
- , Collections(MoveTemp(Other.Collections))
- {
- }
- FSourcesData& operator=(const FSourcesData& Other)
- {
- if (this != &Other)
- {
- PackagePaths = Other.PackagePaths;
- Collections = Other.Collections;
- }
- return *this;
- }
- FSourcesData& operator=(FSourcesData&& Other)
- {
- if (this != &Other)
- {
- PackagePaths = MoveTemp(Other.PackagePaths);
- Collections = MoveTemp(Other.Collections);
- }
- return *this;
- }
- FORCEINLINE bool IsEmpty() const
- {
- return PackagePaths.Num() == 0 && Collections.Num() == 0;
- }
- FORCEINLINE bool HasPackagePaths() const
- {
- return PackagePaths.Num() > 0;
- }
- FORCEINLINE bool HasCollections() const
- {
- return Collections.Num() > 0;
- }
- bool IsDynamicCollection() const
- {
- if ( Collections.Num() == 1 && FCollectionManagerModule::IsModuleAvailable() )
- {
- // Collection manager module should already be loaded since it may cause a hitch on the first search
- FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
- ECollectionStorageMode::Type StorageMode = ECollectionStorageMode::Static;
- return (CollectionManagerModule.Get().GetCollectionStorageMode(Collections[0].Name, Collections[0].Type, StorageMode) && StorageMode == ECollectionStorageMode::Dynamic);
- }
- return false;
- }
- FARFilter MakeFilter(bool bRecurse, bool bUsingFolders) const
- {
- FARFilter Filter;
- // Package Paths
- Filter.PackagePaths = PackagePaths;
- Filter.bRecursivePaths = bRecurse || !bUsingFolders;
- // If we have a dynamic source, then we need to make sure that the root path is searched for matching objects as the dynamic filter will sort through them
- if (IsDynamicCollection())
- {
- Filter.PackagePaths.AddUnique(TEXT("/"));
- }
- // Collections
- TArray<FSoftObjectPath> ObjectPaths;
- if ( Collections.Num() && FCollectionManagerModule::IsModuleAvailable() )
- {
- // Collection manager module should already be loaded since it may cause a hitch on the first search
- FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
- // Include objects from child collections if we're recursing
- const ECollectionRecursionFlags::Flags CollectionRecursionMode = (Filter.bRecursivePaths) ? ECollectionRecursionFlags::SelfAndChildren : ECollectionRecursionFlags::Self;
- for ( int32 CollectionIdx = 0; CollectionIdx < Collections.Num(); ++CollectionIdx )
- {
- // Find the collection
- const FCollectionNameType& CollectionNameType = Collections[CollectionIdx];
- CollectionManagerModule.Get().GetObjectsInCollection(CollectionNameType.Name, CollectionNameType.Type, ObjectPaths, CollectionRecursionMode);
- }
- }
- Filter.SoftObjectPaths = ObjectPaths;
- return Filter;
- }
- };
|