[박치영] C++ 기본구조 작업

main
PCYPC\pcy35 2023-07-27 20:47:58 +09:00
parent e35ed0a933
commit e2d1c17b96
33 changed files with 267 additions and 43 deletions

View File

@ -68,3 +68,60 @@ ConnectionType=USBOnly
bUseManualIPAddress=False
ManualIPAddress=
[/Script/Engine.CollisionProfile]
-Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision",bCanModify=False)
-Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
-Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ",bCanModify=False)
-Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ",bCanModify=False)
-Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic",Response=ECR_Block),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.",bCanModify=False)
-Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors",bCanModify=False)
-Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors",bCanModify=False)
-Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.",bCanModify=False)
-Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.",bCanModify=False)
-Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.",bCanModify=False)
-Profiles=(Name="UI",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Block),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False)
+Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision")
+Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.")
+Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ")
+Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ")
+Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic"),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.")
+Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.")
+Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors")
+Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors")
+Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.")
+Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.")
+Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.")
+Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.")
+Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.")
+Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ")
+DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Block,bTraceType=False,bStaticObject=False,Name="Interactable")
-ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall")
-ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn")
-ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic")
-ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor")
-ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic")
+ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall")
+ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn")
+ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic")
+ProfileRedirects=(OldName="SkeletalMeshActor",NewName="PhysicsActor")
+ProfileRedirects=(OldName="InvisibleActor",NewName="InvisibleWallDynamic")
-CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic")
-CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic")
-CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
-CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")
+CollisionChannelRedirects=(OldName="Static",NewName="WorldStatic")
+CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic")
+CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle")
+CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn")

View File

@ -3,7 +3,6 @@
#include "Actor/BaseEquippable.h"
#include "GameFramework/Character.h"
//#include "SkeletalMesh.h"
// Sets default values
ABaseEquippable::ABaseEquippable()
@ -11,6 +10,15 @@ ABaseEquippable::ABaseEquippable()
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
RootComponent = DefaultSceneRoot;
ItemSkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("ItemSkeletalMesh"));
ItemSkeletalMesh->SetupAttachment(RootComponent);
ItemStaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ItemStaticMesh"));
ItemStaticMesh->SetupAttachment(RootComponent);
ItemStaticMesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}
void ABaseEquippable::AttachActor(const FName SocketName)

View File

@ -22,6 +22,14 @@ public:
virtual void OnUnequipped();
virtual void SetIsEquipped(bool IsEquipped);
virtual bool GetIsEquipped();
protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class USceneComponent* DefaultSceneRoot;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
class USkeletalMeshComponent* ItemSkeletalMesh;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Mesh, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* ItemStaticMesh;
protected:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
bool bIsEquipped;

View File

@ -3,6 +3,8 @@
#include "Actor/BaseWeapon.h"
#include "Components/CombatComponent.h"
#include "GameFramework/Character.h"
#include "Animation/CombatAnimInstance.h"
ABaseWeapon::ABaseWeapon()
{
@ -13,14 +15,20 @@ void ABaseWeapon::OnEquipped()
{
SetIsEquipped(true);
AActor* owner = GetOwner();
UCombatComponent* component = owner->GetComponentByClass<UCombatComponent>();
CombatComponent = owner->GetComponentByClass<UCombatComponent>();
if (component->GetCombatEnabled())
if (CombatComponent->GetCombatEnabled())
AttachActor(HandSocketName);
else
AttachActor(AttachSocketName);
CombatComponent->SetMainWeapon(this);
//TODO Update Combat Type
ACharacter* character = Cast<ACharacter>(owner);
if (character)
{
UCombatAnimInstance* animInstance = Cast<UCombatAnimInstance>(character->GetMesh()->GetAnimInstance());
animInstance->UpdateCombatType(CombatType);
}
}

View File

@ -10,6 +10,8 @@
/**
*
*/
class UAnimMontage;
UCLASS()
class D1_API ABaseWeapon : public ABaseEquippable
{
@ -21,6 +23,9 @@ public:
public:
void OnEquipped() override;
public:
FORCEINLINE UAnimMontage* GetEnterCombat() const { return EnterCombat; }
FORCEINLINE UAnimMontage* GetExitCombat() const { return ExitCombat; }
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Initialization")
FName HandSocketName;
@ -31,7 +36,7 @@ protected:
TObjectPtr<class UCombatComponent> CombatComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Animations")
TObjectPtr<class UAnimMontage> EnterCombat;
TObjectPtr<UAnimMontage> EnterCombat;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Animations")
TObjectPtr<class UAnimMontage> ExitCombat;
TObjectPtr<UAnimMontage> ExitCombat;
};

View File

@ -2,13 +2,40 @@
#include "Actor/PickupActor.h"
#include "Actor/BaseEquippable.h"
#include "Components/SceneComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Components/SphereComponent.h"
// Sets default values
APickupActor::APickupActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
DefaultSceneRoot = CreateDefaultSubobject<USceneComponent>(TEXT("DefaultSceneRoot"));
RootComponent = DefaultSceneRoot;
Cube = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Cube"));
Cube->SetupAttachment(RootComponent);
Sphere = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
Sphere->SetupAttachment(Cube);
}
void APickupActor::Interact(AActor* Caller)
{
if (Caller == nullptr)
return;
APawn* pawn = Cast<APawn>(Caller);
if (pawn != nullptr)
{
FActorSpawnParameters spawnParam;
spawnParam.Owner = Caller;
spawnParam.Instigator = pawn;
ABaseEquippable* SpawnItem = Cast<ABaseEquippable>(GetWorld()->SpawnActor(Item, &GetActorTransform(),spawnParam));
if(SpawnItem)
SpawnItem->OnEquipped();
}
}

View File

@ -4,10 +4,11 @@
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Interface/Interact.h"
#include "PickupActor.generated.h"
UCLASS()
class D1_API APickupActor : public AActor
class D1_API APickupActor : public AActor, public IInteract
{
GENERATED_BODY()
@ -15,6 +16,19 @@ public:
// Sets default values for this actor's properties
APickupActor();
private:
public:
virtual void Interact(AActor* Caller) override;
private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class USceneComponent> DefaultSceneRoot;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UStaticMeshComponent> Cube;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class USphereComponent> Sphere;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TSubclassOf<class ABaseEquippable> Item;
};

View File

@ -19,14 +19,16 @@ void UCombatAnimInstance::NativeUpdateAnimation(float DeltaSeconds)
{
Super::NativeUpdateAnimation(DeltaSeconds);
if (CharacterMovementComponent == nullptr)
return;
IsFalling = CharacterMovementComponent->IsFalling();
Velocity = CharacterMovementComponent->Velocity;
FVector2D vel = { Velocity.X, Velocity.Y };
GroundSpeed = vel.Length();
ShouldMove = (GroundSpeed > 3.f) && (CharacterMovementComponent->GetCurrentAcceleration().Length() != 0);
IsFalling = CharacterMovementComponent->IsFalling();
}
void UCombatAnimInstance::UpdateCombatType(ECombatType combatType)

View File

@ -9,7 +9,10 @@
#include "GameFramework/SpringArmComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Interface/Interact.h"
#include "Actor/BaseWeapon.h"
#include "Components//CombatComponent.h"
//////////////////////////////////////////////////////////////////////////
// ACombatCharacter
@ -50,6 +53,8 @@ ACombatCharacter::ACombatCharacter()
// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character)
// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
CombatComponent = CreateDefaultSubobject<UCombatComponent>(TEXT("CombatComponent"));
}
void ACombatCharacter::BeginPlay()
@ -75,7 +80,7 @@ void ACombatCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerIn
// Set up action bindings
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
//Jumping@
//Jumping
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
@ -85,8 +90,12 @@ void ACombatCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerIn
//Looking
EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACombatCharacter::Look);
}
//Interact
EnhancedInputComponent->BindAction(InteractAction, ETriggerEvent::Started, this, &ACombatCharacter::Interact);
//ToggleCombat
EnhancedInputComponent->BindAction(ToggleCombatAction, ETriggerEvent::Started, this, &ACombatCharacter::ToggleCombat);
}
}
void ACombatCharacter::Move(const FInputActionValue& Value)
@ -125,6 +134,51 @@ void ACombatCharacter::Look(const FInputActionValue& Value)
}
}
void ACombatCharacter::Interact(const FInputActionValue& Value)
{
bool bInput = Value.Get<bool>();
//static bool SphereTraceSingleForObjects(const UObject * WorldContextObject,
// const FVector Start,
// const FVector End,
// float Radius,
// const TArray<TEnumAsByte<EObjectTypeQuery> > &ObjectTypes,
// bool bTraceComplex,
// const TArray<AActor*>&ActorsToIgnore,
// EDrawDebugTrace::Type DrawDebugType,
// FHitResult & OutHit, bool bIgnoreSelf,
// FLinearColor TraceColor = FLinearColor::Red,
// FLinearColor TraceHitColor = FLinearColor::Green,
// float DrawTime = 5.0f);
TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
TEnumAsByte<EObjectTypeQuery> InteractiveType = UEngineTypes::ConvertToObjectType(ECollisionChannel::ECC_GameTraceChannel1);
ObjectTypes.Add(InteractiveType);
TArray<AActor*> ActorsToIgnore;
FHitResult OutHit;
if (UKismetSystemLibrary::SphereTraceSingleForObjects(GetWorld(), GetActorLocation(), GetActorLocation(), 100.f, ObjectTypes, false, ActorsToIgnore, EDrawDebugTrace::ForDuration, OutHit, true))
{
IInteract* interactObject = Cast<IInteract>(OutHit.GetActor());
if (interactObject)
interactObject->Interact(this);
}
}
void ACombatCharacter::ToggleCombat(const FInputActionValue& Value)
{
bool bInput = Value.Get<bool>();
ABaseWeapon* baseWeapon = CombatComponent->GetMainWeapon();
bool isCombatEnabled = CombatComponent->GetCombatEnabled();
if (!baseWeapon)
return;
if (!isCombatEnabled)
PlayAnimMontage(baseWeapon->GetEnterCombat());
else
PlayAnimMontage(baseWeapon->GetExitCombat());
}

