-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrapBaseComponent.cpp
More file actions
60 lines (50 loc) · 1.75 KB
/
Copy pathTrapBaseComponent.cpp
File metadata and controls
60 lines (50 loc) · 1.75 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
#include "TrapBaseComponent.h"
#include "TrapBase.h"
#include "Components/BoxComponent.h"
UTrapBaseComponent::UTrapBaseComponent()
{
PrimaryComponentTick.bCanEverTick = true;
OwnerActor = nullptr;
DynamicMaterial = nullptr;
InteractCollision = nullptr;
}
void UTrapBaseComponent::BeginPlay()
{
Super::BeginPlay();
// Prepare Owner
AActor* Actor = GetOwner();
if (Actor)
{
OwnerActor = Cast<ATrapBase>(Actor);
if (!OwnerActor)
{
UE_LOG(LogTemp,Error,TEXT(" %s cannot get OwnerActor"), *this->GetOwner()->GetName());
}
}
// Prepare material
UStaticMeshComponent* Platform = Cast<UStaticMeshComponent>(GetOwner()->GetRootComponent());
if (Platform)
{
DynamicMaterial = UMaterialInstanceDynamic::Create(Platform->GetMaterial(0), this);
}
// Prepare Collision
InteractCollision = Cast<UBoxComponent>(GetOwner()->GetDefaultSubobjectByName("Interact Collision"));
if (InteractCollision){
InteractCollision->OnComponentBeginOverlap.AddDynamic(this, &UTrapBaseComponent::OnOverlapBegin);
InteractCollision->OnComponentEndOverlap.AddDynamic(this, &UTrapBaseComponent::OnOverlapEnd);
} else
{
UE_LOG(LogTemp,Error,TEXT("InteractCollision lost at %s --TrapBaseComponent"), *this->GetOwner()->GetName());
}
}
void UTrapBaseComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}
void UTrapBaseComponent::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
}
void UTrapBaseComponent::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
}