70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "WingServer.h"
|
|
#include "WingHandler.h"
|
|
#include "WingUtils.h"
|
|
#include "AssetRegistry/AssetData.h"
|
|
#include "AssetRegistry/IAssetRegistry.h"
|
|
#include "Asset_FindReferences.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UWing_Asset_FindReferences : public UObject, public IWingHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="Asset to find references for"))
|
|
FString Asset;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Find all assets that reference a given asset.");
|
|
}
|
|
|
|
virtual void Handle() override
|
|
{
|
|
IAssetRegistry& Registry = *IAssetRegistry::Get();
|
|
|
|
// Verify the asset exists
|
|
FAssetData AssetData = Registry.GetAssetByObjectPath(FSoftObjectPath(Asset));
|
|
if (!AssetData.IsValid())
|
|
{
|
|
UWingServer::Printf(TEXT("ERROR: Asset not found: %s\n"), *Asset);
|
|
return;
|
|
}
|
|
|
|
TArray<FName> Referencers;
|
|
Registry.GetReferencers(FName(*Asset), Referencers);
|
|
|
|
if (Referencers.Num() == 0)
|
|
{
|
|
UWingServer::Print(TEXT("No referencers found.\n"));
|
|
return;
|
|
}
|
|
|
|
// Classify referencers by looking up their asset class
|
|
for (const FName& Ref : Referencers)
|
|
{
|
|
FString RefStr = Ref.ToString();
|
|
TArray<FAssetData> RefAssets;
|
|
Registry.GetAssetsByPackageName(Ref, RefAssets);
|
|
if (RefAssets.Num() > 0)
|
|
{
|
|
UWingServer::Printf(TEXT("%s %s\n"),
|
|
*WingUtils::FormatName(RefAssets[0].GetClass()),
|
|
*RefStr);
|
|
}
|
|
else
|
|
{
|
|
UWingServer::Printf(TEXT("Unknown %s\n"), *RefStr);
|
|
}
|
|
}
|
|
}
|
|
};
|