View File

@ -37,19 +37,25 @@ class ACombatCharacter : public ACharacter
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* LookAction;
/* Interact Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* InteractAction;
/* ToggleCombat Input Action */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
class UInputAction* ToggleCombatAction;
public:
ACombatCharacter();
protected:
/** Called for movement input */
void Move(const FInputActionValue& Value);
/** Called for looking input */
void Look(const FInputActionValue& Value);
void Interact(const FInputActionValue& Value);
void ToggleCombat(const FInputActionValue& Value);
protected:
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
@ -62,5 +68,9 @@ public:
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
/** Returns FollowCamera subobject **/
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="Components", meta=(AllowPrivateAccess="true"))
TObjectPtr<class UCombatComponent> CombatComponent;
};

View File

@ -5,6 +5,7 @@
#include "Actor/BaseWeapon.h"
#include "Enums/CombatType.h"
#include "GameFramework/Character.h"
#include "Interface/IAnimInstance.h"
// Sets default values for this component's properties
UCombatComponent::UCombatComponent()
@ -16,6 +17,24 @@ UCombatComponent::UCombatComponent()
// ...
}
void UCombatComponent::SetCombatEnabled(bool bInputCombat)
{
bCombatEnabled = bInputCombat;
ACharacter* character = Cast<ACharacter>(GetOwner());
if (character)
{
IIAnimInstance* Animinstance = Cast<IIAnimInstance>(character->GetMesh()->GetAnimInstance());
if (Animinstance)
Animinstance->UpdateCombatEnabled(bInputCombat);
}
}
bool UCombatComponent::GetCombatEnabled()
{
return bCombatEnabled;
}
void UCombatComponent::SetMainWeapon(ABaseWeapon* NewWeapon)
{
if (IsValid(MainWeapon))
@ -26,27 +45,3 @@ void UCombatComponent::SetMainWeapon(ABaseWeapon* NewWeapon)
MainWeapon = NewWeapon;
}
ABaseWeapon* UCombatComponent::GetMainWeapon()
{
return MainWeapon;
}
void UCombatComponent::SetCombatEnabled(bool bInputCombat)
{
bCombatEnabled = bInputCombat;
ACharacter* character = Cast<ACharacter>(GetOwner());
if (character)
{
//TODO : AnimInstance ÈÄ¿¡ ó¸®
//character->GetMesh()->GetAnimInstance();
}
}
bool UCombatComponent::GetCombatEnabled()
{
return bCombatEnabled;
}

View File

@ -18,10 +18,14 @@ public:
UCombatComponent();
public:
void SetMainWeapon(ABaseWeapon* NewWeapon);
ABaseWeapon* GetMainWeapon();
UFUNCTION(BlueprintCallable)
void SetCombatEnabled(bool bInputCombat);
UFUNCTION(BlueprintCallable)
bool GetCombatEnabled();
void SetMainWeapon(ABaseWeapon* NewWeapon);
FORCEINLINE ABaseWeapon* GetMainWeapon() const { return MainWeapon; }
private:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess="true"))
TObjectPtr<ABaseWeapon> MainWeapon;

View File

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interface/Interact.h"
// Add default functionality here for any IInteract functions that are not pure virtual.

View File

@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "Interact.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UInteract : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class D1_API IInteract
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
virtual void Interact(AActor* Caller) = 0;
};