RealtimeStyleTransferRuntime/Source/LyraGame/System/LyraActorUtilities.cpp

44 lines
1.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "LyraActorUtilities.h"
#include "Components/ActorComponent.h"
#include "Engine/EngineBaseTypes.h"
#include "GameFramework/Actor.h"
#include "Misc/AssertionMacros.h"
#include "Templates/Casts.h"
#include "UObject/Object.h"
EBlueprintExposedNetMode ULyraActorUtilities::SwitchOnNetMode(const UObject* WorldContextObject)
{
ENetMode NetMode = NM_Standalone;
for (const UObject* TestObject = WorldContextObject; TestObject != nullptr; TestObject = TestObject->GetOuter())
{
if (const UActorComponent* Component = Cast<const UActorComponent>(WorldContextObject))
{
NetMode = Component->GetNetMode();
break;
}
else if (const AActor* Actor = Cast<const AActor>(WorldContextObject))
{
NetMode = Actor->GetNetMode();
break;
}
}
switch (NetMode)
{
case NM_Client:
return EBlueprintExposedNetMode::Client;
case NM_Standalone:
return EBlueprintExposedNetMode::Standalone;
case NM_DedicatedServer:
return EBlueprintExposedNetMode::DedicatedServer;
case NM_ListenServer:
return EBlueprintExposedNetMode::ListenServer;
default:
ensure(false);
return EBlueprintExposedNetMode::Standalone;
}
}