-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteractableComponent.cpp
More file actions
74 lines (57 loc) · 2.29 KB
/
InteractableComponent.cpp
File metadata and controls
74 lines (57 loc) · 2.29 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
// ©2023 JDSherbert. All Rights Reserved.
#include "Project/Public/Components/InteractableComponent.h"
#include "Project/Public/Components/InteractorComponent.h"
/* ---------------------------- Method Definitions ------------------------------- */
UInteractableComponent::UInteractableComponent(const FObjectInitializer& ObjectInitializer)
: bInteractable(true)
{
PrimaryComponentTick.bCanEverTick = true;
SetIsReplicatedByDefault(true);
}
/* ------------------------------------------------------------------------------- */
void UInteractableComponent::BeginPlay()
{
Super::BeginPlay();
}
/* ------------------------------------------------------------------------------- */
void UInteractableComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
/* ------------------------------------------------------------------------------- */
void UInteractableComponent::Interact(UInteractorComponent* Instigator)
{
if (GetIsInteractable())
{
Event_OnInteraction(Instigator);
}
// You can add additional functionality here if you like.
// Be aware it will apply to all of these, so I'd recommend inheriting this class instead and doing it there.
// OR you could define/call an implemented interface for custom handling per object.
}
/* ------------------------------------------------------------------------------- */
void UInteractableComponent::LookAt(UInteractorComponent* Instigator, const bool bActive)
{
if (GetIsInteractable())
{
Instigator->DisplayInteractionUIWidget(bActive);
(bActive) ? Event_OnLookAt(Instigator) : Event_OnLookAway(Instigator);
}
}
/* ------------------------------------------------------------------------------- */
bool UInteractableComponent::SetPhysicsActive(bool bActive /*= false*/)
{
if (AActor* Owner = GetOwner())
{
if (UActorComponent* ActorComponent = Owner->GetComponentByClass(UPrimitiveComponent::StaticClass()))
{
if (UPrimitiveComponent* PrimitiveComponent = CastChecked<UPrimitiveComponent>(ActorComponent))
{
PrimitiveComponent->SetSimulatePhysics(bActive);
return PrimitiveComponent->IsSimulatingPhysics();
}
}
}
return false;
}
/* ------------------------------------------------------------------------------- */