4#include "CoreMinimal.h"
5#include "Components/ActorComponent.h"
6#include "InteractionComponent.generated.h"
8class UInteractableComponent;
9class APlayerController;
24UCLASS( ClassGroup=(
Custom), meta=(BlueprintSpawnableComponent) )
25class PROJECTX_API UInteractionComponent :
public UActorComponent
31 UPROPERTY(EditDefaultsOnly)
32 float InteractionDistance = 500.0f;
34 UPROPERTY(EditDefaultsOnly)
35 float ServerInteractionDistanceAllowableError = 1000.0f;
37 UPROPERTY(BlueprintAssignable, Category = "Interaction Events")
38 FHighlightTextSignature OnHighlightEnter;
39 UPROPERTY(BlueprintAssignable, Category = "Interaction Events")
40 FHighlightNoTextSignature OnHighlightExit;
41 UPROPERTY(BlueprintAssignable, Category = "Interaction Events")
42 FInteractionErrorSignature OnInteractionError;
43 UPROPERTY(BlueprintAssignable, Category = "Interaction Events")
44 FHoldSignature OnHoldInteraction;
45 UPROPERTY(BlueprintAssignable, Category = "Interaction Events")
46 FHoldStopSignature OnHoldInteractionStop;
48 void UpdateCanInteract(
bool bNewCanInteract);
50 bool HasValidInteractionTarget() const;
55 FTimerHandle HoldTimerHandle;
56 UInteractableComponent* TargetCache;
57 mutable APlayerController* PlayerController;
59 UInteractionComponent();
61 APlayerController* GetPlayerController() const;
62 FHitResult FindTargetInteractable() const;
63 void GetTarget(UInteractableComponent*& Target, UPrimitiveComponent*& TargetComponent) const;
65 virtual
void TickComponent(
float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
72 void FinishHoldInteract(UInteractableComponent* HitInteractable, UPrimitiveComponent* HitComponent);
74 void ClearHoldInteract();
76 void HoldInteract(UInteractableComponent* Target,UPrimitiveComponent* HitComponent);
77 bool IsValidInteraction(const UInteractableComponent* HitInteractable, UPrimitiveComponent* HitComponent, const
bool bDisplayErrors = true) const;
78 UFUNCTION(Reliable,
Server, WithValidation)
79 void Server_Select(UInteractableComponent* HitInteractable, UPrimitiveComponent* HitComponent);
80 UFUNCTION(Reliable,
Server, WithValidation)
81 void Server_Hold(UInteractableComponent* HitInteractable, UPrimitiveComponent* HitComponent);
82 UFUNCTION(Reliable,
Server, WithValidation)
83 void Server_StopHold();
85 bool bCanInteract = true;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams(FHighlightTextSignature, FText, HighlightText, UInteractableComponent *, Interactable, UPrimitiveComponent *, Component, APlayerController *, Sender)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FInteractionErrorSignature, EInteractionError, Error)
EInteractionError
Definition: InteractionComponent.h:13
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FHoldStopSignature, UInteractableComponent *, Interactable, UPrimitiveComponent *, Component, APlayerController *, Sender)
Definition: ProjectXCharacter.h:128