Move Widget from PlayerCharacter to PlayerController
This commit is contained in:
parent
6106a2dae6
commit
0c90ade615
|
@ -54,16 +54,6 @@ APlayerCharacter::APlayerCharacter()
|
||||||
void APlayerCharacter::BeginPlay()
|
void APlayerCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
if (PlayerHUD)
|
|
||||||
{
|
|
||||||
currentPlayerHUD = UUserWidget::CreateWidgetInstance(*GetWorld(), PlayerHUD, FName("Player HUD"));
|
|
||||||
|
|
||||||
if (currentPlayerHUD)
|
|
||||||
{
|
|
||||||
currentPlayerHUD->AddToViewport();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||||
|
|
|
@ -48,17 +48,12 @@ public:
|
||||||
|
|
||||||
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
|
||||||
TSubclassOf<UUserWidget> PlayerHUD = nullptr;
|
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
UWidgetComponent* HealthBarWidgetComponent;
|
UWidgetComponent* HealthBarWidgetComponent;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FTimerHandle GarlicTimerHandle;
|
FTimerHandle GarlicTimerHandle;
|
||||||
|
|
||||||
UUserWidget* currentPlayerHUD = nullptr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
APlayerCharacter();
|
APlayerCharacter();
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,22 @@
|
||||||
|
|
||||||
#include "VampirePlayerController.h"
|
#include "VampirePlayerController.h"
|
||||||
|
|
||||||
|
#include "EXPComponent.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "Widgets/HUDWidget.h"
|
||||||
|
|
||||||
|
void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||||
|
{
|
||||||
|
Super::OnPossess(aPawn);
|
||||||
|
|
||||||
|
if (PlayerHUD)
|
||||||
|
{
|
||||||
|
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
|
||||||
|
|
||||||
|
if (currentPlayerHUD)
|
||||||
|
{
|
||||||
|
currentPlayerHUD->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,25 @@
|
||||||
#include "GameFramework/PlayerController.h"
|
#include "GameFramework/PlayerController.h"
|
||||||
#include "VampirePlayerController.generated.h"
|
#include "VampirePlayerController.generated.h"
|
||||||
|
|
||||||
|
class UHUDWidget;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS(Abstract)
|
||||||
class VAMPIRES_API AVampirePlayerController : public APlayerController
|
class VAMPIRES_API AVampirePlayerController : public APlayerController
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void OnPossess(APawn* aPawn) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue