48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "MCPHandler.h"
|
|
#include "MCPFetcher.h"
|
|
#include "Editor.h"
|
|
#include "Subsystems/AssetEditorSubsystem.h"
|
|
#include "Editor_OpenAsset.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UMCP_Editor_OpenAsset : public UObject, public IMCPHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(meta=(Description="MCPFetcher path to the asset to open (e.g. /Game/Materials/M_Gold)"))
|
|
FString Path;
|
|
|
|
virtual FString GetDescription() const override
|
|
{
|
|
return TEXT("Open an asset in its editor and bring it to focus.");
|
|
}
|
|
|
|
virtual void Handle(FStringBuilderBase& Result) override
|
|
{
|
|
MCPFetcher F(Result);
|
|
UObject* Obj = F.Walk(Path).Cast<UObject>();
|
|
if (!Obj) return;
|
|
|
|
UAssetEditorSubsystem* Sub = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
|
if (!Sub)
|
|
{
|
|
Result.Append(TEXT("Error: AssetEditorSubsystem not available\n"));
|
|
return;
|
|
}
|
|
|
|
if (Sub->OpenEditorForAsset(Obj))
|
|
Result.Appendf(TEXT("Opened editor for %s\n"), *Obj->GetPathName());
|
|
else
|
|
Result.Appendf(TEXT("Error: Could not open editor for %s\n"), *Obj->GetPathName());
|
|
}
|
|
};
|