Advertisement
Guest User

Untitled

a guest
Jun 28th, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3.  
  4. #include "PongGameplayController.h"
  5. #include "Kismet/GameplayStatics.h"
  6. #include "Net/UnrealNetwork.h"
  7. #include "PongCamera.h"
  8. #include "PongRacket.h"
  9.  
  10. APongGameplayController::APongGameplayController(const FObjectInitializer& ObjectInitializer)
  11.     : Super(ObjectInitializer)
  12. {
  13.     bReplicates = true;
  14.  
  15.     bAutoManageActiveCameraTarget = false;
  16.  
  17. }
  18.  
  19. void APongGameplayController::BeginPlay()
  20. {
  21.     Super::BeginPlay();
  22.  
  23.     SetInputMode(FInputModeGameOnly());
  24.  
  25.     APongRacket* ControlledPawn = GetPawn<APongRacket>();
  26.        
  27.     ControlledPawn != nullptr ?
  28.         GEngine->AddOnScreenDebugMessage(
  29.             -1,
  30.             10.f,
  31.             FColor::Cyan,
  32.             FString::Printf(
  33.                 TEXT("Is controlling a %s pawn."),
  34.                 *ControlledPawn->GetClass()->GetDescription()
  35.             )          
  36.         ) : GEngine->AddOnScreenDebugMessage(-1, 10.f, FColor::Cyan, TEXT("No pawn controlled."));
  37.        
  38.     if (GetLocalRole() == ROLE_Authority)
  39.     {
  40.         APongCamera* MainCamera = Cast<APongCamera>(
  41.             UGameplayStatics::GetActorOfClass(GetWorld(), APongCamera::StaticClass())
  42.         );
  43.  
  44.         if(MainCamera)
  45.         {
  46.             ViewTarget = MainCamera;           
  47.  
  48.             OnRep_ViewTarget();
  49.         }
  50.  
  51.     }
  52.  
  53. }
  54.  
  55. void APongGameplayController::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
  56. {
  57.     Super::GetLifetimeReplicatedProps(OutLifetimeProps);
  58.    
  59.     DOREPLIFETIME(APongGameplayController, ViewTarget);
  60.  
  61. }
  62.  
  63. void APongGameplayController::OnRep_ViewTarget()
  64. {
  65.     GEngine->AddOnScreenDebugMessage(
  66.         -1,
  67.         10.f,
  68.         FColor::Green,
  69.         TEXT("Player's point of view changed.")
  70.     ); 
  71.  
  72.     SetViewTarget(ViewTarget);
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement