Skip to content
Snippets Groups Projects
Commit d5c30d7b authored by Jonathan Wendt's avatar Jonathan Wendt
Browse files

update attachement method

parent 942e7a53
No related branches found
No related tags found
1 merge request!2Feature/update to new VRPawn structure and adding an interaction ray that is also available in shipping builds
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#define LOCTEXT_NAMESPACE "FWidgetInteractionModule" #define LOCTEXT_NAMESPACE "FWidgetInteractionModule"
DEFINE_LOG_CATEGORY(WidgetIntLog);
void FWidgetInteractionModule::StartupModule() void FWidgetInteractionModule::StartupModule()
{ {
on_world_tick_start_delegate_.BindRaw(this, &FWidgetInteractionModule::OnWorldTickStart); on_world_tick_start_delegate_.BindRaw(this, &FWidgetInteractionModule::OnWorldTickStart);
...@@ -25,77 +27,49 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val ...@@ -25,77 +27,49 @@ void FWidgetInteractionModule::OnWorldTickStart(ELevelTick level_tick, float val
auto worlds = GEngine->GetWorldContexts(); auto worlds = GEngine->GetWorldContexts();
for (auto world_context : worlds) { for (auto world_context : worlds) {
auto world = world_context.World(); auto world = world_context.World();
if (last_world == world && widget_interaction_cmp_ != nullptr) { if (last_world == world && widget_interaction_cmp_ != nullptr) {
if (widget_interaction_cmp_->IsValidLowLevel() == true) { if (widget_interaction_cmp_->IsValidLowLevel() == true) {
continue; continue;
} }
else { else {
widget_interaction_cmp_ = nullptr; widget_interaction_cmp_ = nullptr;
} }
} }
if (world == nullptr) if (world == nullptr)
continue; continue;
auto player_controller = world->GetFirstPlayerController(); auto player_controller = world->GetFirstPlayerController();
if (player_controller == nullptr) if (player_controller == nullptr)
continue; continue;
auto vr_pawn = dynamic_cast<AVirtualRealityPawn*>(player_controller->AcknowledgedPawn); auto vr_pawn = dynamic_cast<AVirtualRealityPawn*>(player_controller->AcknowledgedPawn);
if (vr_pawn == nullptr) if (vr_pawn == nullptr)
continue; continue;
UE_LOG(LogTemp, Warning, TEXT("OnWorldTickStart called and interaction component will be updated"));
FString name = "";
FString name = ""; UClass* component_class = UMotionControllerComponent::StaticClass();
UClass* component_class = UMotionControllerComponent::StaticClass();
auto right_hand = vr_pawn->GetRightHandComponent();
CreateWidgetInteraction(vr_pawn->GetRightHandComponent(), vr_pawn);
if (IDisplayCluster::Get().GetClusterMgr()->IsStandalone()) { last_world = world;
//if this is a standalone setup ...
if (UHeadMountedDisplayFunctionLibrary::IsHeadMountedDisplayEnabled()) { UE_LOG(WidgetIntLog, Verbose, TEXT("VRInteractionComponent attached to right hand"));
//.. with an HMD, we attach the intercation component to the right hand }
name = FString("HMDRightMotionController");
component_class = UMotionControllerComponent::StaticClass();
}
else {
//... without an HMD, we also attach it to the virtual right hand, since it exists in this case
name = TEXT("HMDRightMotionController");
component_class = UMotionControllerComponent::StaticClass();
}
}
else {
//if this is a cluster setup we attach it to the flystick
name = TEXT("flystick");
component_class = UDisplayClusterSceneComponent::StaticClass();
}
auto parent_vec = vr_pawn->GetComponentsByClass(component_class);
bool success;
for (auto parent : parent_vec) {
if (parent->GetName() == FString(name)) {
CreateWidgetInteraction(dynamic_cast<USceneComponent*>(parent), vr_pawn);
success = true;
last_world = world;
}
}
if (!success)
UE_LOG(LogTemp, Error, TEXT("Failed to load widget asset \"%s\", cannot attach widget interaction component"), *name);
}
} }
URwthComponent* FWidgetInteractionModule::GetWidgetInteractionComponent() { UVRWidgetInteractionComponent* FWidgetInteractionModule::GetWidgetInteractionComponent() {
return widget_interaction_cmp_; return widget_interaction_cmp_;
} }
void FWidgetInteractionModule::CreateWidgetInteraction(USceneComponent * parent, AVirtualRealityPawn* outer) void FWidgetInteractionModule::CreateWidgetInteraction(USceneComponent * parent, AVirtualRealityPawn* outer)
{ {
widget_interaction_cmp_ = NewObject<URwthComponent>(outer, URwthComponent::StaticClass()); widget_interaction_cmp_ = NewObject<UVRWidgetInteractionComponent>(outer, UVRWidgetInteractionComponent::StaticClass());
widget_interaction_cmp_->AttachToComponent(parent, FAttachmentTransformRules(EAttachmentRule::KeepRelative, false)); widget_interaction_cmp_->AttachToComponent(parent, FAttachmentTransformRules(EAttachmentRule::KeepRelative, false));
widget_interaction_cmp_->Init(); widget_interaction_cmp_->Init();
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "VRWidgetInteractionComponent.h" #include "VRWidgetInteractionComponent.h"
#include "Modules/ModuleManager.h" #include "Modules/ModuleManager.h"
DECLARE_LOG_CATEGORY_EXTERN(WidgetIntLog, Log, All);
class WIDGETINTERACTION_API FWidgetInteractionModule : public IModuleInterface class WIDGETINTERACTION_API FWidgetInteractionModule : public IModuleInterface
{ {
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment