Guest User

Untitled

a guest
Dec 26th, 2023
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. // 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
  2.  
  3. #include "SurfaceableCustomNavLinkComponent.h"
  4. #include "UObject/ConstructorHelpers.h"
  5. #include "NavigationSystem.h"
  6. #include "NavigationSystemTypes.h"
  7. #include "AI/NavigationSystemHelpers.h"
  8. #include "Navigation/PathFollowingComponent.h"
  9.  
  10. #if WITH_EDITOR
  11. void USurfaceableCustomNavLinkComponent::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  12. {
  13. static const FName NAME_SmartLinkIsRelevant = GET_MEMBER_NAME_CHECKED(USurfaceableCustomNavLinkComponent, bSmartLinkIsRelevant);
  14.  
  15. bool bUpdateInNavOctree = false;
  16. if (PropertyChangedEvent.GetPropertyName() == NAME_SmartLinkIsRelevant)
  17. {
  18. SetNavigationRelevancy(bSmartLinkIsRelevant);
  19. bUpdateInNavOctree = true;
  20. }
  21.  
  22. if (bUpdateInNavOctree && (GetOwner() != NULL))
  23. {
  24. UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
  25. if (NavSys)
  26. {
  27. NavSys->UpdateActorInNavOctree(*GetOwner());
  28. }
  29. }
  30.  
  31. Super::PostEditChangeProperty(PropertyChangedEvent);
  32. }
  33. #endif // WITH_EDITOR
  34.  
  35. void USurfaceableCustomNavLinkComponent::OnRegister()
  36. {
  37. Super::OnRegister();
  38.  
  39. // We want to wait until after registration has happened, to do this, since that's the pattern used by NavLinkProxy (an Actor)
  40. SetNavigationRelevancy(bSmartLinkIsRelevant);
  41. }
  42.  
  43. USurfaceableCustomNavLinkComponent::USurfaceableCustomNavLinkComponent(const FObjectInitializer& ObjectInitializer)
  44. : Super(ObjectInitializer)
  45. {
  46. SetNavigationRelevancy(false);
  47. SetMoveReachedLink(this, &USurfaceableCustomNavLinkComponent::NotifySmartLinkReached);
  48.  
  49. bSmartLinkIsRelevant = false;
  50. }
  51.  
  52. void USurfaceableCustomNavLinkComponent::NotifySmartLinkReached(UNavLinkCustomComponent* LinkComp, UObject* PathingAgent, const FVector& DestPoint)
  53. {
  54. UPathFollowingComponent* PathComp = Cast<UPathFollowingComponent>(PathingAgent);
  55. if (PathComp)
  56. {
  57. AActor* PathOwner = PathComp->GetOwner();
  58. AController* ControllerOwner = Cast<AController>(PathOwner);
  59. if (ControllerOwner)
  60. {
  61. PathOwner = ControllerOwner->GetPawn();
  62. }
  63.  
  64. ReceiveSmartLinkReached(PathOwner, DestPoint);
  65. OnSmartLinkReached.Broadcast(PathOwner, DestPoint);
  66. }
  67. }
  68.  
  69. void USurfaceableCustomNavLinkComponent::SmartLinkResumePathFollowing(AActor* Agent)
  70. {
  71. if (Agent)
  72. {
  73. UPathFollowingComponent* PathComp = Agent->FindComponentByClass<UPathFollowingComponent>();
  74. if (PathComp == NULL)
  75. {
  76. APawn* PawnOwner = Cast<APawn>(Agent);
  77. if (PawnOwner && PawnOwner->GetController())
  78. {
  79. PathComp = PawnOwner->GetController()->FindComponentByClass<UPathFollowingComponent>();
  80. }
  81. }
  82.  
  83. if (PathComp)
  84. {
  85. PathComp->FinishUsingCustomLink(this);
  86. }
  87. }
  88. }
  89.  
  90. bool USurfaceableCustomNavLinkComponent::IsSmartLinkRelevant() const
  91. {
  92. return IsEnabled();
  93. }
  94.  
  95. bool USurfaceableCustomNavLinkComponent::SmartLinkHasMovingAgents() const
  96. {
  97. return HasMovingAgents();
  98. }
  99.  
  100. void USurfaceableCustomNavLinkComponent::SetSmartLinkData(FVector relStartPoint, FVector relEndPoint, bool bBothWays)
  101. {
  102. TEnumAsByte<ENavLinkDirection::Type> linkDir = ENavLinkDirection::Type::LeftToRight;
  103. if (bBothWays) { linkDir = ENavLinkDirection::Type::BothWays; }
  104.  
  105. SetLinkData(relStartPoint, relEndPoint, linkDir);
  106. }
Advertisement
Add Comment
Please, Sign In to add comment