Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "OpenXR" as a dependency plugin #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 65 additions & 74 deletions Source/UltraleapTrackingCore/Private/LeapVisualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,81 @@
* between Ultraleap and you, your company or other organization. *
******************************************************************************/


#include "LeapVisualizer.h"
#include "LeapUtility.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
#include "HeadMountedDisplayFunctionLibrary.h"

// Sets default values
ALeapVisualizer::ALeapVisualizer()
: NSPlayerAreaBounds(nullptr)
, NSPTeleportRing(nullptr)
, Root(nullptr)
, PlayerAreaBoundsComponent(nullptr)
, TeleportRingComponent(nullptr)
, LeapPawn(nullptr)
, PlayerCameraManager(nullptr)
, World(nullptr)
ALeapVisualizer::ALeapVisualizer()
: NSPlayerAreaBounds(nullptr), NSPTeleportRing(nullptr), Root(nullptr), PlayerAreaBoundsComponent(nullptr), TeleportRingComponent(nullptr), LeapPawn(nullptr), PlayerCameraManager(nullptr), World(nullptr)
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

Root = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent = Root;

NSPlayerAreaBounds = Cast<UNiagaraSystem>(StaticLoadObject(UNiagaraSystem::StaticClass(), nullptr,
TEXT("NiagaraSystem'/UltraleapTracking/InteractionEngine/VFX/Leap_NS_PlayAreaBounds.Leap_NS_PlayAreaBounds'")));
if (NSPlayerAreaBounds == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPlayerAreaBounds is nullptr in ALeapVisualizer()"));
}

NSPTeleportRing = Cast<UNiagaraSystem>(StaticLoadObject(UNiagaraSystem::StaticClass(), nullptr,
TEXT("NiagaraSystem'/UltraleapTracking/InteractionEngine/VFX/Leap_NS_TeleportRing.Leap_NS_TeleportRing'")));

if (NSPTeleportRing == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPTeleportRing is nullptr in ALeapVisualizer()"));
}

PlayerAreaBoundsComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("NiagaraAreaBoundsComponent"));
TeleportRingComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("NiagaraTeleportRingComponent"));

if (!PlayerAreaBoundsComponent || !TeleportRingComponent)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPTeleportRing is nullptr in ALeapVisualizer()"));
}

if (RootComponent)
{
PlayerAreaBoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
TeleportRingComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
}

PlayerAreaBoundsComponent->SetAsset(NSPlayerAreaBounds);
TeleportRingComponent->SetAsset(NSPTeleportRing);

// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

Root = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent = Root;

NSPlayerAreaBounds = Cast<UNiagaraSystem>(StaticLoadObject(UNiagaraSystem::StaticClass(), nullptr,
TEXT("NiagaraSystem'/UltraleapTracking/InteractionEngine/VFX/Leap_NS_PlayAreaBounds.Leap_NS_PlayAreaBounds'")));
if (NSPlayerAreaBounds == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPlayerAreaBounds is nullptr in ALeapVisualizer()"));
}

NSPTeleportRing = Cast<UNiagaraSystem>(StaticLoadObject(UNiagaraSystem::StaticClass(), nullptr,
TEXT("NiagaraSystem'/UltraleapTracking/InteractionEngine/VFX/Leap_NS_TeleportRing.Leap_NS_TeleportRing'")));

if (NSPTeleportRing == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPTeleportRing is nullptr in ALeapVisualizer()"));
}

PlayerAreaBoundsComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("NiagaraAreaBoundsComponent"));
TeleportRingComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("NiagaraTeleportRingComponent"));

if (!PlayerAreaBoundsComponent || !TeleportRingComponent)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("NSPTeleportRing is nullptr in ALeapVisualizer()"));
}

if (RootComponent)
{
PlayerAreaBoundsComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
TeleportRingComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
}

PlayerAreaBoundsComponent->SetAsset(NSPlayerAreaBounds);
TeleportRingComponent->SetAsset(NSPTeleportRing);
}

// Called when the game starts or when spawned
void ALeapVisualizer::BeginPlay()
{
Super::BeginPlay();

FVector2D PlayerArea = UHeadMountedDisplayFunctionLibrary::GetPlayAreaBounds();
FVector PlayerVec = FVector(PlayerArea.X, PlayerArea.Y, 0.0f);
PlayerAreaBoundsComponent->SetNiagaraVariableVec3("User.PlayAreaBounds", PlayerVec);

World = GetWorld();
if (World == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("World is nullptr in ALeapVisualizer::BeginPlay"));
return;
}

LeapPawn = UGameplayStatics::GetPlayerPawn(World, 0);
if (LeapPawn == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("LeapPawn is nullptr in ALeapVisualizer::BeginPlay"));
return;
}
PlayerCameraManager = UGameplayStatics::GetPlayerCameraManager(World, 0);
if (PlayerCameraManager == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("PlayerCameraManager is nullptr in ALeapVisualizer::BeginPlay"));
return;
}
}
Super::BeginPlay();

FVector2D PlayerArea = UHeadMountedDisplayFunctionLibrary::GetPlayAreaBounds();
FVector PlayerVec = FVector(PlayerArea.X, PlayerArea.Y, 0.0f);
PlayerAreaBoundsComponent->SetVariableVec3(FName(*FString("User.PlayAreaBounds")), PlayerVec);

World = GetWorld();
if (World == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("World is nullptr in ALeapVisualizer::BeginPlay"));
return;
}

LeapPawn = UGameplayStatics::GetPlayerPawn(World, 0);
if (LeapPawn == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("LeapPawn is nullptr in ALeapVisualizer::BeginPlay"));
return;
}
PlayerCameraManager = UGameplayStatics::GetPlayerCameraManager(World, 0);
if (PlayerCameraManager == nullptr)
{
UE_LOG(UltraleapTrackingLog, Error, TEXT("PlayerCameraManager is nullptr in ALeapVisualizer::BeginPlay"));
return;
}
}
4 changes: 4 additions & 0 deletions UltraleapTracking.uplugin
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
{
"Name": "Niagara",
"Enabled": true
},
{
"Name": "OpenXR",
"Enabled": true
}
]
}