Skip to content
Snippets Groups Projects
Commit 02a453cd authored by Marcel Krüger's avatar Marcel Krüger
Browse files

refactor(interaction): Renames InteractableBase to InteractableComponent and...

refactor(interaction): Renames InteractableBase to InteractableComponent and Interactee folder to Interactables
parent 213d1418
Branches
Tags
1 merge request!42refactor(interaction): Change to a bitflag based sytem
Showing
with 51 additions and 49 deletions
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Interactees/ActionBehaviour.h"
#include "Interaction/Interactables/ActionBehaviour.h"
// We disable ticking here, as we are mainly interested in the events
UActionBehaviour::UActionBehaviour()
......
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction\Interactees\GrabBehavior.h"
#include "Interaction/Interactees/InteractableBase.h"
#include "Interaction/Interactables/GrabBehavior.h"
#include "Interaction/Interactables/InteractableComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Serialization/JsonTypes.h"
......@@ -60,9 +59,9 @@ void UGrabBehavior::OnActionStart(USceneComponent* TriggeredComponent, const UIn
if (bBlockOtherInteractionsWhileGrabbed)
{
TArray<UInteractableBase*> Interactables;
GetOwner()->GetComponents<UInteractableBase>(Interactables, false);
for (UInteractableBase* Interactable : Interactables)
TArray<UInteractableComponent*> Interactables;
GetOwner()->GetComponents<UInteractableComponent>(Interactables, false);
for (UInteractableComponent* Interactable : Interactables)
{
Interactable->RestrictInteractionToComponent(TriggeredComponent);
}
......@@ -84,9 +83,9 @@ void UGrabBehavior::OnActionEnd(USceneComponent* TriggeredComponent, const UInpu
if (bBlockOtherInteractionsWhileGrabbed)
{
TArray<UInteractableBase*> Interactables;
GetOwner()->GetComponents<UInteractableBase>(Interactables, false);
for (UInteractableBase* Interactable : Interactables)
TArray<UInteractableComponent*> Interactables;
GetOwner()->GetComponents<UInteractableComponent>(Interactables, false);
for (UInteractableComponent* Interactable : Interactables)
{
Interactable->ResetRestrictInteraction();
}
......
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Interactees/HoverBehaviour.h"
#include "Interaction/Interactables/HoverBehaviour.h"
void UHoverBehaviour::OnHoverStart(const USceneComponent* TriggeredComponent, FHitResult Hit)
{
......
// Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Interactees/InteractableBase.h"
#include "Interaction/Interactables/InteractableComponent.h"
#include "Interaction/Interactables/ActionBehaviour.h"
#include "Interaction/Interactables/HoverBehaviour.h"
#include "Interaction/Interactees/ActionBehaviour.h"
#include "Interaction/Interactees/HoverBehaviour.h"
void UInteractableBase::RestrictInteractionToComponents(const TArray<USceneComponent*>& Components)
void UInteractableComponent::RestrictInteractionToComponents(const TArray<USceneComponent*>& Components)
{
if (Components.IsEmpty())
{
......@@ -20,28 +19,29 @@ void UInteractableBase::RestrictInteractionToComponents(const TArray<USceneCompo
}
}
void UInteractableBase::RestrictInteractionToComponent(USceneComponent* Component)
void UInteractableComponent::RestrictInteractionToComponent(USceneComponent* Component)
{
TArray<USceneComponent*> Components;
Components.Add(Component);
RestrictInteractionToComponents(Components);
}
void UInteractableBase::ResetRestrictInteraction()
void UInteractableComponent::ResetRestrictInteraction()
{
bRestrictInteraction = false;
AllowedComponents.Empty();
}
// Called when the game starts
void UInteractableBase::BeginPlay()
void UInteractableComponent::BeginPlay()
{
Super::BeginPlay();
InitDefaultBehaviourReferences();
}
// This functions dispatches the HoverStart Event to the attached Hover Behaviour Components
void UInteractableBase::HandleOnHoverStartEvents(USceneComponent* TriggerComponent, const EInteractorType Interactor)
void UInteractableComponent::HandleOnHoverStartEvents(USceneComponent* TriggerComponent,
const EInteractorType Interactor)
{
// We early return if there the InteractorFilter is set and the Interactor is allowed.
if (!(InteractorFilter == EInteractorType::None || InteractorFilter & Interactor)) return;
......@@ -57,7 +57,7 @@ void UInteractableBase::HandleOnHoverStartEvents(USceneComponent* TriggerCompone
}
// This functions dispatches the HoverEnd Event to the attached Hover Behaviour Components
void UInteractableBase::HandleOnHoverEndEvents(USceneComponent* TriggerComponent, const EInteractorType Interactor)
void UInteractableComponent::HandleOnHoverEndEvents(USceneComponent* TriggerComponent, const EInteractorType Interactor)
{
// We early return if there the InteractorFilter is set and the Interactor is allowed.
if (!(InteractorFilter == EInteractorType::None || InteractorFilter & Interactor)) return;
......@@ -73,7 +73,8 @@ void UInteractableBase::HandleOnHoverEndEvents(USceneComponent* TriggerComponent
}
// This functions dispatches the ActionStart Event to the attached Action Behaviour Components
void UInteractableBase::HandleOnActionStartEvents(USceneComponent* TriggerComponent, const UInputAction* InputAction,
void UInteractableComponent::HandleOnActionStartEvents(USceneComponent* TriggerComponent,
const UInputAction* InputAction,
const FInputActionValue& Value,
const EInteractorType Interactor)
{
......@@ -91,7 +92,7 @@ void UInteractableBase::HandleOnActionStartEvents(USceneComponent* TriggerCompon
}
// This functions dispatches the ActionEnd Event to the attached Action Behaviour Components
void UInteractableBase::HandleOnActionEndEvents(USceneComponent* TriggerComponent, const UInputAction* InputAction,
void UInteractableComponent::HandleOnActionEndEvents(USceneComponent* TriggerComponent, const UInputAction* InputAction,
const FInputActionValue& Value,
const EInteractorType Interactor)
{
......@@ -110,7 +111,7 @@ void UInteractableBase::HandleOnActionEndEvents(USceneComponent* TriggerComponen
// This function searches for Action and Hover Behaviours that are attached to the Actor iff they are not set
// manually by the user.
void UInteractableBase::InitDefaultBehaviourReferences()
void UInteractableComponent::InitDefaultBehaviourReferences()
{
// only do this if empty, otherwise the user has explicitly stated, which behaviors to include
if (OnHoverBehaviours.IsEmpty())
......@@ -133,7 +134,7 @@ void UInteractableBase::InitDefaultBehaviourReferences()
}
}
bool UInteractableBase::IsComponentAllowed(USceneComponent* Component) const
bool UInteractableComponent::IsComponentAllowed(USceneComponent* Component) const
{
if (bRestrictInteraction)
{
......
......@@ -5,6 +5,8 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Interaction/Interactables/InteractableComponent.h"
#include "Interaction/Interactables/InteractionBitSet.h"
#include "Kismet/GameplayStatics.h"
......@@ -23,7 +25,7 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
TArray<UInteractableBase*> CurrentGrabCompsInRange;
TArray<UInteractableComponent*> CurrentGrabCompsInRange;
TArray<AActor*> ActorsToIgnore;
TArray<FHitResult> OutHits;
......@@ -41,7 +43,7 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
AActor* HitActor = Hit.GetActor();
if (HitActor)
{
UInteractableBase* Grabbable = HitActor->FindComponentByClass<UInteractableBase>();
UInteractableComponent* Grabbable = HitActor->FindComponentByClass<UInteractableComponent>();
if (Grabbable && Grabbable->HasInteractionTypeFlag(EInteractorType::Grab) && Grabbable->IsInteractable)
{
Grabbable->HitResult = Hit;
......@@ -53,7 +55,7 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
CurrentGrabbableInRange = CurrentGrabCompsInRange;
// Call hover start events on all components that were not in range before
for (UInteractableBase* CurrentGrabbale : CurrentGrabCompsInRange)
for (UInteractableComponent* CurrentGrabbale : CurrentGrabCompsInRange)
{
if (!PreviousGrabbablesInRange.Contains(CurrentGrabbale))
{
......@@ -62,10 +64,10 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
}
}
TArray<UInteractableBase*> ComponentsToRemove;
TArray<UInteractableComponent*> ComponentsToRemove;
// Call hover end events on all components that were previously in range, but not anymore
for (UInteractableBase* PrevGrabbale : PreviousGrabbablesInRange)
for (UInteractableComponent* PrevGrabbale : PreviousGrabbablesInRange)
{
if (!CurrentGrabCompsInRange.Contains(PrevGrabbale))
{
......@@ -74,7 +76,7 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
}
}
for (UInteractableBase* CompToRemove : ComponentsToRemove)
for (UInteractableComponent* CompToRemove : ComponentsToRemove)
{
PreviousGrabbablesInRange.Remove(CompToRemove);
}
......@@ -105,7 +107,7 @@ void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
void UGrabComponent::OnBeginGrab(const FInputActionValue& Value)
{
for (UInteractableBase* Grabbale : CurrentGrabbableInRange)
for (UInteractableComponent* Grabbale : CurrentGrabbableInRange)
{
Grabbale->HandleOnActionStartEvents(this, GrabInputAction, Value, EInteractorType::Grab);
}
......@@ -113,7 +115,7 @@ void UGrabComponent::OnBeginGrab(const FInputActionValue& Value)
void UGrabComponent::OnEndGrab(const FInputActionValue& Value)
{
for (UInteractableBase* Grabbale : CurrentGrabbableInRange)
for (UInteractableComponent* Grabbale : CurrentGrabbableInRange)
{
Grabbale->HandleOnActionEndEvents(this, GrabInputAction, Value, EInteractorType::Grab);
}
......
......@@ -5,7 +5,7 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Interaction/Interactees/InteractableBase.h"
#include "Interaction/Interactables/InteractableComponent.h"
#include "Kismet/KismetSystemLibrary.h"
// Sets default values for this component's properties
......@@ -24,7 +24,7 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
UInteractableBase* CurrentSelectable = nullptr;
UInteractableComponent* CurrentSelectable = nullptr;
TArray<AActor*> ActorsToIgnore;
......@@ -42,7 +42,7 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
AActor* HitActor = Hit.GetActor();
if (HitActor)
{
UInteractableBase* Selectable = HitActor->FindComponentByClass<UInteractableBase>();
UInteractableComponent* Selectable = HitActor->FindComponentByClass<UInteractableComponent>();
if (Selectable && Selectable->IsInteractable)
{
CurrentSelectable = Selectable;
......
......@@ -6,7 +6,7 @@
#include "InputAction.h"
#include "InteractionBitSet.h"
#include "Components/ActorComponent.h"
#include "InteractableBase.generated.h"
#include "InteractableComponent.generated.h"
struct FInputActionValue;
......@@ -29,7 +29,7 @@ class UHoverBehaviour;
*
*/
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class RWTHVRTOOLKIT_API UInteractableBase : public UActorComponent
class RWTHVRTOOLKIT_API UInteractableComponent : public UActorComponent
{
GENERATED_BODY()
......
......@@ -4,7 +4,7 @@
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "Interaction/Interactees/InteractableBase.h"
#include "Interaction/Interactables/InteractableComponent.h"
#include "Pawn/InputExtensionInterface.h"
#include "GrabComponent.generated.h"
......@@ -44,8 +44,8 @@ private:
void OnEndGrab(const FInputActionValue& Value);
UPROPERTY()
TArray<UInteractableBase*> PreviousGrabbablesInRange;
TArray<UInteractableComponent*> PreviousGrabbablesInRange;
UPROPERTY()
TArray<UInteractableBase*> CurrentGrabbableInRange;
TArray<UInteractableComponent*> CurrentGrabbableInRange;
};
......@@ -46,8 +46,8 @@ public:
private:
UPROPERTY()
UInteractableBase* PreviousInteractable;
UInteractableComponent* PreviousInteractable;
UPROPERTY()
UInteractableBase* CurrentInteractable;
UInteractableComponent* CurrentInteractable;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment