From a200c40bed751fb381cdea291ade28039822d1c1 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Fri, 20 Oct 2023 16:25:01 -0400 Subject: [PATCH] CogEngine: Selection prioritize another actor than the selected actor unless only touching the selected actor. --- .../Private/CogEngineWindow_Selection.cpp | 21 ++++++++++++------- .../Public/CogEngineWindow_Selection.h | 2 -- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp index 0f2dc6f..912ad27 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp @@ -407,17 +407,27 @@ void UCogEngineWindow_Selection::TickSelectionMode() FVector WorldOrigin, WorldDirection; if (UGameplayStatics::DeprojectScreenToWorld(PlayerController, FCogImguiHelper::ToVector2D(ImGui::GetMousePos()), WorldOrigin, WorldDirection)) { + //-------------------------------------------------------------------------------------------------------- + // Prioritize another actor than the selected actor unless we only touch the selected actor. + //-------------------------------------------------------------------------------------------------------- TArray IgnoreList; + IgnoreList.Add(FCogDebugSettings::GetSelection()); FHitResult HitResult; - if (UKismetSystemLibrary::LineTraceSingle(GetWorld(), WorldOrigin, WorldOrigin + WorldDirection * 10000, TraceType, false, IgnoreList, EDrawDebugTrace::None, HitResult, true)) + for (int i = 0; i < 2; ++i) { - if (HitResult.GetActor() != nullptr) + if (UKismetSystemLibrary::LineTraceSingle(GetWorld(), WorldOrigin, WorldOrigin + WorldDirection * 10000, TraceType, false, IgnoreList, EDrawDebugTrace::None, HitResult, true)) { if (SelectedActorClass == nullptr || HitResult.GetActor()->GetClass()->IsChildOf(SelectedActorClass)) { HoveredActor = HitResult.GetActor(); + break; } + + //------------------------------------------------ + // The second time we accept the selected actor + //------------------------------------------------ + IgnoreList.Empty(); } } } @@ -467,6 +477,7 @@ void UCogEngineWindow_Selection::DrawActorFrame(const AActor& Actor) if (const UPrimitiveComponent* PrimitiveComponent = Cast(Actor.GetRootComponent())) { PrimitiveFound = true; + Bounds += PrimitiveComponent->Bounds.GetBox(); } else @@ -643,9 +654,3 @@ void UCogEngineWindow_Selection::SetGlobalSelection(AActor* Value) const { FCogDebugSettings::SetSelection(GetWorld(), Value); } - -//-------------------------------------------------------------------------------------------------------------------------- -AActor* UCogEngineWindow_Selection::GetGlobalSelection(AActor* Value) const -{ - return FCogDebugSettings::GetSelection(); -} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h index d5de7c5..7725b05 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Selection.h @@ -58,8 +58,6 @@ protected: virtual void SetGlobalSelection(AActor* Value) const; - virtual AActor* GetGlobalSelection(AActor* Value) const; - private: TSubclassOf GetSelectedActorClass() const;