Replaced Interactable Actor Class with Interaction Interface

This commit is contained in:
Rafal Swierczek 2023-10-18 00:02:16 +01:00
parent ab76177b16
commit dec1d761bf
9 changed files with 43 additions and 72 deletions

View File

@ -6,13 +6,13 @@
#include "MainBountyClass.h"
#include "SideBountyClass.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
#include "EndlessVendetta/InteractableActor.h"
#include "EndlessVendetta/InteractionInterface.h"
#include "EndlessVendetta/UserWidgets/PC_Display.h"
#include "GameFramework/Actor.h"
#include "BountyDirector.generated.h"
UCLASS()
class ENDLESSVENDETTA_API ABountyDirector : public AInteractableActor
class ENDLESSVENDETTA_API ABountyDirector : public AActor, public IInteractionInterface
{
GENERATED_BODY()

View File

@ -6,7 +6,7 @@
#include "Components/CapsuleComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InteractableActor.h"
#include "InteractionInterface.h"
#include "AI/EnemyCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/GameplayStatics.h"
@ -124,10 +124,8 @@ void AEndlessVendettaCharacter::Interact()
if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams)) return;
AActor* HitActor = OutHit.GetActor();
AInteractableActor* InteractableActor = Cast<AInteractableActor>(HitActor);
if (!IsValid(InteractableActor)) return;
InteractableActor->Interact();
IInteractionInterface* InteractableActor = Cast<IInteractionInterface>(HitActor);
if (InteractableActor) InteractableActor->Interact();
}

View File

@ -1,33 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "InteractableActor.h"
// Sets default values
AInteractableActor::AInteractableActor()
{
// 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;
}
// Called when the game starts or when spawned
void AInteractableActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AInteractableActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AInteractableActor::Interact()
{
UE_LOG(LogTemp, Warning, TEXT("Interacted with %s"), *GetName());
}

View File

@ -1,26 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "InteractableActor.generated.h"
UCLASS()
class ENDLESSVENDETTA_API AInteractableActor : public AActor
{
GENERATED_BODY()
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Sets default values for this actor's properties
AInteractableActor();
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void Interact();
};

View File

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "InteractionInterface.h"
// Add default functionality here for any IInteractionInterface 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 "InteractionInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UInteractionInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class ENDLESSVENDETTA_API IInteractionInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
virtual void Interact(){}
};