5#include "CoreMinimal.h"
6#include "Components/ActorComponent.h"
7#include "Runtime/CoreUObject/Public/UObject/TextProperty.h"
8#include "InteractableComponent.generated.h"
27 GENERATED_USTRUCT_BODY()
30 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = HighlightableComponent)
31 bool bIsHighlightable = true;
32 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (MultiLine = "true", EditCondition = "bIsHighlightable"))
33 FText HighlightText = NSLOCTEXT("
ProjectX", "cmd_interact", "Interact");
36UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
37class PROJECTX_API UInteractableComponent : public UActorComponent
39 GENERATED_UCLASS_BODY()
43 virtual void BeginPlay()
override;
44 virtual void Deactivate()
override;
48 virtual bool CanSelect(APlayerController* Sender, UPrimitiveComponent* Component)
const;
49 bool IsValidInteraction(APlayerController* Sender)
const;
51 virtual void Select(APlayerController* Sender, UPrimitiveComponent* Component);
52 virtual void HoldSelect(APlayerController* Sender, UPrimitiveComponent* Component);
53 virtual void StartHold(APlayerController* Sender, UPrimitiveComponent* Component);
54 virtual void ExitHold(APlayerController* Sender, UPrimitiveComponent* Component);
56 UFUNCTION(BlueprintCallable, Category =
"Interactable")
57 void SetHighlightText(FText NewHighlightText);
58 UFUNCTION(BlueprintCallable, Category =
"Interactable")
59 void SetHighlightable(
bool bHighlightable);
60 UFUNCTION(BlueprintCallable, Category =
"Interactable")
63 virtual void Highlight(APlayerController* Sender, UPrimitiveComponent* Component);
64 virtual void ExitHighlight(APlayerController* Sender, UPrimitiveComponent* Component);
66 UFUNCTION(BlueprintPure, Category =
"Interactable")
67 bool CanHighlight(
const UPrimitiveComponent* Component)
const;
68 UFUNCTION(BlueprintPure, Category =
"Interactable")
69 FText GetHighlightText(
const UPrimitiveComponent* Component,
const APlayerController* EventSender = NULL)
const;
70 UFUNCTION(BlueprintPure, Category =
"Interactable")
72 UFUNCTION(BlueprintPure, Category =
"Interactable")
74 UFUNCTION(BlueprintPure, Category =
"Interactable")
75 FORCEINLINE
float GetHoldTime()
const {
return HoldDuration; }
76 UFUNCTION(BlueprintPure, Category =
"Interactable")
77 FORCEINLINE
bool CanInteract()
const {
return bIsInteractable; }
78 void UpdateIsInteractable(
bool bCanInteract) { bIsInteractable = bCanInteract; }
82 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
83 FActorHighlightSignature OnHighlight;
84 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
85 FActorHighlightExitSignature OnHighlightExit;
86 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
87 FActorSelectedSignature OnSelected;
88 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
89 FActorHoldSelectedSignature OnHoldSelected;
90 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
91 FActorHoldSelectedSignature OnHoldStarted;
92 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
93 FActorHoldSelectedSignature OnHoldExited;
94 UPROPERTY(BlueprintAssignable, Category =
"Interactable Events")
95 FActorValidInteractionSignature OnValidInteractionUpdatedEvent;
99 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category =
"Highlight Settings", meta = (AllowPrivateAccess =
true))
100 bool bIsHighlightable =
true;
102 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, meta = (MultiLine =
"true", EditCondition =
"bIsHighlightable", AllowPrivateAccess =
true), Category =
"Highlight Settings")
103 FText HighlightText = NSLOCTEXT(
"ProjectX",
"cmd_interact",
"Interact");
105 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category =
"Interactable", meta = (AllowPrivateAccess =
true))
108 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category =
"Interactable", meta = (EditCondition =
"bAllowHoldInteraction", AllowPrivateAccess =
true))
109 float HoldDuration = 1.f;
111 bool bIsInteractable =
true;
113 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, meta = (MultiLine =
"true", AllowPrivateAccess =
true), Category =
"Highlight Settings")
114 TMap<UPrimitiveComponent*, FHighlightableComponent> PerComponentHighlightText;
116 class UMeshComponent* Mesh;
EInteractionType
Definition: InteractableComponent.h:18
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FActorHighlightSignature, APlayerController *, Sender, UPrimitiveComponent *, Component)
Definition: ProjectX.Build.cs:6
Definition: InteractableComponent.h:26