49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "WingServer.h"
|
|
#include "WingHandler.h"
|
|
#include "WingFetcher.h"
|
|
#include "Editor.h"
|
|
#include "Subsystems/AssetEditorSubsystem.h"
|
|
#include "Editor_OpenAsset.generated.h"
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------
|
|
|
|
UCLASS()
|
|
class UWing_Editor_OpenAsset : public UWingHandler
|
|
{
|
|
GENERATED_BODY()
|
|
|
|
public:
|
|
UPROPERTY(EditAnywhere, meta=(Description="Asset to open"))
|
|
FString Asset;
|
|
|
|
virtual void Register() override
|
|
{
|
|
UWingServer::AddHandler(this,
|
|
TEXT("Open an asset in its editor and bring it to focus."));
|
|
}
|
|
virtual void Handle() override
|
|
{
|
|
WingFetcher F(WingOut::Stdout);
|
|
UObject* Obj = F.Walk(Asset).Cast<UObject>();
|
|
if (!Obj) return;
|
|
|
|
UAssetEditorSubsystem* Sub = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
|
if (!Sub)
|
|
{
|
|
WingOut::Stdout.Print(TEXT("Error: AssetEditorSubsystem not available\n"));
|
|
return;
|
|
}
|
|
|
|
if (Sub->OpenEditorForAsset(Obj))
|
|
WingOut::Stdout.Printf(TEXT("Opened editor for %s\n"), *Obj->GetPathName());
|
|
else
|
|
WingOut::Stdout.Printf(TEXT("Error: Could not open editor for %s\n"), *Obj->GetPathName());
|
|
}
|
|
};
|