// Copyright Epic Games, Inc. All Rights Reserved. #include "BaseGizmos/GizmoElementHitTargets.h" #include "BaseGizmos/GizmoElementBase.h" #include "BaseGizmos/GizmoViewContext.h" #include "BaseGizmos/TransformProxy.h" #include "Engine/EngineTypes.h" // FHitResult #include UE_INLINE_GENERATED_CPP_BY_NAME(GizmoElementHitTargets) FInputRayHit UGizmoElementHitTarget::IsHit(const FInputDeviceRay& ClickPos) const { if (GizmoElement && GizmoViewContext && GizmoTransformProxy && (!Condition || Condition(ClickPos))) { UGizmoElementBase::FLineTraceTraversalState LineTraceState; LineTraceState.Initialize(GizmoViewContext, GizmoTransformProxy->GetTransform()); return GizmoElement->LineTrace(GizmoViewContext, LineTraceState, ClickPos.WorldRay.Origin, ClickPos.WorldRay.Direction); } return FInputRayHit(); } void UGizmoElementHitTarget::UpdateHoverState(bool bHovering) { if (!GizmoElement) { return; } if (bHovering) { GizmoElement->SetElementInteractionState(EGizmoElementInteractionState::Hovering); } // If this element is interacting, do not update the hover state. This is necessary because when transitioning // from hovering to interacting, the gizmo framework updates interacting to true before updating hovering to false. else if (GizmoElement->GetElementInteractionState() != EGizmoElementInteractionState::Interacting) { GizmoElement->SetElementInteractionState(EGizmoElementInteractionState::None); } } void UGizmoElementHitTarget::UpdateInteractingState(bool bInteracting) { if (!GizmoElement) { return; } if (bInteracting) { GizmoElement->SetElementInteractionState(EGizmoElementInteractionState::Interacting); } else { GizmoElement->SetElementInteractionState(EGizmoElementInteractionState::None); } } UGizmoElementHitTarget* UGizmoElementHitTarget::Construct(UGizmoElementBase* InGizmoElement, UGizmoViewContext* InGizmoViewContext, UObject* Outer) { UGizmoElementHitTarget* NewHitTarget = NewObject(Outer); NewHitTarget->GizmoElement = InGizmoElement; NewHitTarget->GizmoViewContext = InGizmoViewContext; return NewHitTarget; } FInputRayHit UGizmoElementHitMultiTarget::IsHit(const FInputDeviceRay& ClickPos) const { if (GizmoElement && GizmoViewContext && GizmoTransformProxy && (!Condition || Condition(ClickPos))) { UGizmoElementBase::FLineTraceTraversalState LineTraceState; LineTraceState.Initialize(GizmoViewContext, GizmoTransformProxy->GetTransform()); return GizmoElement->LineTrace(GizmoViewContext, LineTraceState, ClickPos.WorldRay.Origin, ClickPos.WorldRay.Direction); } return FInputRayHit(); } void UGizmoElementHitMultiTarget::UpdateHoverState(bool bInHovering, uint32 PartIdentifier) { if (!GizmoElement) { return; } if (bInHovering) { GizmoElement->UpdatePartInteractionState(EGizmoElementInteractionState::Hovering, PartIdentifier); } else { // If this element is interacting, do not update the hover state. This is necessary because when transitioning // from hovering to interacting, the gizmo framework updates interacting to true before updating hovering to false. TOptional InteractionStateResult = GizmoElement->GetPartInteractionState(PartIdentifier); if (InteractionStateResult.IsSet() && InteractionStateResult.GetValue() == EGizmoElementInteractionState::Interacting) { return; } GizmoElement->UpdatePartInteractionState(EGizmoElementInteractionState::None, PartIdentifier); } } void UGizmoElementHitMultiTarget::UpdateInteractingState(bool bInInteracting, uint32 PartIdentifier) { if (!GizmoElement) { return; } if (bInInteracting) { GizmoElement->UpdatePartInteractionState(EGizmoElementInteractionState::Interacting, PartIdentifier); } else { GizmoElement->UpdatePartInteractionState(EGizmoElementInteractionState::None, PartIdentifier); } } void UGizmoElementHitMultiTarget::UpdateHittableState(bool bHittable, uint32 PartIdentifier) { if (!GizmoElement) { return; } GizmoElement->UpdatePartHittableState(bHittable, PartIdentifier); } UGizmoElementHitMultiTarget* UGizmoElementHitMultiTarget::Construct(UGizmoElementBase* InGizmoElement, UGizmoViewContext* InGizmoViewContext, UObject* Outer) { UGizmoElementHitMultiTarget* NewHitTarget = NewObject(Outer); NewHitTarget->GizmoElement = InGizmoElement; NewHitTarget->GizmoViewContext = InGizmoViewContext; return NewHitTarget; }