Files
UnrealEngine/Engine/Source/Editor/UnrealEd/Private/Subsystems/UnrealEditorSubsystem.cpp
Brandyn / Techy fcc1b09210 init
2026-04-04 15:40:51 -05:00

90 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Subsystems/UnrealEditorSubsystem.h"
#include "Editor.h"
#include "SLevelViewport.h"
#include "LevelEditor.h"
#include "Utils.h"
#include "GameFramework/Actor.h"
#include "EditorScriptingHelpers.h"
#include UE_INLINE_GENERATED_CPP_BY_NAME(UnrealEditorSubsystem)
namespace InternalUnrealEditorSubsystemLibrary
{
UWorld* GetEditorWorld()
{
return GEditor ? GEditor->GetEditorWorldContext(false).World() : nullptr;
}
UWorld* GetGameWorld()
{
if (GEditor)
{
if (FWorldContext* WorldContext = GEditor->GetPIEWorldContext())
{
return WorldContext->World();
}
return nullptr;
}
return GWorld;
}
}
bool UUnrealEditorSubsystem::GetLevelViewportCameraInfo(FVector& CameraLocation, FRotator& CameraRotation)
{
bool RetVal = false;
CameraLocation = FVector::ZeroVector;
CameraRotation = FRotator::ZeroRotator;
for (FLevelEditorViewportClient* LevelVC : GEditor->GetLevelViewportClients())
{
if (LevelVC && LevelVC->IsPerspective())
{
CameraLocation = LevelVC->GetViewLocation();
CameraRotation = LevelVC->GetViewRotation();
RetVal = true;
break;
}
}
return RetVal;
}
void UUnrealEditorSubsystem::SetLevelViewportCameraInfo(FVector CameraLocation, FRotator CameraRotation)
{
for (FLevelEditorViewportClient* LevelVC : GEditor->GetLevelViewportClients())
{
if (LevelVC && LevelVC->IsPerspective())
{
LevelVC->SetViewLocationForOrbiting(CameraLocation);
LevelVC->SetViewLocation(CameraLocation);
LevelVC->SetViewRotation(CameraRotation);
break;
}
}
}
UWorld* UUnrealEditorSubsystem::GetEditorWorld()
{
TGuardValue<bool> UnattendedScriptGuard(GIsRunningUnattendedScript, true);
if (!EditorScriptingHelpers::CheckIfInEditorAndPIE())
{
return nullptr;
}
return InternalUnrealEditorSubsystemLibrary::GetEditorWorld();
}
UWorld* UUnrealEditorSubsystem::GetGameWorld()
{
TGuardValue<bool> UnattendedScriptGuard(GIsRunningUnattendedScript, true);
return InternalUnrealEditorSubsystemLibrary::GetGameWorld();
}