SourcesData.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright 2017-2021 marynate. All Rights Reserved.
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "AssetRegistry/ARFilter.h"
  5. #include "CollectionManagerTypes.h"
  6. #include "ICollectionManager.h"
  7. #include "CollectionManagerModule.h"
  8. struct FSourcesData
  9. {
  10. TArray<FName> PackagePaths;
  11. TArray<FCollectionNameType> Collections;
  12. FSourcesData()
  13. : PackagePaths()
  14. , Collections()
  15. {
  16. }
  17. explicit FSourcesData(FName InPackagePath)
  18. : PackagePaths()
  19. , Collections()
  20. {
  21. PackagePaths.Add(InPackagePath);
  22. }
  23. explicit FSourcesData(FCollectionNameType InCollection)
  24. : PackagePaths()
  25. , Collections()
  26. {
  27. Collections.Add(InCollection);
  28. }
  29. FSourcesData(TArray<FName> InPackagePaths, TArray<FCollectionNameType> InCollections)
  30. : PackagePaths(MoveTemp(InPackagePaths))
  31. , Collections(MoveTemp(InCollections))
  32. {
  33. }
  34. FSourcesData(const FSourcesData& Other)
  35. : PackagePaths(Other.PackagePaths)
  36. , Collections(Other.Collections)
  37. {
  38. }
  39. FSourcesData(FSourcesData&& Other)
  40. : PackagePaths(MoveTemp(Other.PackagePaths))
  41. , Collections(MoveTemp(Other.Collections))
  42. {
  43. }
  44. FSourcesData& operator=(const FSourcesData& Other)
  45. {
  46. if (this != &Other)
  47. {
  48. PackagePaths = Other.PackagePaths;
  49. Collections = Other.Collections;
  50. }
  51. return *this;
  52. }
  53. FSourcesData& operator=(FSourcesData&& Other)
  54. {
  55. if (this != &Other)
  56. {
  57. PackagePaths = MoveTemp(Other.PackagePaths);
  58. Collections = MoveTemp(Other.Collections);
  59. }
  60. return *this;
  61. }
  62. FORCEINLINE bool IsEmpty() const
  63. {
  64. return PackagePaths.Num() == 0 && Collections.Num() == 0;
  65. }
  66. FORCEINLINE bool HasPackagePaths() const
  67. {
  68. return PackagePaths.Num() > 0;
  69. }
  70. FORCEINLINE bool HasCollections() const
  71. {
  72. return Collections.Num() > 0;
  73. }
  74. bool IsDynamicCollection() const
  75. {
  76. if ( Collections.Num() == 1 && FCollectionManagerModule::IsModuleAvailable() )
  77. {
  78. // Collection manager module should already be loaded since it may cause a hitch on the first search
  79. FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
  80. ECollectionStorageMode::Type StorageMode = ECollectionStorageMode::Static;
  81. return (CollectionManagerModule.Get().GetCollectionStorageMode(Collections[0].Name, Collections[0].Type, StorageMode) && StorageMode == ECollectionStorageMode::Dynamic);
  82. }
  83. return false;
  84. }
  85. FARFilter MakeFilter(bool bRecurse, bool bUsingFolders) const
  86. {
  87. FARFilter Filter;
  88. // Package Paths
  89. Filter.PackagePaths = PackagePaths;
  90. Filter.bRecursivePaths = bRecurse || !bUsingFolders;
  91. // 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
  92. if (IsDynamicCollection())
  93. {
  94. Filter.PackagePaths.AddUnique(TEXT("/"));
  95. }
  96. // Collections
  97. TArray<FSoftObjectPath> ObjectPaths;
  98. if ( Collections.Num() && FCollectionManagerModule::IsModuleAvailable() )
  99. {
  100. // Collection manager module should already be loaded since it may cause a hitch on the first search
  101. FCollectionManagerModule& CollectionManagerModule = FCollectionManagerModule::GetModule();
  102. // Include objects from child collections if we're recursing
  103. const ECollectionRecursionFlags::Flags CollectionRecursionMode = (Filter.bRecursivePaths) ? ECollectionRecursionFlags::SelfAndChildren : ECollectionRecursionFlags::Self;
  104. for ( int32 CollectionIdx = 0; CollectionIdx < Collections.Num(); ++CollectionIdx )
  105. {
  106. // Find the collection
  107. const FCollectionNameType& CollectionNameType = Collections[CollectionIdx];
  108. CollectionManagerModule.Get().GetObjectsInCollection(CollectionNameType.Name, CollectionNameType.Type, ObjectPaths, CollectionRecursionMode);
  109. }
  110. }
  111. Filter.SoftObjectPaths = ObjectPaths;
  112. return Filter;
  113. }
  114. };