Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright 2021 Glass Bottom Games, all rights reserved, also all lefts reserved because Megan Fox is left-handed so it's only right, wait, oh no
- #include "SurfaceableCustomNavLinkComponent.h"
- #include "UObject/ConstructorHelpers.h"
- #include "NavigationSystem.h"
- #include "NavigationSystemTypes.h"
- #include "AI/NavigationSystemHelpers.h"
- #include "Navigation/PathFollowingComponent.h"
- #if WITH_EDITOR
- void USurfaceableCustomNavLinkComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
- {
- static const FName NAME_SmartLinkIsRelevant = GET_MEMBER_NAME_CHECKED(USurfaceableCustomNavLinkComponent, bSmartLinkIsRelevant);
- bool bUpdateInNavOctree = false;
- if (PropertyChangedEvent.GetPropertyName() == NAME_SmartLinkIsRelevant)
- {
- SetNavigationRelevancy(bSmartLinkIsRelevant);
- bUpdateInNavOctree = true;
- }
- if (bUpdateInNavOctree && (GetOwner() != NULL))
- {
- UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
- if (NavSys)
- {
- NavSys->UpdateActorInNavOctree(*GetOwner());
- }
- }
- Super::PostEditChangeProperty(PropertyChangedEvent);
- }
- #endif // WITH_EDITOR
- void USurfaceableCustomNavLinkComponent::OnRegister()
- {
- Super::OnRegister();
- // We want to wait until after registration has happened, to do this, since that's the pattern used by NavLinkProxy (an Actor)
- SetNavigationRelevancy(bSmartLinkIsRelevant);
- }
- USurfaceableCustomNavLinkComponent::USurfaceableCustomNavLinkComponent(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- SetNavigationRelevancy(false);
- SetMoveReachedLink(this, &USurfaceableCustomNavLinkComponent::NotifySmartLinkReached);
- bSmartLinkIsRelevant = false;
- }
- void USurfaceableCustomNavLinkComponent::NotifySmartLinkReached(UNavLinkCustomComponent* LinkComp, UObject* PathingAgent, const FVector& DestPoint)
- {
- UPathFollowingComponent* PathComp = Cast<UPathFollowingComponent>(PathingAgent);
- if (PathComp)
- {
- AActor* PathOwner = PathComp->GetOwner();
- AController* ControllerOwner = Cast<AController>(PathOwner);
- if (ControllerOwner)
- {
- PathOwner = ControllerOwner->GetPawn();
- }
- ReceiveSmartLinkReached(PathOwner, DestPoint);
- OnSmartLinkReached.Broadcast(PathOwner, DestPoint);
- }
- }
- void USurfaceableCustomNavLinkComponent::SmartLinkResumePathFollowing(AActor* Agent)
- {
- if (Agent)
- {
- UPathFollowingComponent* PathComp = Agent->FindComponentByClass<UPathFollowingComponent>();
- if (PathComp == NULL)
- {
- APawn* PawnOwner = Cast<APawn>(Agent);
- if (PawnOwner && PawnOwner->GetController())
- {
- PathComp = PawnOwner->GetController()->FindComponentByClass<UPathFollowingComponent>();
- }
- }
- if (PathComp)
- {
- PathComp->FinishUsingCustomLink(this);
- }
- }
- }
- bool USurfaceableCustomNavLinkComponent::IsSmartLinkRelevant() const
- {
- return IsEnabled();
- }
- bool USurfaceableCustomNavLinkComponent::SmartLinkHasMovingAgents() const
- {
- return HasMovingAgents();
- }
- void USurfaceableCustomNavLinkComponent::SetSmartLinkData(FVector relStartPoint, FVector relEndPoint, bool bBothWays)
- {
- TEnumAsByte<ENavLinkDirection::Type> linkDir = ENavLinkDirection::Type::LeftToRight;
- if (bBothWays) { linkDir = ENavLinkDirection::Type::BothWays; }
- SetLinkData(relStartPoint, relEndPoint, linkDir);
- }
Advertisement
Add Comment
Please, Sign In to add comment