Skip to content
Snippets Groups Projects
Commit 28d2169c authored by Simon Oehrl's avatar Simon Oehrl
Browse files

Merge branch 'feature/TargetableLeaveAndEnterEvent' into 'develop'

Add enter and leave events for targetable interface

See merge request VR-Group/unreal-development/plugins/ndisplayextensions!44
parents 317f30fa 9b1b7c02
Branches
No related tags found
1 merge request!44Add enter and leave events for targetable interface
......@@ -104,15 +104,44 @@ void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tic
const FTwoVectors StartEnd = GetHandRay(MaxClickDistance);
TOptional<FHitResult> Hit = RaytraceForFirstHit(StartEnd);
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;
}
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
if (HitActor->Implements<UTargetable>() && Hit->Distance < MaxClickDistance)
{
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)
......
......@@ -22,4 +22,12 @@ public:
// function that will be called when targetable actor is targeted, the world pos of the target is returned
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay)
void OnTargeted(FVector WorldPositionOfTarget);
//function that will be called when a targetable actor gets focused
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay)
void OnTargetedEnter();
//function that will be called when a targetable actor loses focused
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Gameplay)
void OnTargetedLeave();
};
......@@ -40,7 +40,8 @@ private:
UPROPERTY() UPrimitiveComponent* ComponentSimulatingPhysics = nullptr;
UPROPERTY() UGrabbingBehaviorComponent* Behavior = nullptr;
UPROPERTY() USceneComponent* InteractionRayEmitter = nullptr;
/* Stores the reference of the Actor that was hit in the last frame*/
UPROPERTY() AActor* LastActorHit = nullptr;
void HandlePhysicsAndAttachActor(AActor* HitActor);
FTwoVectors GetHandRay(float Length) const;
TOptional<FHitResult> RaytraceForFirstHit(const FTwoVectors& Ray) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment