-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractableComponent.h
More file actions
129 lines (101 loc) · 4.9 KB
/
InteractableComponent.h
File metadata and controls
129 lines (101 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// ©2023 JDSherbert. All Rights Reserved.
#pragma once
#include <Runtime/Core/Public/CoreMinimal.h>
#include <Runtime/Engine/Classes/Components/ActorComponent.h>
#include "Project/Public/Interfaces/InteractionInterface.h"
#include "InteractableComponent.generated.h"
/* ---------------------------- Forward Declarations ----------------------------- */
class UInteractorComponent;
/* ------------------------------ Class Definition ------------------------------- */
/**
* Interactable Component Class. Receives calls from an Interactor Component.
* Define custom behaviour in the "Interact" method and the event calls in blueprint.
* Make sure to assign a UInputAction to the Interactor Component to define the bindings for this behavior!
* @since 19/01/2023
* @author JDSherbert
*/
UCLASS(ClassGroup = "Sherbert", Blueprintable, meta = (BlueprintSpawnableComponent))
class SHERBERT_API UBlueGhost_InteractableComponent : public UActorComponent, public IInteractionInterface
{
GENERATED_BODY()
public:
UInteractableComponent(const FObjectInitializer& ObjectInitializer);
private:
/** True = Interactable, False = not interactable! */
UPROPERTY(EditDefaultsOnly, Category = "Sherbert|Component|Interaction", meta = (AllowPrivateAccess = "true"))
bool bInteractable;
protected:
virtual void BeginPlay() override;
public:
void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
/**
* Interaction method. Should be called only by an Interactor Component when the input action is pressed, once.
* @param Instigator : The interactor component that is interacting with this object.
* @since 27/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, Category = "Sherbert|Component|Interaction")
virtual void Interact(UInteractorComponent* Instigator) override;
/**
* LookAt method. Should be called only by an Interactor Component when the raycast hits this interactable, every tick.
* @param Instigator : The Interactor component that is looking at this object.
* @param bActive : Sets if this Interactable is being looked at (and thus remains in the interactor's cache) or is being looked away from.
* @since 27/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, Category = "Sherbert|Component|Interaction")
void LookAt(UInteractorComponent* Instigator, const bool bActive = false);
/**
* Setter method. Should be called if the physics are being handled in a custom way, such as for picking up the attached actor.
* @param bActive : Sets if this Interactable is to be simulated by the physics engine.
* @return bool : True if simulating physics.
* @since 27/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, Category = "Sherbert|Component|Interaction")
bool SetPhysicsActive(bool bActive = false);
/**
* Getter method. Returns true if this can be interacted with.
* @return bool bInteractable : True if this is an interactable component that can be interacted with.
* @since 27/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Sherbert|Component|Interaction")
FORCEINLINE bool GetIsInteractable() const { return bInteractable; }
/**
* Setter method. Sets if this component can be interacted with by an interactor.
* Useful for turning on/off interaction functionality such as for a cutscene.
* @param bIsInteractable : Sets if this Interactable Component is interactable or not.
* @return bool bInteractable : True if this is an interactable component that can be interacted with.
* @since 27/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Sherbert|Component|Interaction")
FORCEINLINE bool SetIsInteractable(const bool bIsInteractable = true) { bInteractable = bIsInteractable; return bInteractable; }
/* ------------------------------ Events ------------------------------- */
/**
* Event: Triggers when the object is looked at.
* @param Instigator : The Interactor component that is looking at this object.
* @since 17/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintImplementableEvent, Category = "Sherbert|Component|Interaction")
void Event_OnLookAt(UInteractorComponent* Instigator);
/**
* Event: Triggers when the object is looked away from.
* @param Instigator : The Interactor component that is looking away from this object.
* @since 17/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintImplementableEvent, Category = "Sherbert|Component|Interaction")
void Event_OnLookAway(UInteractorComponent* Instigator);
/**
* Event: Triggers when the object is interacted with.
* @param Instigator : The interactor component that is interacting with this object.
* @since 17/01/2023
* @author JDSherbert
*/
UFUNCTION(BlueprintImplementableEvent, Category = "Sherbert|Component|Interaction")
void Event_OnInteraction(UInteractorComponent* Instigator);
};
/* ------------------------------------------------------------------------------- */