Only get viewport information when viewport is resized
This commit is contained in:
parent
cb0230d24f
commit
1a3516c263
@ -3,14 +3,9 @@
|
|||||||
|
|
||||||
#include "PlayerCharacter.h"
|
#include "PlayerCharacter.h"
|
||||||
|
|
||||||
#include "VampirePlayerController.h"
|
|
||||||
#include "EnhancedInputComponent.h"
|
|
||||||
#include "EnhancedInputSubsystems.h"
|
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
#include "GoldComponent.h"
|
#include "GoldComponent.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "InputMappingContext.h"
|
|
||||||
#include "WeaponInventoryComponent.h"
|
|
||||||
#include "Components/WidgetComponent.h"
|
#include "Components/WidgetComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
@ -55,23 +50,17 @@ void APlayerCharacter::BeginPlay()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
|
PlayerCameraManager = GetWorld()->GetFirstPlayerController()->PlayerCameraManager;
|
||||||
|
|
||||||
|
// For some reason, we need a slight delay here. I need to investigate the exact reason, but this is a quick workaround
|
||||||
|
GEngine->GameViewport->Viewport->ViewportResizedEvent.AddUObject(this, &APlayerCharacter::OnViewportResized);
|
||||||
|
GetWorldTimerManager().SetTimer(ResizeViewportTimerDelegate, this, &APlayerCharacter::ResizeViewportTimerCallback,
|
||||||
|
0.01f, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::Tick(float DeltaTime)
|
void APlayerCharacter::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
|
||||||
|
|
||||||
FVector TopLeft, TopLeftDir;
|
|
||||||
FVector BottomRight, BottomRightDir;
|
|
||||||
|
|
||||||
FVector2d ViewportSize;
|
|
||||||
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
|
||||||
|
|
||||||
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
|
|
||||||
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir);
|
|
||||||
|
|
||||||
FVector Location = GetActorLocation();
|
FVector Location = GetActorLocation();
|
||||||
if (Location.X < BottomRight.X || Location.X > TopLeft.X || Location.Y > BottomRight.Y || Location.Y < TopLeft.Y)
|
if (Location.X < BottomRight.X || Location.X > TopLeft.X || Location.Y > BottomRight.Y || Location.Y < TopLeft.Y)
|
||||||
{
|
{
|
||||||
@ -92,7 +81,7 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
|
|||||||
return GoldComponent;
|
return GoldComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
|
void APlayerCharacter::OnDamaged(FDamageInfo DamageInfo)
|
||||||
{
|
{
|
||||||
if (OnDamagedSound)
|
if (OnDamagedSound)
|
||||||
{
|
{
|
||||||
@ -102,7 +91,7 @@ void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
|
|||||||
CameraShakeTimelineComponent->PlayFromStart();
|
CameraShakeTimelineComponent->PlayFromStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::OnDeath(FDamageInfo damageInfo)
|
void APlayerCharacter::OnDeath(FDamageInfo DamageInfo)
|
||||||
{
|
{
|
||||||
if (OnDeathSound)
|
if (OnDeathSound)
|
||||||
{
|
{
|
||||||
@ -110,12 +99,12 @@ void APlayerCharacter::OnDeath(FDamageInfo damageInfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::CameraShakeTimelineCallback(float val)
|
void APlayerCharacter::CameraShakeTimelineCallback(float Val)
|
||||||
{
|
{
|
||||||
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||||
auto cameraActor = PlayerController->GetViewTarget();
|
auto cameraActor = PlayerController->GetViewTarget();
|
||||||
cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * val,
|
cameraActor->SetActorLocation(FVector(FMath::RandRange(0.0f, CameraShakeStrength) * Val,
|
||||||
FMath::RandRange(0.0f, CameraShakeStrength) * val, 0.0f));
|
FMath::RandRange(0.0f, CameraShakeStrength) * Val, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::CameraShakeTimelineFinishedCallback()
|
void APlayerCharacter::CameraShakeTimelineFinishedCallback()
|
||||||
@ -124,3 +113,19 @@ void APlayerCharacter::CameraShakeTimelineFinishedCallback()
|
|||||||
auto cameraActor = PlayerController->GetViewTarget();
|
auto cameraActor = PlayerController->GetViewTarget();
|
||||||
cameraActor->SetActorLocation(FVector::ZeroVector);
|
cameraActor->SetActorLocation(FVector::ZeroVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::ResizeViewportTimerCallback()
|
||||||
|
{
|
||||||
|
OnViewportResized(GEngine->GameViewport->Viewport, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::OnViewportResized(FViewport* ViewPort, uint32 val)
|
||||||
|
{
|
||||||
|
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||||
|
|
||||||
|
FVector2d ViewportSize;
|
||||||
|
GEngine->GameViewport->GetViewportSize(ViewportSize);
|
||||||
|
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir);
|
||||||
|
PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir);
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "VampireCharacter.h"
|
#include "VampireCharacter.h"
|
||||||
#include "Components/TimelineComponent.h"
|
#include "Components/TimelineComponent.h"
|
||||||
|
#include "UnrealClient.h"
|
||||||
#include "PlayerCharacter.generated.h"
|
#include "PlayerCharacter.generated.h"
|
||||||
|
|
||||||
struct FDamageInfo;
|
struct FDamageInfo;
|
||||||
@ -47,15 +48,19 @@ private:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
|
TObjectPtr<APlayerCameraManager> PlayerCameraManager = nullptr;
|
||||||
|
|
||||||
APlayerCharacter();
|
|
||||||
|
|
||||||
FOnTimelineFloat OnTimelineCallback;
|
FOnTimelineFloat OnTimelineCallback;
|
||||||
FOnTimelineEventStatic OnTimelineFinishedCallback;
|
FOnTimelineEventStatic OnTimelineFinishedCallback;
|
||||||
|
|
||||||
|
FTimerHandle ResizeViewportTimerDelegate;
|
||||||
|
FVector TopLeft, TopLeftDir, BottomRight, BottomRightDir;
|
||||||
|
|
||||||
|
APlayerCharacter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
UEXPComponent* GetEXPComponent();
|
UEXPComponent* GetEXPComponent();
|
||||||
@ -64,14 +69,19 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void OnDamaged(FDamageInfo damageInfo);
|
virtual void OnDamaged(FDamageInfo DamageInfo);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void OnDeath(FDamageInfo damageInfo);
|
virtual void OnDeath(FDamageInfo DamageInfo);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void CameraShakeTimelineCallback(float val);
|
void CameraShakeTimelineCallback(float Val);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void CameraShakeTimelineFinishedCallback();
|
void CameraShakeTimelineFinishedCallback();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ResizeViewportTimerCallback();
|
||||||
|
|
||||||
|
void OnViewportResized(FViewport* ViewPort, uint32 val);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user