// Fill out your copyright notice in the Description page of Project Settings. #include "VRWidgetInteractionComponent.h" #include "Runtime/InputCore/Classes/InputCoreTypes.h" #include "Runtime/Engine/Classes/Components/InputComponent.h" #include "ConstructorHelpers.h" #include "Modules/ModuleManager.h" #include "Interfaces/IPluginManager.h" #include "VirtualRealityPawn.h" UVRWidgetInteractionComponent::UVRWidgetInteractionComponent() { InteractionRay = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Interaction Ray")); auto MeshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("/WidgetInteraction/Ray_Mesh")); if (MeshAsset.Object != nullptr) { InteractionRay->SetStaticMesh(MeshAsset.Object); //InteractionRay->SetRelativeRotation(FRotator(0, 90, 0)); } } void UVRWidgetInteractionComponent::Init() { SetVisibility(true); InteractionDistance = 1000000.0f; auto input_cmp = dynamic_cast<UInputComponent*>(GetOwner()->GetComponentByClass(UInputComponent::StaticClass())); input_cmp->BindAction<FFireDelegate>("Fire", IE_Pressed, this, &UVRWidgetInteractionComponent::OnFire, true); input_cmp->BindAction<FFireDelegate>("Fire", IE_Released, this, &UVRWidgetInteractionComponent::OnFire, false); RegisterComponent(); } void UVRWidgetInteractionComponent::SetVisibility(bool visible) { bShowDebug = visible; } void UVRWidgetInteractionComponent::OnFire(bool val) { if (val == true) PressPointerKey(EKeys::LeftMouseButton); else ReleasePointerKey(EKeys::LeftMouseButton); }