From bca83f6a9cc4abe69e91096e787f6f50fb90ee66 Mon Sep 17 00:00:00 2001 From: HappyTanuki Date: Tue, 4 Mar 2025 18:51:09 +0900 Subject: [PATCH] =?UTF-8?q?16=EB=B2=88=20=ED=95=A0=20=EC=B0=A8=EB=A1=80,?= =?UTF-8?q?=20=ED=8F=AC=EC=8A=A4=ED=8A=B8=ED=94=84=EB=A1=9C=EC=84=B8?= =?UTF-8?q?=EC=8B=B1=20=ED=95=98=EC=9D=B4=EB=9D=BC=EC=9D=B4=ED=8C=85?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20=EC=99=84=EB=A3=8C=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Config/DefaultEngine.ini | 1 + .../Blueprints/Character/Aura/ABP_Aura.uasset | 4 +- .../Character/Aura/BP_AuraCharacter.uasset | 4 +- .../Blueprints/Character/BP_EnemyBase.uasset | 3 + .../BP_Goblin_Slingshot.uasset | 4 +- .../Goblin_Spear/BP_Goblin_Spear.uasset | 4 +- .../Blueprints/Game/BP_AuraGameMode.uasset | 3 + .../Player/BP_AuraPlayerController.uasset | 3 + Content/Maps/StartupMap.umap | 4 +- Source/Aura/Aura.Build.cs | 2 +- Source/Aura/Aura.h | 1 + .../Aura/Private/Character/AuraCharacter.cpp | 13 +++ Source/Aura/Private/Character/AuraEnemy.cpp | 20 ++++ Source/Aura/Private/Game/AuraGameModeBase.cpp | 5 + .../Private/Interaction/EnemyInterface.cpp | 6 ++ .../Private/Player/AuraPlayerController.cpp | 98 +++++++++++++++++++ Source/Aura/Public/Character/AuraCharacter.h | 3 +- Source/Aura/Public/Character/AuraEnemy.h | 7 +- Source/Aura/Public/Game/AuraGameModeBase.h | 17 ++++ .../Aura/Public/Interaction/EnemyInterface.h | 27 +++++ .../Aura/Public/Player/AuraPlayerController.h | 21 ++++ 21 files changed, 237 insertions(+), 13 deletions(-) create mode 100644 Content/Blueprints/Character/BP_EnemyBase.uasset create mode 100644 Content/Blueprints/Game/BP_AuraGameMode.uasset create mode 100644 Content/Blueprints/Player/BP_AuraPlayerController.uasset create mode 100644 Source/Aura/Private/Game/AuraGameModeBase.cpp create mode 100644 Source/Aura/Private/Interaction/EnemyInterface.cpp create mode 100644 Source/Aura/Public/Game/AuraGameModeBase.h create mode 100644 Source/Aura/Public/Interaction/EnemyInterface.h diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index e33cbe4..0d90035 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -46,6 +46,7 @@ r.DynamicGlobalIlluminationMethod=1 r.ReflectionMethod=1 r.Shadow.Virtual.Enable=1 r.DefaultFeature.AutoExposure.ExtendDefaultLuminanceRange=True +r.CustomDepth=3 [/Script/WorldPartitionEditor.WorldPartitionEditorSettings] CommandletClass=Class'/Script/UnrealEd.WorldPartitionConvertCommandlet' diff --git a/Content/Blueprints/Character/Aura/ABP_Aura.uasset b/Content/Blueprints/Character/Aura/ABP_Aura.uasset index 680b476..9c682db 100644 --- a/Content/Blueprints/Character/Aura/ABP_Aura.uasset +++ b/Content/Blueprints/Character/Aura/ABP_Aura.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:37f34fcd6dbffec7c642b838c92cd9eaa8de43497eac99fd9dadafbcf18c8eda -size 110389 +oid sha256:ad1b9ca20c033bb1d94432a7d8fd26491c9c394ce0a584476733b3601b5d7f51 +size 156977 diff --git a/Content/Blueprints/Character/Aura/BP_AuraCharacter.uasset b/Content/Blueprints/Character/Aura/BP_AuraCharacter.uasset index 60d0dd9..b2d5fb1 100644 --- a/Content/Blueprints/Character/Aura/BP_AuraCharacter.uasset +++ b/Content/Blueprints/Character/Aura/BP_AuraCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:26d05d873315f253f3038d7b19f926e71961fc84c3d5e0a91c596e617b6199bb -size 33836 +oid sha256:971616aa220fa6faab3c08ad128c0313d75204714a6c0ce0f347cb05c7163443 +size 36385 diff --git a/Content/Blueprints/Character/BP_EnemyBase.uasset b/Content/Blueprints/Character/BP_EnemyBase.uasset new file mode 100644 index 0000000..3b728f3 --- /dev/null +++ b/Content/Blueprints/Character/BP_EnemyBase.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6d88c3717993fc68fb00ee8fdb467780587adde109c91eea2aac1a8f3a329b63 +size 23348 diff --git a/Content/Blueprints/Character/Goblin_Slingshot/BP_Goblin_Slingshot.uasset b/Content/Blueprints/Character/Goblin_Slingshot/BP_Goblin_Slingshot.uasset index 702d253..70b23e7 100644 --- a/Content/Blueprints/Character/Goblin_Slingshot/BP_Goblin_Slingshot.uasset +++ b/Content/Blueprints/Character/Goblin_Slingshot/BP_Goblin_Slingshot.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ff596d3fe8404ca63cf7bcaf6fb68ba6e95d5ab9e3634ffdd2db15795f9f9b60 -size 34692 +oid sha256:53a44fd9ba9e7c5431f7d19db5c7ec84803388b2a85c6fa51507430feed671d9 +size 34821 diff --git a/Content/Blueprints/Character/Goblin_Spear/BP_Goblin_Spear.uasset b/Content/Blueprints/Character/Goblin_Spear/BP_Goblin_Spear.uasset index 4676e64..5f278a7 100644 --- a/Content/Blueprints/Character/Goblin_Spear/BP_Goblin_Spear.uasset +++ b/Content/Blueprints/Character/Goblin_Spear/BP_Goblin_Spear.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f9e812e12a617096612acb0bf966a52dc5c8f3cd0f141662f44b8769420dac58 -size 34072 +oid sha256:f2518f1bdd20ae42f89dc47c33ef0925f0542615e9ad65d62c1d9bd3d4f1f9dc +size 35221 diff --git a/Content/Blueprints/Game/BP_AuraGameMode.uasset b/Content/Blueprints/Game/BP_AuraGameMode.uasset new file mode 100644 index 0000000..4747d61 --- /dev/null +++ b/Content/Blueprints/Game/BP_AuraGameMode.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e384a43fcb9a03bf321cbb7d401f4017eb226a3994b5dcf8ea9e957bdfde7674 +size 21244 diff --git a/Content/Blueprints/Player/BP_AuraPlayerController.uasset b/Content/Blueprints/Player/BP_AuraPlayerController.uasset new file mode 100644 index 0000000..34d6997 --- /dev/null +++ b/Content/Blueprints/Player/BP_AuraPlayerController.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:367e31ec9aa1aec3d8e6cd4938dea4ec97e8f7e839175dfe95455f05421cb97d +size 20454 diff --git a/Content/Maps/StartupMap.umap b/Content/Maps/StartupMap.umap index 7b4b1fc..56d5c1b 100644 --- a/Content/Maps/StartupMap.umap +++ b/Content/Maps/StartupMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:93eb5b31a9fda3b7f0639ca03949a578b079b25ddfcc13feca1c58de1065bbb6 -size 43045 +oid sha256:ea9182604bc59d10bdb4971274f4ea1f19c66e84ddf10652918ff2f67c8feeea +size 63374 diff --git a/Source/Aura/Aura.Build.cs b/Source/Aura/Aura.Build.cs index d5cd7c1..45fb2ae 100644 --- a/Source/Aura/Aura.Build.cs +++ b/Source/Aura/Aura.Build.cs @@ -8,7 +8,7 @@ public class Aura : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/Source/Aura/Aura.h b/Source/Aura/Aura.h index 54c6aaa..18050d2 100644 --- a/Source/Aura/Aura.h +++ b/Source/Aura/Aura.h @@ -4,3 +4,4 @@ #include "CoreMinimal.h" +#define CUSTOM_DEPTH_RED 250 \ No newline at end of file diff --git a/Source/Aura/Private/Character/AuraCharacter.cpp b/Source/Aura/Private/Character/AuraCharacter.cpp index 7ed3bf3..301aad6 100644 --- a/Source/Aura/Private/Character/AuraCharacter.cpp +++ b/Source/Aura/Private/Character/AuraCharacter.cpp @@ -3,3 +3,16 @@ #include "Character/AuraCharacter.h" +#include "GameFramework/CharacterMovementComponent.h" + +AAuraCharacter::AAuraCharacter() +{ + GetCharacterMovement()->bOrientRotationToMovement = true; + GetCharacterMovement()->RotationRate = FRotator(0.f, 400.f, 0.f); + GetCharacterMovement()->bConstrainToPlane = true; + GetCharacterMovement()->bSnapToPlaneAtStart = true; + + bUseControllerRotationPitch = false; + bUseControllerRotationYaw = false; + bUseControllerRotationRoll = false; +} diff --git a/Source/Aura/Private/Character/AuraEnemy.cpp b/Source/Aura/Private/Character/AuraEnemy.cpp index cf3bebc..973eaa2 100644 --- a/Source/Aura/Private/Character/AuraEnemy.cpp +++ b/Source/Aura/Private/Character/AuraEnemy.cpp @@ -3,3 +3,23 @@ #include "Character/AuraEnemy.h" +#include "Aura/Aura.h" + +AAuraEnemy::AAuraEnemy() +{ + GetMesh()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block); +} + +void AAuraEnemy::HighlightActor() +{ + GetMesh()->SetRenderCustomDepth(true); + GetMesh()->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED); + Weapon->SetRenderCustomDepth(true); + Weapon->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED); +} + +void AAuraEnemy::UnHighlightActor() +{ + GetMesh()->SetRenderCustomDepth(false); + Weapon->SetRenderCustomDepth(false); +} diff --git a/Source/Aura/Private/Game/AuraGameModeBase.cpp b/Source/Aura/Private/Game/AuraGameModeBase.cpp new file mode 100644 index 0000000..cbfcd52 --- /dev/null +++ b/Source/Aura/Private/Game/AuraGameModeBase.cpp @@ -0,0 +1,5 @@ +// Copyright HappyTanuki + + +#include "Game/AuraGameModeBase.h" + diff --git a/Source/Aura/Private/Interaction/EnemyInterface.cpp b/Source/Aura/Private/Interaction/EnemyInterface.cpp new file mode 100644 index 0000000..5cc0bf4 --- /dev/null +++ b/Source/Aura/Private/Interaction/EnemyInterface.cpp @@ -0,0 +1,6 @@ +// Copyright HappyTanuki + + +#include "Interaction/EnemyInterface.h" + +// Add default functionality here for any IEnemyInterface functions that are not pure virtual. diff --git a/Source/Aura/Private/Player/AuraPlayerController.cpp b/Source/Aura/Private/Player/AuraPlayerController.cpp index 04bf44b..aa0a0e2 100644 --- a/Source/Aura/Private/Player/AuraPlayerController.cpp +++ b/Source/Aura/Private/Player/AuraPlayerController.cpp @@ -2,8 +2,106 @@ #include "Player/AuraPlayerController.h" +#include "EnhancedInputSubsystems.h" +#include "EnhancedInputComponent.h" +#include "Interaction/EnemyInterface.h" AAuraPlayerController::AAuraPlayerController() { bReplicates = true; } + +void AAuraPlayerController::PlayerTick(float DeltaTime) +{ + Super::PlayerTick(DeltaTime); + + CursorTrace(); +} + +void AAuraPlayerController::BeginPlay() +{ + Super::BeginPlay(); + check(AuraContext); //블루프린트에서 입력이 설정이 되지 않았다면 그대로 멈춘다 왜?:입력이 안 먹으면 안 되기 때문 + + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer()); + check(Subsystem); + + Subsystem->AddMappingContext(AuraContext, 0); + + bShowMouseCursor = true; + DefaultMouseCursor = EMouseCursor::Default; + + FInputModeGameAndUI InputModeData; + InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock); + InputModeData.SetHideCursorDuringCapture(false); + SetInputMode(InputModeData); +} + +void AAuraPlayerController::SetupInputComponent() +{ + Super::SetupInputComponent(); + + UEnhancedInputComponent* EnhancedInputComponent = CastChecked(InputComponent); + + EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move); +} + +void AAuraPlayerController::Move(const FInputActionValue& InputActionvalue) +{ + const FVector2d InputAxisVector = InputActionvalue.Get(); + const FRotator Ratation = GetControlRotation(); + const FRotator YawRotation(0.f, Ratation.Yaw, 0.f); + + const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); + const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); + + if (APawn* ControlledPawn = GetPawn()) + { + ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y); + ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X); + } +} + +void AAuraPlayerController::CursorTrace() +{ + FHitResult CursorHit; + GetHitResultUnderCursor(ECC_Visibility, false, CursorHit); + if (!CursorHit.bBlockingHit) return; + + LastActor = ThisActor; + ThisActor = CursorHit.GetActor(); //자동 캐스팅됨, Cast()생략됨. + + /** + * 각 상황에 따른 분류: + * A. LastActor == nullptr && ThisActor == nullptr + * - NOP + * B. LastActor == nullptr && ThisActor != nullptr + * - ThisActor 하이라이팅하기 + * C. LastActor != nullptr && ThisActor == nullptr + * - LastActor 하이라이트 끄기 + * D. LastActor != nullptr && ThisActor != nullptr && LastActor != ThisActor + * - LastActor 하이라이트 끄고 ThisActor 하이라이팅하기 + * E. LastActor != nullptr && ThisActor != nullptr && LastActor == ThisActor + * - NOP + **/ + if (LastActor == nullptr) + { + if (ThisActor == nullptr) return; //A + ThisActor->HighlightActor(); //B + } + else if (ThisActor == nullptr) + { + //C + LastActor->UnHighlightActor(); + } + else if (LastActor != ThisActor) + { + //D + LastActor->UnHighlightActor(); + ThisActor->HighlightActor(); + } + else + { + //E + } +} diff --git a/Source/Aura/Public/Character/AuraCharacter.h b/Source/Aura/Public/Character/AuraCharacter.h index 3534786..6d4fd80 100644 --- a/Source/Aura/Public/Character/AuraCharacter.h +++ b/Source/Aura/Public/Character/AuraCharacter.h @@ -13,5 +13,6 @@ UCLASS() class AURA_API AAuraCharacter : public AAuraCharacterBase { GENERATED_BODY() - +public: + AAuraCharacter(); }; diff --git a/Source/Aura/Public/Character/AuraEnemy.h b/Source/Aura/Public/Character/AuraEnemy.h index a5cfb0a..0dcaf4a 100644 --- a/Source/Aura/Public/Character/AuraEnemy.h +++ b/Source/Aura/Public/Character/AuraEnemy.h @@ -4,14 +4,19 @@ #include "CoreMinimal.h" #include "Character/AuraCharacterBase.h" +#include "Interaction/EnemyInterface.h" #include "AuraEnemy.generated.h" /** * */ UCLASS() -class AURA_API AAuraEnemy : public AAuraCharacterBase +class AURA_API AAuraEnemy : public AAuraCharacterBase, public IEnemyInterface { GENERATED_BODY() +public: + AAuraEnemy(); + virtual void HighlightActor() override; + virtual void UnHighlightActor() override; }; diff --git a/Source/Aura/Public/Game/AuraGameModeBase.h b/Source/Aura/Public/Game/AuraGameModeBase.h new file mode 100644 index 0000000..759dd1b --- /dev/null +++ b/Source/Aura/Public/Game/AuraGameModeBase.h @@ -0,0 +1,17 @@ +// Copyright HappyTanuki + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameModeBase.h" +#include "AuraGameModeBase.generated.h" + +/** + * + */ +UCLASS() +class AURA_API AAuraGameModeBase : public AGameModeBase +{ + GENERATED_BODY() + +}; diff --git a/Source/Aura/Public/Interaction/EnemyInterface.h b/Source/Aura/Public/Interaction/EnemyInterface.h new file mode 100644 index 0000000..226fbd9 --- /dev/null +++ b/Source/Aura/Public/Interaction/EnemyInterface.h @@ -0,0 +1,27 @@ +// Copyright HappyTanuki + +#pragma once + +#include "CoreMinimal.h" +#include "UObject/Interface.h" +#include "EnemyInterface.generated.h" + +// This class does not need to be modified. +UINTERFACE(MinimalAPI) +class UEnemyInterface : public UInterface +{ + GENERATED_BODY() +}; + +/** + * + */ +class AURA_API IEnemyInterface +{ + GENERATED_BODY() + + // Add interface functions to this class. This is the class that will be inherited to implement this interface. +public: + virtual void HighlightActor() = 0; + virtual void UnHighlightActor() = 0; +}; diff --git a/Source/Aura/Public/Player/AuraPlayerController.h b/Source/Aura/Public/Player/AuraPlayerController.h index 351e7c1..85fd595 100644 --- a/Source/Aura/Public/Player/AuraPlayerController.h +++ b/Source/Aura/Public/Player/AuraPlayerController.h @@ -6,6 +6,11 @@ #include "GameFramework/PlayerController.h" #include "AuraPlayerController.generated.h" +class UInputMappingContext; +class UInputAction; +struct FInputActionValue; +class IEnemyInterface; + /** * */ @@ -15,6 +20,22 @@ class AURA_API AAuraPlayerController : public APlayerController GENERATED_BODY() public: AAuraPlayerController(); + + virtual void PlayerTick(float DeltaTime) override; protected: virtual void BeginPlay() override; + + virtual void SetupInputComponent() override; +private: + UPROPERTY(EditAnywhere, Category = "Input") + TObjectPtr AuraContext; + + UPROPERTY(EditAnywhere, Category = "Input") + TObjectPtr MoveAction; + + void Move(const FInputActionValue& InputActionvalue); + + void CursorTrace(); + TScriptInterface LastActor; + TScriptInterface ThisActor; };