Skip to content
Snippets Groups Projects

Feature/targetable leave and enter event

Closed Jan Delember requested to merge feature/TargetableLeaveAndEnterEvent into develop
3 files
+ 101
62
Compare changes
  • Side-by-side
  • Inline

Files

@@ -104,15 +104,45 @@ void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tic
@@ -104,15 +104,45 @@ void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tic
const FTwoVectors StartEnd = GetHandRay(MaxClickDistance);
const FTwoVectors StartEnd = GetHandRay(MaxClickDistance);
TOptional<FHitResult> Hit = RaytraceForFirstHit(StartEnd);
TOptional<FHitResult> Hit = RaytraceForFirstHit(StartEnd);
 
if (!Hit.IsSet())
if (!Hit.IsSet())
 
{
 
 
// Execute leave event on the actor that lost the focus if there was one
 
if (LastActorHit && LastActorHit->Implements<UTargetable>())
 
{
 
ITargetable::Execute_OnTargetedLeave(LastActorHit);
 
}
 
 
LastActorHit = nullptr;
return;
return;
 
}
 
AActor* HitActor = Hit->GetActor();
AActor* HitActor = Hit->GetActor();
 
 
// Execute Leave and enter events when the focused actor changed
 
if (HitActor != LastActorHit)
 
{
 
//We can always execute the enter event as we are sure that a hit occured
 
if (HitActor->Implements<UTargetable>())
 
{
 
ITargetable::Execute_OnTargetedEnter(HitActor);
 
}
 
 
//Only execute the Leave Event if there was an actor that was focused previously
 
if (LastActorHit != nullptr && LastActorHit->Implements<UTargetable>())
 
{
 
ITargetable::Execute_OnTargetedLeave(LastActorHit);
 
}
 
}
 
// for now uses the same distance as clicking
// for now uses the same distance as clicking
if (HitActor->Implements<UTargetable>() && Hit->Distance < MaxClickDistance)
if (HitActor->Implements<UTargetable>() && Hit->Distance < MaxClickDistance)
{
{
ITargetable::Execute_OnTargeted(HitActor, Hit->Location);
ITargetable::Execute_OnTargeted(HitActor, Hit->Location);
}
}
 
LastActorHit = HitActor; // Store the actor that was hit to have access to it in the next frame as well
}
}
void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance, float InMaxClickDistance)
void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance, float InMaxClickDistance)
Loading