A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRVehiclePawn.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4#include "CoreMinimal.h"
5#include "UObject/ObjectMacros.h"
6#include "GameFramework/Pawn.h"
7#include "Engine/InputDelegateBinding.h"
8#include "Components/InputComponent.h"
9#include "GameFramework/PlayerController.h"
10#include "VRVehiclePawn.generated.h"
11
12
18UCLASS(config = Game, BlueprintType)
19class VREXPANSIONPLUGIN_API AVRVehiclePawn : public APawn
20{
21 GENERATED_BODY()
23public:
26 /*UFUNCTION(BlueprintCallable, Category = "Pawn", meta = (Keywords = "Delete"))
27 virtual void DetachFromControllerPendingDestroy() override
28 {
29 if (Controller != NULL && Controller->GetPawn() == this)
30 {
31 Controller->PawnPendingDestroy(this);
32 if (Controller != NULL)
33 {
34 Controller->UnPossess();
35 Controller = NULL;
36 }
37 }
38 }*/
39
40
41 //UFUNCTION()
42 virtual void OnRep_Controller() override
43 {
44 if ((Controller != NULL) && (Controller->GetPawn() == NULL))
45 {
46 // This ensures that APawn::OnRep_Pawn is called. Since we cant ensure replication order of APawn::Controller and AController::Pawn,
47 // if APawn::Controller is repped first, it will set AController::Pawn locally. When AController::Pawn is repped, the rep value will not
48 // be different from the just set local value, and OnRep_Pawn will not be called. This can cause problems if OnRep_Pawn does anything important.
49 //
50 // It would be better to never ever set replicated properties locally, but this is pretty core in the gameplay framework and I think there are
51 // lots of assumptions made in the code base that the Pawn and Controller will always be linked both ways.
52 //Controller->SetPawnFromRep(this);
53
54 /*APlayerController* const PC = Cast<APlayerController>(Controller);
55 if ((PC != NULL) && PC->bAutoManageActiveCameraTarget && (PC->PlayerCameraManager->ViewTarget.Target == Controller))
56 {
57 PC->AutoManageActiveCameraTarget(this);
58 }*/
59 }
60
61 /*if (IsLocallyControlled())
62 {
63 SetBindToInput(Controller, true);
64 }*/
65
66 }
67
68
69 UFUNCTION(BlueprintCallable, Category = "Pawn")
70 virtual bool SetBindToInput(AController * CController, bool bBindToInput)
71 {
72 APlayerController * playe = Cast<APlayerController>(CController);
73
74 if (playe != NULL)
75 {
76 if(InputComponent)
77 playe->PopInputComponent(InputComponent); // Make sure it is off the stack
78
79 if (!bBindToInput)
80 {
81 // Unregister input component if we created one
82 DestroyPlayerInputComponent();
83 return true;
84 }
85 else
86 {
87 // Set up player input component, if there isn't one already.
88 if (InputComponent == NULL)
89 {
90 InputComponent = CreatePlayerInputComponent();
91 if (InputComponent)
92 {
93 SetupPlayerInputComponent(InputComponent);
94 InputComponent->RegisterComponent();
95
96 if (UInputDelegateBinding::SupportsInputDelegate(GetClass()))
97 {
98 InputComponent->bBlockInput = bBlockInput;
99 UInputDelegateBinding::BindInputDelegates(GetClass(), InputComponent);
100 }
101 }
102 }
103
104 if (InputComponent)
105 {
106 playe->PushInputComponent(InputComponent); // Enforce input as top of stack so it gets input first and can consume it
107 return true;
108 }
109 }
110 }
111 else
112 {
113 // Unregister input component if we created one
114 DestroyPlayerInputComponent();
115 return false;
116 }
117
118 return false;
119 }
120
121 UFUNCTION(BlueprintCallable, Category = "Pawn")
122 virtual bool ForceSecondaryPossession(AController * NewController)
123 {
124 if (NewController)
125 {
126 PossessedBy(NewController);
127 }
128 else
129 {
130 UnPossessed();
132
133 return false;
134 //INetworkPredictionInterface* NetworkPredictionInterface = GetPawn() ? Cast<INetworkPredictionInterface>(GetPawn()->GetMovementComponent()) : NULL;
135 //if (NetworkPredictionInterface)
136 //{
137 // NetworkPredictionInterface->ResetPredictionData_Server();
138 // }
139
140
141 // Local PCs will have the Restart() triggered right away in ClientRestart (via PawnClientRestart()), but the server should call Restart() locally for remote PCs.
142 // We're really just trying to avoid calling Restart() multiple times.
143 // if (!IsLocalPlayerController())
144 // {
145 // GetPawn()->Restart();
146 // }
147 // ClientRestart(GetPawn());
148
149 //ChangeState(NAME_Playing);
150 //if (bAutoManageActiveCameraTarget)
151 //{
152 // AutoManageActiveCameraTarget(GetPawn());
153 // ResetCameraMode();
154 //}
155 //UpdateNavigationComponents();
156 }
157
158};
UCLASS(config = Game, BlueprintType)
virtual bool ForceSecondaryPossession(AController *NewController)
UFUNCTION(BlueprintCallable, Category = "Pawn")
virtual void OnRep_Controller() override
virtual bool SetBindToInput(AController *CController, bool bBindToInput)
UFUNCTION(BlueprintCallable, Category = "Pawn")