From bf043b91fd8155400815ad03421d60f4967fd3f8 Mon Sep 17 00:00:00 2001 From: 10000Je Date: Fri, 9 May 2025 00:08:39 +0900 Subject: [PATCH] =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95=20=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BP_ToonTanksPlayerController.uasset | 3 +++ .../GameMode/BP_ToonTanksGameMode.uasset | 4 ++-- Source/ToonTanks/Tank.cpp | 8 +------ Source/ToonTanks/ToonTanksGameMode.cpp | 7 ++++--- Source/ToonTanks/ToonTanksGameMode.h | 4 ++++ .../ToonTanks/ToonTanksPlayerController.cpp | 17 +++++++++++++++ Source/ToonTanks/ToonTanksPlayerController.h | 21 +++++++++++++++++++ 7 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset create mode 100644 Source/ToonTanks/ToonTanksPlayerController.cpp create mode 100644 Source/ToonTanks/ToonTanksPlayerController.h diff --git a/Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset b/Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset new file mode 100644 index 0000000..0f240c1 --- /dev/null +++ b/Content/Blueprints/Controller/BP_ToonTanksPlayerController.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abe85906f74331cfc631d87b16e36c80702272e3a921825002a361761d3e5e86 +size 20711 diff --git a/Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset b/Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset index 6e65ed6..1631af3 100644 --- a/Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset +++ b/Content/Blueprints/GameMode/BP_ToonTanksGameMode.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a22a0fdf1483ab9020016fe87a1eab9051287dcd5576b709ec2f2cbdb9d40da0 -size 21231 +oid sha256:97d4bb8442517166383c7ef8f1494f787463a8568fcc8dd5c5d5929cce0d4722 +size 21170 diff --git a/Source/ToonTanks/Tank.cpp b/Source/ToonTanks/Tank.cpp index ee0b7f9..a694f8c 100644 --- a/Source/ToonTanks/Tank.cpp +++ b/Source/ToonTanks/Tank.cpp @@ -3,6 +3,7 @@ #include "Tank.h" +#include "ToonTanksPlayerController.h" #include "Camera/CameraComponent.h" #include "GameFramework/SpringArmComponent.h" #include "Kismet/GameplayStatics.h" @@ -37,13 +38,6 @@ void ATank::Tick(float DeltaTime) false, HitResult ); - DrawDebugSphere( - GetWorld(), - HitResult.ImpactPoint, - 25, - 12, - FColor::Green - ); RotateTurret(HitResult.ImpactPoint); } } diff --git a/Source/ToonTanks/ToonTanksGameMode.cpp b/Source/ToonTanks/ToonTanksGameMode.cpp index b22f069..6a562db 100644 --- a/Source/ToonTanks/ToonTanksGameMode.cpp +++ b/Source/ToonTanks/ToonTanksGameMode.cpp @@ -3,6 +3,7 @@ #include "ToonTanksGameMode.h" #include "Tank.h" +#include "ToonTanksPlayerController.h" #include "Tower.h" #include "Kismet/GameplayStatics.h" @@ -10,6 +11,7 @@ void AToonTanksGameMode::BeginPlay() { Super::BeginPlay(); Tank = Cast(UGameplayStatics::GetPlayerPawn(this, 0)); + PlayerController = Cast(UGameplayStatics::GetPlayerController(this, 0)); } void AToonTanksGameMode::ActorDied(AActor* DeadActor) @@ -17,10 +19,9 @@ void AToonTanksGameMode::ActorDied(AActor* DeadActor) if (DeadActor == Tank) { Tank->HandleDestruction(); - if (Tank->GetPlayerController()) + if (PlayerController) { - Tank->DisableInput(Tank->GetPlayerController()); - Tank->GetPlayerController()->bShowMouseCursor = false; + PlayerController->SetPlayerEnabledState(false); } } else if (ATower* DestroyedTower = Cast(DeadActor)) diff --git a/Source/ToonTanks/ToonTanksGameMode.h b/Source/ToonTanks/ToonTanksGameMode.h index 5bf38e1..c44340b 100644 --- a/Source/ToonTanks/ToonTanksGameMode.h +++ b/Source/ToonTanks/ToonTanksGameMode.h @@ -25,5 +25,9 @@ private: // Tank Pointer for DeadActor which is ATank. UPROPERTY() class ATank* Tank; + + // ToonTanksPlayerController Pointer of player pawn. + UPROPERTY() + class AToonTanksPlayerController* PlayerController; }; diff --git a/Source/ToonTanks/ToonTanksPlayerController.cpp b/Source/ToonTanks/ToonTanksPlayerController.cpp new file mode 100644 index 0000000..7a7d240 --- /dev/null +++ b/Source/ToonTanks/ToonTanksPlayerController.cpp @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ToonTanksPlayerController.h" + +void AToonTanksPlayerController::SetPlayerEnabledState(bool bPlayerEnabled) +{ + if (bPlayerEnabled) + { + GetPawn()->EnableInput(this); + } + else + { + GetPawn()->DisableInput(this); + } + bShowMouseCursor = bPlayerEnabled; +} \ No newline at end of file diff --git a/Source/ToonTanks/ToonTanksPlayerController.h b/Source/ToonTanks/ToonTanksPlayerController.h new file mode 100644 index 0000000..e895a15 --- /dev/null +++ b/Source/ToonTanks/ToonTanksPlayerController.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/PlayerController.h" +#include "ToonTanksPlayerController.generated.h" + +/** + * + */ +UCLASS() +class TOONTANKS_API AToonTanksPlayerController : public APlayerController +{ + GENERATED_BODY() + +public: + // Set this controller to Enabled or Disabled. + void SetPlayerEnabledState(bool bPlayerEnabled); + +};