4#include "NavigationSystem.h"
6#include "VRExpansionFunctionLibrary.h"
7#include "Components/SceneComponent.h"
8#include "GameFramework/Character.h"
9#include "Kismet/GameplayStatics.h"
10#include "Materials/MaterialInstanceDynamic.h"
21 return TEXT(
"ROLE_None");
22 case ROLE_SimulatedProxy:
23 return TEXT(
"ROLE_SimulatedProxy");
24 case ROLE_AutonomousProxy:
25 return TEXT(
"ROLE_AutonomousProxy");
27 return TEXT(
"ROLE_Authority");
30 return TEXT(
"ROLE_MAX");
38 case NM_DedicatedServer:
39 return TEXT(
"NM_DedicatedServer");
41 return TEXT(
"NM_ListenServer");
43 return TEXT(
"NM_Standalone");
45 return TEXT(
"NM_Client");
48 return TEXT(
"NM_MAX");
57 , LaserBeamEndPoint(nullptr)
58 , WidgetInteraction(nullptr)
59 , bIsLaserBeamActive(false)
60 , LaserBeamMaxDistance(10000.0f)
61 , LaserBeamRadius(1.0f)
62 , LaserBeamEndpointRadius(0.02f)
63 , LaserBeamColor(FLinearColor::
Red)
64 , LaserBeamEndpointColor(FLinearColor::
Red)
65 , bActivateHovering(true)
66 , bLinkToInteraction(true)
67 , LaserBeamMaterial(nullptr)
68 , LaserBeamMaterialDynamic(nullptr)
69 , LaserBeamEndpointMaterialDynamic(nullptr)
72 PrimaryActorTick.bCanEverTick =
true;
73 PrimaryActorTick.bStartWithTickEnabled =
false;
76 SetReplicateMovement(
true);
78 static ConstructorHelpers::FObjectFinder<UStaticMesh> LaserBeamMeshFinder(TEXT(
"StaticMesh'/PixoCore/Meshes/Controller/BeamMesh.BeamMesh'"));
79 UStaticMesh* LaserBeamMesh = LaserBeamMeshFinder.Object;
81 static ConstructorHelpers::FObjectFinder<UStaticMesh> LaserBeamEndPointMeshFinder(TEXT(
"StaticMesh'/Engine/BasicShapes/Sphere.Sphere'"));
82 UStaticMesh* LaserBeamEndPointMesh = LaserBeamEndPointMeshFinder.Object;
84 static ConstructorHelpers::FObjectFinder<UMaterial> LaserBeamMaterialFinder(TEXT(
"Material'/PixoCore/Materials/Controller/LaserBeamSplineMat.LaserBeamSplineMat'"));
87 SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT(
"LaserSceneComponent"));
90 LaserBeam = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(
"LaserBeam"));
95 LaserBeam->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
96 LaserBeam->SetGenerateOverlapEvents(
false);
99 LaserBeamEndPoint = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(
"LaserBeamEndPoint"));
104 LaserBeamEndPoint->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
108 LaserPointerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(
"LaserPointerMesh"));
111 LaserPointerMesh->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
115 WidgetInteraction = CreateDefaultSubobject<UWidgetInteractionComponent>(TEXT(
"LaserWidgetInteraction"));
133 Super::OnConstruction(Transform);
148 Super::Tick(DeltaTime);
153void APixoVRLaser::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps)
const
155 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
177 FHitResult HitResult;
178 HitResult.bBlockingHit =
false;
179 HitResult.Time = 0.0f;
180 HitResult.Distance = 0.0f;
181 HitResult.Location = FVector::ZeroVector;
182 HitResult.ImpactPoint = FVector::ZeroVector;
183 HitResult.Normal = FVector(0.0f, 0.0f, 1.0f);
184 HitResult.ImpactNormal = FVector(0.0f, 0.0f, 1.0f);
185 HitResult.BoneName = NAME_None;
186 HitResult.Actor =
nullptr;
187 HitResult.Component =
nullptr;
189 HitResult.FaceIndex = 0;
190 HitResult.TraceStart = FVector::ZeroVector;
191 HitResult.TraceEnd = FVector::ZeroVector;
218 if(
HoverHitResult.Actor->GetClass()->ImplementsInterface(UPixoVRInteractionInterface::StaticClass()))
220 if(!IPixoVRInteractionInterface::Execute_DisableHoverEvents(
HoverHitResult.Actor.Get()))
237void APixoVRLaser::ActivateLaserBeam_Implementation(
bool InActivate)
266void APixoVRLaser::ClientTickLaserBeam_Implementation(
float DeltaTime)
275 const FVector Start = GetActorLocation();
279 const ETraceTypeQuery ChannelType = UEngineTypes::ConvertToTraceType(ECC_Visibility);
280 const auto TraceComplex =
false;
283 TArray<AActor*> ActorsToIgnore;
284 ActorsToIgnore.Add(GetOwner());
287 const auto IgnoreSelf =
true;
288 const float DrawTime = 5.0;
290 FVector WorldScale3D;
291 FHitResult HitResult;
292 const auto Result = UKismetSystemLibrary::LineTraceSingle(
this,
298 EDrawDebugTrace::None,
313 LaserBeamEndPoint->SetRelativeLocation(FVector(LaserEndpointDistance, 0.0f, 0.0f),
false,
nullptr, ETeleportType::TeleportPhysics);
319 if(
HoverHitResult.Actor->GetClass()->ImplementsInterface(UPixoVRInteractionInterface::StaticClass()))
321 if(!IPixoVRInteractionInterface::Execute_DisableHoverEvents(
HoverHitResult.Actor.Get()))
331 if (HitResult.Actor.IsValid())
333 if (HitResult.Actor->GetClass()->ImplementsInterface(UPixoVRInteractionInterface::StaticClass()))
335 if (!IPixoVRInteractionInterface::Execute_DisableHoverEvents(HitResult.Actor.Get()))
353 if(
HoverHitResult.Actor->GetClass()->ImplementsInterface(UPixoVRInteractionInterface::StaticClass()))
355 if(!IPixoVRInteractionInterface::Execute_DisableHoverEvents(
HoverHitResult.Actor.Get()))
369 LaserBeam->SetWorldScale3D(WorldScale3D);
375 APlayerController* Executor = GetWorld()->GetFirstPlayerController();
376 if(Executor && Executor->GetCharacter() == Cast<ACharacter>(GetOwner()))
382void APixoVRLaser::ServerTriggerHover_Implementation(
bool State,
AActor* InteractableObject,
383 const FHitResult& HitResult, APlayerController* Executor)
388bool APixoVRLaser::ServerTriggerHover_Validate(
bool State,
AActor* InteractableObject,
const FHitResult& HitResult,
389 APlayerController* Executor)
394void APixoVRLaser::MulticastTriggerHover_Implementation(
bool State,
AActor* InteractableObject,
395 const FHitResult& HitResult, APlayerController* Executor)
397 if(!Executor || !InteractableObject)
404 IPixoVRInteractionInterface::Execute_OnHoverBegin(InteractableObject, HitResult, Executor);
408 IPixoVRInteractionInterface::Execute_OnHoverEnd(InteractableObject, HitResult, Executor);
412bool APixoVRLaser::MulticastTriggerHover_Validate(
bool State,
AActor* InteractableObject,
const FHitResult& HitResult,
413 APlayerController* Executor)
419void APixoVRLaser::OnHoverBegin_Implementation(
const FHitResult& HitResult)
424void APixoVRLaser::OnHoverEnd_Implementation(
const FHitResult& HitResult)
429void APixoVRLaser::OnSelected_Implementation(
const FHitResult& HitResult)
434void APixoVRLaser::OnUnSelected_Implementation(
const FHitResult& HitResult)
447 if(
HoverHitResult.Actor->GetClass()->ImplementsInterface(UPixoVRInteractionInterface::StaticClass()))
449 if(!IPixoVRInteractionInterface::Execute_DisablePressEvents(
HoverHitResult.Actor.Get()))
452 APlayerController* Executor = GetWorld()->GetFirstPlayerController();
469void APixoVRLaser::ServerTriggerSelect_Implementation(
bool State,
AActor* InteractableObject,
const FHitResult& HitResult, APlayerController* Executor)
473 IPixoVRInteractionInterface::Execute_OnPressBegin(InteractableObject, HitResult, Executor);
477 IPixoVRInteractionInterface::Execute_OnPressEnd(InteractableObject, HitResult, Executor);
481bool APixoVRLaser::ServerTriggerSelect_Validate(
bool State,
AActor* InteractableObject,
const FHitResult& HitResult, APlayerController* Executor)
492void APixoVRLaser::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
494 if(PropertyChangedEvent.Property !=
nullptr)
496 const FName PropertyName (PropertyChangedEvent.Property->GetFName());
506 Super::PostEditChangeProperty(PropertyChangedEvent);
DEFINE_LOG_CATEGORY(LogPixoVRLaser)
FString GetRoleName(ENetRole Role)
FString GetNetModeName(ENetMode Mode)
Class for VR laser interaction. It can interact with widget buttons or actors derived from IPixoVRInt...
UMaterial * LaserBeamMaterial
bool IsOverWidgetUse(bool InPressed)
Check if the laser is over a widget and simulate button press.
void TriggerSelect(bool State)
Call this method when the user wants to select the hovered object.
UStaticMeshComponent * LaserBeamEndPoint
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)
bool IsActivated() const
Check if the laser is activated.
void SetHandType(EControllerHand HandType, bool InIsLocal)
Set the hand type describing which hand is holding it.
UStaticMeshComponent * LaserBeam
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)
FLinearColor LaserBeamColor
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
UStaticMeshComponent * LaserPointerMesh
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)
void UpdateStateLaserBeam()
FHitResult HoverHitResult
void ServerTriggerSelect(bool State, AActor *InteractableObject, const FHitResult &HitResult, APlayerController *Executor)
UFUNCTION(Server, Reliable, WithValidation)
virtual void Tick(float DeltaTime) override
void OnUnSelected(const FHitResult &HitResult)
Called when the user unselects the hovered object.
TWeakObjectPtr< class AActor > HitActor
void OnRep_LaserBeamActive()
UFUNCTION()
UWidgetInteractionComponent * WidgetInteraction
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)
virtual void OnConstruction(const FTransform &Transform) override
FLaserBeamActivated OnLaserBeamActivated
UPROPERTY(BlueprintAssignable, Category = "PixoVR | Laser")
UMaterialInstanceDynamic * LaserBeamEndpointMaterialDynamic
float LaserBeamEndpointRadius
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
void OnSelected(const FHitResult &HitResult)
Called when the user selects the hovered object.
UMaterialInstanceDynamic * LaserBeamMaterialDynamic
void MulticastTriggerHover(bool State, AActor *InteractableObject, const FHitResult &HitResult, APlayerController *Executor)
UFUNCTION(NetMulticast, Reliable, WithValidation)
float LaserBeamRadius
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
float LaserBeamMaxDistance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
void ServerTriggerHover(bool State, AActor *InteractableObject, const FHitResult &HitResult, APlayerController *Executor)
UFUNCTION(Server, Reliable, WithValidation)
bool bActivateHovering
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
void TriggerHover(bool State, AActor *InteractableObject, const FHitResult &HitResult)
Call this method when the user wants to hover over an object.
bool bIsLaserBeamActive
UPROPERTY(BlueprintReadOnly, Transient, ReplicatedUsing=OnRep_LaserBeamActive, Category = "PixoVR | L...
void OnHoverBegin(const FHitResult &HitResult)
Called when an object enters the hover state.
bool bLinkToInteraction
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
void OnHoverEnd(const FHitResult &HitResult)
Called when an object exits the hover state.
USceneComponent * SceneComponent
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite)
FLinearColor LaserBeamEndpointColor
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PixoVR | Laser")
void ClientTickLaserBeam(float DeltaTime)
UFUNCTION(Client, Unreliable)