CogEngine: Selection prioritize another actor than the selected actor unless only touching the selected actor.

This commit is contained in:
Arnaud Jamin
2023-10-20 16:25:01 -04:00
parent ac90ba6ab6
commit a200c40bed
2 changed files with 13 additions and 10 deletions
@@ -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<AActor*> 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<UPrimitiveComponent>(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();
}
@@ -58,8 +58,6 @@ protected:
virtual void SetGlobalSelection(AActor* Value) const;
virtual AActor* GetGlobalSelection(AActor* Value) const;
private:
TSubclassOf<AActor> GetSelectedActorClass() const;