A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VRWheeledVehicle.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//#if WITH_CHAOS
6//#include "Plugins/Experimental/ChaosVehicles/WheeledVehiclePawn.h"
7//#include "Plugins/Experimental/ChaosVehicles/ChaosWheeledVehicleMovementComponent.h"
8#if PHYSICS_INTERFACE_PHYSX
9#include "WheeledVehicle.h"
10#include "WheeledVehicleMovementComponent.h"
11#include "SimpleWheeledVehicleMovementComponent.h"
12#endif
13
14#include "UObject/ObjectMacros.h"
15#include "GameFramework/Pawn.h"
16#include "Engine/InputDelegateBinding.h"
17#include "Components/InputComponent.h"
18#include "GameFramework/PlayerController.h"
19#include "VRWheeledVehicle.generated.h"
20
21
27UCLASS(config = Game, BlueprintType)
28class VREXPANSIONPLUGIN_API AVRWheeledVehicle : public AWheeledVehicle
29//UCLASS(config = Game, BlueprintType)
30//class VREXPANSIONPLUGIN_API AVRWheeledVehicle : public APawn//AWheeledVehiclePawn
31//#endif
32{
33 GENERATED_BODY()
34
35public:
38 /*UFUNCTION(BlueprintCallable, Category = "Pawn", meta = (Keywords = "Delete"))
39 virtual void DetachFromControllerPendingDestroy() override
40 {
41 if (Controller != NULL && Controller->GetPawn() == this)
42 {
43 Controller->PawnPendingDestroy(this);
44 if (Controller != NULL)
45 {
46 Controller->UnPossess();
47 Controller = NULL;
48 }
49 }
50 }*/
51
52
53 //UFUNCTION()
54 virtual void OnRep_Controller() override
55 {
56 if ((Controller != NULL) && (Controller->GetPawn() == NULL))
57 {
58 // This ensures that APawn::OnRep_Pawn is called. Since we cant ensure replication order of APawn::Controller and AController::Pawn,
59 // if APawn::Controller is repped first, it will set AController::Pawn locally. When AController::Pawn is repped, the rep value will not
60 // 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.
61 //
62 // 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
63 // lots of assumptions made in the code base that the Pawn and Controller will always be linked both ways.
64 //Controller->SetPawnFromRep(this);
65
66 /*APlayerController* const PC = Cast<APlayerController>(Controller);
67 if ((PC != NULL) && PC->bAutoManageActiveCameraTarget && (PC->PlayerCameraManager->ViewTarget.Target == Controller))
68 {
69 PC->AutoManageActiveCameraTarget(this);
70 }*/
71 }
72
73 /*if (IsLocallyControlled())
74 {
75 SetBindToInput(Controller, true);
76 }*/
77
78 }
79
80
81 UFUNCTION(BlueprintCallable, Category = "Pawn")
82 virtual bool SetBindToInput(AController * CController, bool bBindToInput)
83 {
84 APlayerController * playe = Cast<APlayerController>(CController);
85
86 if (playe != NULL)
87 {
88 if(InputComponent)
89 playe->PopInputComponent(InputComponent); // Make sure it is off the stack
90
91 if (!bBindToInput)
92 {
93 // Unregister input component if we created one
94 DestroyPlayerInputComponent();
95 return true;
96 }
97 else
98 {
99 // Set up player input component, if there isn't one already.
100 if (InputComponent == NULL)
101 {
102 InputComponent = CreatePlayerInputComponent();
103 if (InputComponent)
104 {
105 SetupPlayerInputComponent(InputComponent);
106 InputComponent->RegisterComponent();
107
108 if (UInputDelegateBinding::SupportsInputDelegate(GetClass()))
109 {
110 InputComponent->bBlockInput = bBlockInput;
111 UInputDelegateBinding::BindInputDelegates(GetClass(), InputComponent);
112 }
113 }
114 }
115
116 if (InputComponent)
117 {
118 playe->PushInputComponent(InputComponent); // Enforce input as top of stack so it gets input first and can consume it
119 return true;
120 }
121 }
122 }
123 else
124 {
125 // Unregister input component if we created one
126 DestroyPlayerInputComponent();
127 return false;
128 }
129
130 return false;
131 }
132
133 // Calls the movement components override controller function
134 UFUNCTION(BlueprintCallable, Category = "Pawn")
135 virtual bool SetOverrideController(AController * NewController)
136 {
137#if PHYSICS_INTERFACE_PHYSX
138 if (UWheeledVehicleMovementComponent * MoveComp = Cast<UWheeledVehicleMovementComponent>(this->GetMovementComponent()))
139 {
140 MoveComp->SetOverrideController(NewController);
141 return true;
142 }
143#else
144 /*if (UChaosWheeledVehicleMovementComponent* MoveComp = Cast<UChaosWheeledVehicleMovementComponent>(this->GetMovementComponent()))
145 {
146 MoveComp->SetOverrideController(NewController);
147 return true;
148 }*/
149#endif
150
151 return false;
152 }
153
154
155 UFUNCTION(BlueprintCallable, Category = "Pawn")
156 virtual bool ForceSecondaryPossession(AController * NewController)
157 {
158 if (NewController)
159 {
160 PossessedBy(NewController);
161 }
162 else
163 {
164 UnPossessed();
165 }
166
167 return false;
168 //INetworkPredictionInterface* NetworkPredictionInterface = GetPawn() ? Cast<INetworkPredictionInterface>(GetPawn()->GetMovementComponent()) : NULL;
169 //if (NetworkPredictionInterface)
170 //{
171 // NetworkPredictionInterface->ResetPredictionData_Server();
172 // }
173
174
175 // Local PCs will have the Restart() triggered right away in ClientRestart (via PawnClientRestart()), but the server should call Restart() locally for remote PCs.
176 // We're really just trying to avoid calling Restart() multiple times.
177 // if (!IsLocalPlayerController())
178 // {
179 // GetPawn()->Restart();
180 // }
181 // ClientRestart(GetPawn());
182
183 //ChangeState(NAME_Playing);
184 //if (bAutoManageActiveCameraTarget)
185 //{
186 // AutoManageActiveCameraTarget(GetPawn());
187 // ResetCameraMode();
188 //}
189 //UpdateNavigationComponents();
190 }
191
192};
193
194/*
195UCLASS(config = Game, BlueprintType)
196class VREXPANSIONPLUGIN_API AVRSimpleWheeledVehicle : public AVRWheeledVehicle
197{
198 GENERATED_BODY()
199
200public:
201
202 AVRSimpleWheeledVehicle(const FObjectInitializer& ObjectInitializer)
203 : Super(ObjectInitializer.SetDefaultSubobjectClass<USimpleWheeledVehicleMovementComponent>(VehicleMovementComponentName))
204 {
205 }
206};
207*/
UCLASS(config = Game, BlueprintType)
virtual void OnRep_Controller() override
virtual bool ForceSecondaryPossession(AController *NewController)
UFUNCTION(BlueprintCallable, Category = "Pawn")
virtual bool SetOverrideController(AController *NewController)
UFUNCTION(BlueprintCallable, Category = "Pawn")
virtual bool SetBindToInput(AController *CController, bool bBindToInput)
UFUNCTION(BlueprintCallable, Category = "Pawn")