You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#rb none Should be just copyright updates [CL 4680440 by Marcus Wassmer in Dev-Rendering branch]
122 lines
2.8 KiB
C++
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);
|
|
}
|