/**
 * Returns a list of all assets referenced by the specified UObject.
 */
void FFindReferencedAssets::BuildAssetList(UObject *Object, const TArray<UClass*>& IgnoreClasses, const TArray<UObject*>& IgnorePackages, TSet<UObject*>& ReferencedAssets, bool bIncludeDefaultRefs)
{
	TArray<FReferencedAssets> LocalReferencers;

	// Create a new entry for this actor.
	new( LocalReferencers ) FReferencedAssets( Object );

	for (FObjectIterator It; It; ++It)
	{
		// Skip the level, world, and any packages that should be ignored
		if ( ShouldSearchForAssets(*It, IgnoreClasses, IgnorePackages, bIncludeDefaultRefs) )
		{
			It->Mark(OBJECTMARK_TagExp);
		}
		else
		{
			It->UnMark(OBJECTMARK_TagExp);
		}
	}

	// Add to the list of referenced assets.
	FFindAssetsArchive( Object, LocalReferencers.Last().AssetList, NULL, /*MaxRecursion=*/0, /*bIncludeClasses=*/true, bIncludeDefaultRefs );

	ReferencedAssets = LocalReferencers.Last().AssetList;
}
示例#2
0
	/**
	 * Builds a list of assets to display from the currently selected actors.
	 * NOTE: It ignores assets that are there because they are always loaded
	 * such as default materials, textures, etc.
	 */
	void BuildAssetList(UWorld* InWorld, int32 Depth, bool bShowDefault, bool bShowScript)
	{
		// Clear the old list
		Referencers.Empty();
		ReferenceGraph.Empty();
		ObjectNameCache.Empty();

		TArray<UObject*> BspMats;
		// Search all BSP surfaces for ones that are selected and add their
		// Materials to a temp list
		for (int32 Index = 0; Index < InWorld->GetModel()->Surfs.Num(); Index++)
		{
			// Only add materials that are selected
			if (InWorld->GetModel()->Surfs[Index].PolyFlags & PF_Selected)
			{
				// No point showing the default material
				if (InWorld->GetModel()->Surfs[Index].Material != NULL)
				{
					BspMats.AddUnique(InWorld->GetModel()->Surfs[Index].Material);
				}
			}
		}
		// If any BSP surfaces are selected
		if (BspMats.Num() > 0)
		{
			FReferencedAssets* Referencer = new(Referencers) FReferencedAssets(InWorld->GetModel());

			// Now copy the array
			Referencer->AssetList = BspMats;
			ReferenceGraph.Add(InWorld->GetModel(), BspMats);
		}

		// This is the maximum depth to use when searching for references
		const int32 MaxRecursionDepth = Depth;

		USelection* ActorSelection = GEditor->GetSelectedActors();

		// Mark all objects so we don't get into an endless recursion
		for (FObjectIterator It; It; ++It)
		{
			// Skip the level, world, and any packages that should be ignored
			if (ShouldSearchForAssets(*It, IgnoreClasses, IgnorePackages, bShowDefault))
			{
				It->Mark(OBJECTMARK_TagExp);
			}
			else
			{
				It->UnMark(OBJECTMARK_TagExp);
			}
		}

		TArray<AActor*> SelectedActors;
		// Get the list of currently selected actors
		ActorSelection->GetSelectedObjects<AActor>(SelectedActors);

		// Build the list of assets from the set of selected actors
		for (int32 Index = 0; Index < SelectedActors.Num(); Index++)
		{
			// Set the flag for the selected item, as it could have actually been cleared by an
			// earlier selected object, which would result in a crash later
			SelectedActors[Index]->Mark(OBJECTMARK_TagExp);

			// Create a new entry for this actor
			FReferencedAssets* Referencer = new(Referencers) FReferencedAssets(SelectedActors[Index]);

			// Add to the list of referenced assets
			FFindAssetsArchive(SelectedActors[Index], Referencer->AssetList, &ReferenceGraph, MaxRecursionDepth, bShowScript, bShowDefault);
		}

		// Rebuild the name cache
		for (int32 RefIndex = 0; RefIndex < Referencers.Num(); RefIndex++)
		{
			FReferencedAssets& Referencer = Referencers[RefIndex];
			if (!ObjectNameCache.Contains(Referencer.Referencer))
			{
				ObjectNameCache.Add(Referencer.Referencer, *Referencer.Referencer->GetName());
			}

			for (int32 AssetIndex = 0; AssetIndex < Referencer.AssetList.Num(); AssetIndex++)
			{
				if (!ObjectNameCache.Contains(Referencer.AssetList[AssetIndex]))
				{
					ObjectNameCache.Add(Referencer.AssetList[AssetIndex], *Referencer.AssetList[AssetIndex]->GetName());
				}
			}
		}
	}