Skip to content
Snippets Groups Projects
Commit d7db3d0a authored by Kris Tabea Helwig's avatar Kris Tabea Helwig
Browse files

Merge branch 'dev/5.3' into feature/toolkit_examples

parents 6ba1388a 8881f577
No related branches found
No related tags found
2 merge requests!80UE5.3-2023.1-rc2,!77ContentExample-themed ToolkitExamples map.
Pipeline #349038 failed
This commit is part of merge request !77. Comments created here will be created in the context of that merge request.
Showing
with 285 additions and 26 deletions
...@@ -5,3 +5,17 @@ ...@@ -5,3 +5,17 @@
+ClassRedirects = (OldName="/Script/RWTHVRToolkit.VRWidgetInteractionComponent",NewName="/Script/RWTHVRToolkit.RWTHVRWidgetInteractionComponent") +ClassRedirects = (OldName="/Script/RWTHVRToolkit.VRWidgetInteractionComponent",NewName="/Script/RWTHVRToolkit.RWTHVRWidgetInteractionComponent")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RWTHVRPawn.PawnMovement",NewName="/Script/RWTHVRToolkit.RWTHVRPawn.CollisionHandlingMovement") +PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RWTHVRPawn.PawnMovement",NewName="/Script/RWTHVRToolkit.RWTHVRPawn.CollisionHandlingMovement")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RWTHVRPawn.PawnMovement",NewName="/Script/RWTHVRToolkit.RWTHVRPawn.CollisionHandlingMovement") +PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RWTHVRPawn.PawnMovement",NewName="/Script/RWTHVRToolkit.RWTHVRPawn.CollisionHandlingMovement")
+ClassRedirects = (OldName="/Script/RWTHVRToolkit.RaycastSelectionComponent",NewName="/Script/RWTHVRToolkit.RaycastInteractionComponent")
+ClassRedirects = (OldName="/Script/RWTHVRToolkit.GrabComponent",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent")
+FunctionRedirects = (OldName="/Script/RWTHVRToolkit.RaycastInteractionComponent.OnBeginSelect",NewName="/Script/RWTHVRToolkit.RaycastInteractionComponent.OnBeginInteraction")
+FunctionRedirects = (OldName="/Script/RWTHVRToolkit.RaycastInteractionComponent.OnEndSelect",NewName="/Script/RWTHVRToolkit.RaycastInteractionComponent.OnEndInteraction")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RaycastInteractionComponent.RayCastSelectInputAction",NewName="/Script/RWTHVRToolkit.RaycastInteractionComponent.RayCastInteractionInputAction")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.RaycastInteractionComponent.RayCastInteractionInputAction",NewName="/Script/RWTHVRToolkit.RaycastInteractionComponent.InteractionInputAction")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.PreviousGrabbablesInRange",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.PreviousInteractableComponentsInRange")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.GrabInputAction",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.InteractionInputAction")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.GrabSphereRadius",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.InteractionSphereRadius")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.bOnlyGrabClosestActor",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.bOnlyInteractWithClosestActor")
+FunctionRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.OnBeginGrab",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.OnBeginInteraction")
+FunctionRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.OnEndGrab",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.OnEndInteraction")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.PreviousGrabBehavioursInRange",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.PreviousInteractableComponentsInRange")
+PropertyRedirects = (OldName="/Script/RWTHVRToolkit.DirectInteractionComponent.CurrentGrabBehavioursInRange",NewName="/Script/RWTHVRToolkit.DirectInteractionComponent.CurrentInteractableComponentsInRange")
\ No newline at end of file
File added
File added
File deleted
File deleted
File deleted
File deleted
File added
File added
No preview for this file type
No preview for this file type
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Interactors/GrabComponent.h" #include "Interaction/Interactors/DirectInteractionComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "Interaction/Interactables/InteractableComponent.h" #include "Interaction/Interactables/InteractableComponent.h"
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "Utility/RWTHVRUtilities.h" #include "Utility/RWTHVRUtilities.h"
// Sets default values for this component's properties // Sets default values for this component's properties
UGrabComponent::UGrabComponent() UDirectInteractionComponent::UDirectInteractionComponent()
{ {
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these
// features off to improve performance if you don't need them. // features off to improve performance if you don't need them.
...@@ -20,11 +20,12 @@ UGrabComponent::UGrabComponent() ...@@ -20,11 +20,12 @@ UGrabComponent::UGrabComponent()
// ... // ...
} }
void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) void UDirectInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
TArray<UInteractableComponent*> CurrentGrabCompsInRange; TArray<UInteractableComponent*> CurrentInteractableCompsInRange;
TArray<FHitResult> OutHits; TArray<FHitResult> OutHits;
const ETraceTypeQuery TraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_PhysicsBody); const ETraceTypeQuery TraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_PhysicsBody);
...@@ -32,54 +33,55 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC ...@@ -32,54 +33,55 @@ void UGrabComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None; auto DebugTrace = bShowDebugTrace ? EDrawDebugTrace::ForOneFrame : EDrawDebugTrace::None;
UKismetSystemLibrary::SphereTraceMulti(GetWorld(), GetAttachParent()->GetComponentLocation(), UKismetSystemLibrary::SphereTraceMulti(GetWorld(), GetAttachParent()->GetComponentLocation(),
GetAttachParent()->GetComponentLocation(), GrabSphereRadius, TraceType, true, GetAttachParent()->GetComponentLocation(), InteractionSphereRadius,
ActorsToIgnore, DebugTrace, OutHits, true, FColor::Green); TraceType, true, ActorsToIgnore, DebugTrace, OutHits, true, FColor::Green);
for (FHitResult Hit : OutHits) for (FHitResult Hit : OutHits)
{ {
AActor* HitActor = Hit.GetActor(); AActor* HitActor = Hit.GetActor();
if (HitActor) if (HitActor)
{ {
UInteractableComponent* Grabbable = SearchForInteractable(HitActor); UInteractableComponent* InteractableComp = SearchForInteractable(HitActor);
if (Grabbable && Grabbable->HasInteractionTypeFlag(EInteractorType::Grab) && Grabbable->IsInteractable) if (InteractableComp && InteractableComp->HasInteractionTypeFlag(EInteractorType::Direct) &&
InteractableComp->IsInteractable)
{ {
Grabbable->HitResult = Hit; InteractableComp->HitResult = Hit;
CurrentGrabCompsInRange.AddUnique(Grabbable); CurrentInteractableCompsInRange.AddUnique(InteractableComp);
} }
} }
} }
CurrentGrabBehavioursInRange = CurrentGrabCompsInRange; CurrentInteractableComponentsInRange = CurrentInteractableCompsInRange;
// Call hover start events on all components that were not in range before // Call hover start events on all components that were not in range before
for (UInteractableComponent* CurrentGrabbable : CurrentGrabCompsInRange) for (UInteractableComponent* CurrentInteractableComp : CurrentInteractableCompsInRange)
{ {
if (!PreviousGrabBehavioursInRange.Contains(CurrentGrabbable)) if (!PreviousInteractableComponentsInRange.Contains(CurrentInteractableComp))
{ {
PreviousGrabBehavioursInRange.AddUnique(CurrentGrabbable); PreviousInteractableComponentsInRange.AddUnique(CurrentInteractableComp);
CurrentGrabbable->HandleOnHoverStartEvents(this, EInteractorType::Grab); CurrentInteractableComp->HandleOnHoverStartEvents(this, EInteractorType::Direct);
} }
} }
TArray<UInteractableComponent*> ComponentsToRemove; TArray<UInteractableComponent*> ComponentsToRemove;
// Call hover end events on all components that were previously in range, but not anymore // Call hover end events on all components that were previously in range, but not anymore
for (UInteractableComponent* PrevGrabbale : PreviousGrabBehavioursInRange) for (UInteractableComponent* PrevInteractableComp : PreviousInteractableComponentsInRange)
{ {
if (!CurrentGrabCompsInRange.Contains(PrevGrabbale)) if (!CurrentInteractableCompsInRange.Contains(PrevInteractableComp))
{ {
ComponentsToRemove.AddUnique(PrevGrabbale); ComponentsToRemove.AddUnique(PrevInteractableComp);
PrevGrabbale->HandleOnHoverEndEvents(this, EInteractorType::Grab); PrevInteractableComp->HandleOnHoverEndEvents(this, EInteractorType::Direct);
} }
} }
for (UInteractableComponent* CompToRemove : ComponentsToRemove) for (UInteractableComponent* CompToRemove : ComponentsToRemove)
{ {
PreviousGrabBehavioursInRange.Remove(CompToRemove); PreviousInteractableComponentsInRange.Remove(CompToRemove);
} }
} }
void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) void UDirectInteractionComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
{ {
IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent); IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent);
...@@ -94,62 +96,67 @@ void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) ...@@ -94,62 +96,67 @@ void UGrabComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
if (EI == nullptr) if (EI == nullptr)
return; return;
EI->BindAction(GrabInputAction, ETriggerEvent::Started, this, &UGrabComponent::OnBeginGrab); EI->BindAction(InteractionInputAction, ETriggerEvent::Started, this,
EI->BindAction(GrabInputAction, ETriggerEvent::Completed, this, &UGrabComponent::OnEndGrab); &UDirectInteractionComponent::OnBeginInteraction);
EI->BindAction(InteractionInputAction, ETriggerEvent::Completed, this,
&UDirectInteractionComponent::OnEndInteraction);
} }
void UGrabComponent::OnBeginGrab(const FInputActionValue& Value) void UDirectInteractionComponent::OnBeginInteraction(const FInputActionValue& Value)
{ {
const FVector GrabLocation = GetAttachParent()->GetComponentLocation(); const FVector InteractionLocation = GetAttachParent()->GetComponentLocation();
if (CurrentGrabBehavioursInRange.IsEmpty()) if (CurrentInteractableComponentsInRange.IsEmpty())
return; return;
if (bOnlyGrabClosestActor) if (bOnlyInteractWithClosestActor)
{ {
auto MinElement = *Algo::MinElementBy( auto MinElement = *Algo::MinElementBy(
CurrentGrabBehavioursInRange, CurrentInteractableComponentsInRange,
[&](auto Element) { return FVector(Element->GetOwner()->GetActorLocation() - GrabLocation).Size(); }); [&](auto Element)
MinElement->HandleOnActionStartEvents(this, GrabInputAction, Value, EInteractorType::Grab); { return FVector(Element->GetOwner()->GetActorLocation() - InteractionLocation).Size(); });
CurrentlyGrabbedComponents = {MinElement}; MinElement->HandleOnActionStartEvents(this, InteractionInputAction, Value, EInteractorType::Direct);
CurrentlyInteractedComponents = {MinElement};
} }
else else
{ {
CurrentlyGrabbedComponents.Reserve(CurrentlyGrabbedComponents.Num() + CurrentGrabBehavioursInRange.Num()); CurrentlyInteractedComponents.Reserve(CurrentlyInteractedComponents.Num() +
for (UInteractableComponent* Grabbable : CurrentGrabBehavioursInRange) CurrentInteractableComponentsInRange.Num());
for (UInteractableComponent* InteractableComp : CurrentInteractableComponentsInRange)
{ {
Grabbable->HandleOnActionStartEvents(this, GrabInputAction, Value, EInteractorType::Grab); InteractableComp->HandleOnActionStartEvents(this, InteractionInputAction, Value, EInteractorType::Direct);
CurrentlyGrabbedComponents.Add(Grabbable); CurrentlyInteractedComponents.Add(InteractableComp);
} }
} }
} }
void UGrabComponent::OnEndGrab(const FInputActionValue& Value) void UDirectInteractionComponent::OnEndInteraction(const FInputActionValue& Value)
{ {
for (auto& Component : CurrentlyGrabbedComponents) for (auto& Component : CurrentlyInteractedComponents)
{ {
if (Component.IsValid()) if (Component.IsValid())
{ {
Component->HandleOnActionEndEvents(this, GrabInputAction, Value, EInteractorType::Grab); Component->HandleOnActionEndEvents(this, InteractionInputAction, Value, EInteractorType::Direct);
} }
} }
} }
UInteractableComponent* UGrabComponent::SearchForInteractable(AActor* HitActor) UInteractableComponent* UDirectInteractionComponent::SearchForInteractable(AActor* HitActor)
{ {
UInteractableComponent* Grabbable = nullptr; UInteractableComponent* InteractableComponent = nullptr;
if (!HitActor) if (!HitActor)
{ {
UE_LOGFMT(Toolkit, Warning, "UGrabComponent::SearchForInteractable: HitActor was nullptr, returning nullptr"); UE_LOGFMT(Toolkit, Warning,
"UDirectInteractionComponent::SearchForInteractable: HitActor was nullptr, returning nullptr");
return nullptr; return nullptr;
} }
if (HitActor->IsChildActor()) if (HitActor->IsChildActor())
{ {
// search for UInteractable upwards from hit geometry and return first one found // search for UInteractable upwards from hit geometry and return first one found
Grabbable = HitActor->FindComponentByClass<UInteractableComponent>(); InteractableComponent = HitActor->FindComponentByClass<UInteractableComponent>();
// if Grabbable is not valid search at parent // if InteractableComponen is not valid search at parent
if (!Grabbable) if (!InteractableComponent)
{ {
HitActor = HitActor->GetParentActor(); HitActor = HitActor->GetParentActor();
if (HitActor) if (HitActor)
...@@ -161,18 +168,18 @@ UInteractableComponent* UGrabComponent::SearchForInteractable(AActor* HitActor) ...@@ -161,18 +168,18 @@ UInteractableComponent* UGrabComponent::SearchForInteractable(AActor* HitActor)
} }
else if (!HitActor->IsChildActor()) else if (!HitActor->IsChildActor())
{ {
Grabbable = HitActor->FindComponentByClass<UInteractableComponent>(); InteractableComponent = HitActor->FindComponentByClass<UInteractableComponent>();
} }
if (Grabbable) if (InteractableComponent)
{ {
// in the case, were we had to iterate up the hierarchy, check if we are allowed // in the case, were we had to iterate up the hierarchy, check if we are allowed
// to grab the parent via child geometry // to interact with the parent via child geometry
if (bSearchAtParent && !Grabbable->bAllowInteractionFromChildGeometry) if (bSearchAtParent && !InteractableComponent->bAllowInteractionFromChildGeometry)
{ {
Grabbable = nullptr; InteractableComponent = nullptr;
} }
} }
bSearchAtParent = false; bSearchAtParent = false;
return Grabbable; return InteractableComponent;
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "Interaction/Interactors/RWTHVRWidgetInteractionComponent.h" #include "Interaction/Interactors/RWTHVRWidgetInteractionComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "Interaction/Interactors/GrabComponent.h" #include "Interaction/Interactors/DirectInteractionComponent.h"
#include "Logging/StructuredLog.h" #include "Logging/StructuredLog.h"
#include "Misc/Optional.h" #include "Misc/Optional.h"
#include "Utility/RWTHVRUtilities.h" #include "Utility/RWTHVRUtilities.h"
......
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "Interaction/Interactors/RaycastSelectionComponent.h" #include "Interaction/Interactors/RaycastInteractionComponent.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "Interaction/Interactables/InteractableComponent.h" #include "Interaction/Interactables/InteractableComponent.h"
#include "Kismet/KismetSystemLibrary.h" #include "Kismet/KismetSystemLibrary.h"
// Sets default values for this component's properties // Sets default values for this component's properties
URaycastSelectionComponent::URaycastSelectionComponent() URaycastInteractionComponent::URaycastInteractionComponent()
{ {
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these
// features off to improve performance if you don't need them. // features off to improve performance if you don't need them.
...@@ -18,12 +18,12 @@ URaycastSelectionComponent::URaycastSelectionComponent() ...@@ -18,12 +18,12 @@ URaycastSelectionComponent::URaycastSelectionComponent()
} }
// Called every frame // Called every frame
void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickType, void URaycastInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) FActorComponentTickFunction* ThisTickFunction)
{ {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
UInteractableComponent* CurrentSelectable = nullptr; UInteractableComponent* NewInteractableComponent = nullptr;
TArray<AActor*> ActorsToIgnore; TArray<AActor*> ActorsToIgnore;
...@@ -40,15 +40,15 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT ...@@ -40,15 +40,15 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
AActor* HitActor = Hit.GetActor(); AActor* HitActor = Hit.GetActor();
if (HitActor) if (HitActor)
{ {
UInteractableComponent* Selectable = HitActor->FindComponentByClass<UInteractableComponent>(); UInteractableComponent* InteractableComponent = HitActor->FindComponentByClass<UInteractableComponent>();
if (Selectable && Selectable->IsInteractable) if (InteractableComponent && InteractableComponent->IsInteractable)
{ {
CurrentSelectable = Selectable; NewInteractableComponent = InteractableComponent;
Selectable->HitResult = Hit; InteractableComponent->HitResult = Hit;
} }
} }
CurrentInteractable = CurrentSelectable; CurrentInteractable = NewInteractableComponent;
if (CurrentInteractable != PreviousInteractable) if (CurrentInteractable != PreviousInteractable)
{ {
...@@ -61,19 +61,19 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT ...@@ -61,19 +61,19 @@ void URaycastSelectionComponent::TickComponent(float DeltaTime, ELevelTick TickT
PreviousInteractable = CurrentInteractable; PreviousInteractable = CurrentInteractable;
} }
void URaycastSelectionComponent::OnBeginSelect(const FInputActionValue& Value) void URaycastInteractionComponent::OnBeginInteraction(const FInputActionValue& Value)
{ {
if (CurrentInteractable && CurrentInteractable->HasInteractionTypeFlag(EInteractorType::Raycast)) if (CurrentInteractable && CurrentInteractable->HasInteractionTypeFlag(EInteractorType::Raycast))
CurrentInteractable->HandleOnActionStartEvents(this, RayCastSelectInputAction, Value, EInteractorType::Raycast); CurrentInteractable->HandleOnActionStartEvents(this, InteractionInputAction, Value, EInteractorType::Raycast);
} }
void URaycastSelectionComponent::OnEndSelect(const FInputActionValue& Value) void URaycastInteractionComponent::OnEndInteraction(const FInputActionValue& Value)
{ {
if (CurrentInteractable && CurrentInteractable->HasInteractionTypeFlag(EInteractorType::Raycast)) if (CurrentInteractable && CurrentInteractable->HasInteractionTypeFlag(EInteractorType::Raycast))
CurrentInteractable->HandleOnActionEndEvents(this, RayCastSelectInputAction, Value, EInteractorType::Raycast); CurrentInteractable->HandleOnActionEndEvents(this, InteractionInputAction, Value, EInteractorType::Raycast);
} }
void URaycastSelectionComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent) void URaycastInteractionComponent::SetupPlayerInput(UInputComponent* PlayerInputComponent)
{ {
IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent); IInputExtensionInterface::SetupPlayerInput(PlayerInputComponent);
...@@ -85,6 +85,8 @@ void URaycastSelectionComponent::SetupPlayerInput(UInputComponent* PlayerInputCo ...@@ -85,6 +85,8 @@ void URaycastSelectionComponent::SetupPlayerInput(UInputComponent* PlayerInputCo
if (!EI) if (!EI)
return; return;
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Started, this, &URaycastSelectionComponent::OnBeginSelect); EI->BindAction(InteractionInputAction, ETriggerEvent::Started, this,
EI->BindAction(RayCastSelectInputAction, ETriggerEvent::Completed, this, &URaycastSelectionComponent::OnEndSelect); &URaycastInteractionComponent::OnBeginInteraction);
EI->BindAction(InteractionInputAction, ETriggerEvent::Completed, this,
&URaycastInteractionComponent::OnEndInteraction);
} }
...@@ -6,7 +6,7 @@ enum EInteractorType : int ...@@ -6,7 +6,7 @@ enum EInteractorType : int
None = 0 UMETA(Hidden), None = 0 UMETA(Hidden),
Raycast = 1 << 0, Raycast = 1 << 0,
Spherecast = 1 << 1, Spherecast = 1 << 1,
Grab = 1 << 2, Direct = 1 << 2,
Reserved2 = 1 << 3, Reserved2 = 1 << 3,
Reserved3 = 1 << 4, Reserved3 = 1 << 4,
Reserved4 = 1 << 5, Reserved4 = 1 << 5,
......
...@@ -6,53 +6,51 @@ ...@@ -6,53 +6,51 @@
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "Interaction/Interactables/InteractableComponent.h" #include "Interaction/Interactables/InteractableComponent.h"
#include "Pawn/InputExtensionInterface.h" #include "Pawn/InputExtensionInterface.h"
#include "GrabComponent.generated.h" #include "DirectInteractionComponent.generated.h"
class UGrabbableComponent;
UCLASS(Abstract, Blueprintable) UCLASS(Abstract, Blueprintable)
class RWTHVRTOOLKIT_API UGrabComponent : public USceneComponent, public IInputExtensionInterface class RWTHVRTOOLKIT_API UDirectInteractionComponent : public USceneComponent, public IInputExtensionInterface
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
// Sets default values for this component's properties // Sets default values for this component's properties
UGrabComponent(); UDirectInteractionComponent();
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override; FActorComponentTickFunction* ThisTickFunction) override;
UPROPERTY(EditAnywhere, Category = "Input") UPROPERTY(EditAnywhere, Category = "Input")
class UInputAction* GrabInputAction; class UInputAction* InteractionInputAction;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Direct Interaction")
float GrabSphereRadius = 15.0; float InteractionSphereRadius = 15.0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Direct Interaction")
bool bShowDebugTrace = false; bool bShowDebugTrace = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Direct Interaction")
bool bOnlyGrabClosestActor = false; bool bOnlyInteractWithClosestActor = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Grabbing") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Direct Interaction")
TArray<AActor*> ActorsToIgnore; TArray<AActor*> ActorsToIgnore;
virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override;
private: private:
UFUNCTION() UFUNCTION()
void OnBeginGrab(const FInputActionValue& Value); void OnBeginInteraction(const FInputActionValue& Value);
UFUNCTION() UFUNCTION()
void OnEndGrab(const FInputActionValue& Value); void OnEndInteraction(const FInputActionValue& Value);
UPROPERTY() UPROPERTY()
TArray<UInteractableComponent*> PreviousGrabBehavioursInRange; TArray<UInteractableComponent*> PreviousInteractableComponentsInRange;
UPROPERTY() UPROPERTY()
TArray<UInteractableComponent*> CurrentGrabBehavioursInRange; TArray<UInteractableComponent*> CurrentInteractableComponentsInRange;
TArray<TWeakObjectPtr<UInteractableComponent>> CurrentlyGrabbedComponents; TArray<TWeakObjectPtr<UInteractableComponent>> CurrentlyInteractedComponents;
UInteractableComponent* SearchForInteractable(AActor* HitActor); UInteractableComponent* SearchForInteractable(AActor* HitActor);
......
...@@ -6,24 +6,24 @@ ...@@ -6,24 +6,24 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "RaycastSelectionComponent.generated.h" #include "RaycastInteractionComponent.generated.h"
UCLASS(Abstract, Blueprintable) UCLASS(Abstract, Blueprintable)
class RWTHVRTOOLKIT_API URaycastSelectionComponent : public USceneComponent, public IInputExtensionInterface class RWTHVRTOOLKIT_API URaycastInteractionComponent : public USceneComponent, public IInputExtensionInterface
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
// Sets default values for this component's properties // Sets default values for this component's properties
URaycastSelectionComponent(); URaycastInteractionComponent();
// Called every frame // Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override; FActorComponentTickFunction* ThisTickFunction) override;
UPROPERTY(EditAnywhere, Category = "Input") UPROPERTY(EditAnywhere, Category = "Input")
class UInputAction* RayCastSelectInputAction; class UInputAction* InteractionInputAction;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Raycast") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Raycast")
float TraceLength = 3000.0; float TraceLength = 3000.0;
...@@ -32,10 +32,10 @@ public: ...@@ -32,10 +32,10 @@ public:
private: private:
UFUNCTION() UFUNCTION()
void OnBeginSelect(const FInputActionValue& Value); void OnBeginInteraction(const FInputActionValue& Value);
UFUNCTION() UFUNCTION()
void OnEndSelect(const FInputActionValue& Value); void OnEndInteraction(const FInputActionValue& Value);
public: public:
virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment