Files
UnrealEngineUWP/Engine/Source/Runtime/NavigationSystem/Private/NavRelevantComponent.cpp
Marcus Wassmer cbfcbbb93b Merging //UE4/Dev-Main@4662404 to Dev-Rendering (//UE4/Dev-Rendering)
#rb none
Should be just copyright updates

[CL 4680440 by Marcus Wassmer in Dev-Rendering branch]
2019-01-03 19:16:26 -05:00

122 lines
2.8 KiB
C++

// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "NavRelevantComponent.h"
#include "NavigationSystem.h"
UNavRelevantComponent::UNavRelevantComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
bCanEverAffectNavigation = true;
bNavigationRelevant = true;
bAttachToOwnersRoot = true;
bBoundsInitialized = false;
}
void UNavRelevantComponent::OnRegister()
{
Super::OnRegister();
if (bAttachToOwnersRoot)
{
bool bUpdateCachedParent = true;
#if WITH_EDITOR
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if (NavSys && NavSys->IsNavigationRegisterLocked())
{
bUpdateCachedParent = false;
}
#endif
AActor* OwnerActor = GetOwner();
if (OwnerActor && bUpdateCachedParent)
{
// attach to root component if it's relevant for navigation
UActorComponent* ActorComp = OwnerActor->GetRootComponent();
INavRelevantInterface* NavInterface = ActorComp ? Cast<INavRelevantInterface>(ActorComp) : nullptr;
if (NavInterface && NavInterface->IsNavigationRelevant() &&
OwnerActor->IsComponentRelevantForNavigation(ActorComp))
{
CachedNavParent = ActorComp;
}
// otherwise try actor itself under the same condition
if (CachedNavParent == nullptr)
{
NavInterface = Cast<INavRelevantInterface>(OwnerActor);
if (NavInterface && NavInterface->IsNavigationRelevant())
{
CachedNavParent = OwnerActor;
}
}
}
}
FNavigationSystem::OnComponentRegistered(*this);
}
void UNavRelevantComponent::OnUnregister()
{
Super::OnUnregister();
FNavigationSystem::OnComponentUnregistered(*this);
}
FBox UNavRelevantComponent::GetNavigationBounds() const
{
if (!bBoundsInitialized)
{
CalcAndCacheBounds();
bBoundsInitialized = true;
}
return Bounds;
}
bool UNavRelevantComponent::IsNavigationRelevant() const
{
return bNavigationRelevant;
}
void UNavRelevantComponent::UpdateNavigationBounds()
{
CalcAndCacheBounds();
bBoundsInitialized = true;
}
UObject* UNavRelevantComponent::GetNavigationParent() const
{
return CachedNavParent;
}
void UNavRelevantComponent::CalcAndCacheBounds() const
{
const AActor* OwnerActor = GetOwner();
const FVector MyLocation = OwnerActor ? OwnerActor->GetActorLocation() : FVector::ZeroVector;
Bounds = FBox::BuildAABB(MyLocation, FVector(100.0f, 100.0f, 100.0f));
}
void UNavRelevantComponent::ForceNavigationRelevancy(bool bForce)
{
bAttachToOwnersRoot = !bForce;
if (bForce)
{
bNavigationRelevant = true;
}
RefreshNavigationModifiers();
}
void UNavRelevantComponent::SetNavigationRelevancy(bool bRelevant)
{
if (bNavigationRelevant != bRelevant)
{
bNavigationRelevant = bRelevant;
RefreshNavigationModifiers();
}
}
void UNavRelevantComponent::RefreshNavigationModifiers()
{
FNavigationSystem::UpdateComponentData(*this);
}