Skip to content
Snippets Groups Projects
Select Git revision
  • ce9589d0c387a7a3c567f01ee8679d0e971a66ba
  • master default protected
  • develop protected
  • feature/interaction_cmp_setup_improvement
  • 4.22.1
5 results

VRWidgetInteractionComponent.cpp

  • VRWidgetInteractionComponent.cpp 1.49 KiB
    // 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);
    }