// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved. #include "ActorTransformer.h" #include "ActorViewportTransformable.h" #include "ViewportWorldInteraction.h" #include "Engine/Selection.h" #include "ViewportInteractionAssetContainer.h" #include "ViewportInteractor.h" #include "Editor.h" void UActorTransformer::Init( UViewportWorldInteraction* InitViewportWorldInteraction ) { Super::Init( InitViewportWorldInteraction ); // Find out about selection changes USelection::SelectionChangedEvent.AddUObject( this, &UActorTransformer::OnActorSelectionChanged ); } void UActorTransformer::Shutdown() { USelection::SelectionChangedEvent.RemoveAll( this ); Super::Shutdown(); } void UActorTransformer::OnStartDragging(class UViewportInteractor* Interactor) { const UViewportInteractionAssetContainer& AssetContainer = ViewportWorldInteraction->GetAssetContainer(); const FVector& SoundLocation = Interactor->GetInteractorData().GizmoLastTransform.GetLocation(); const EViewportInteractionDraggingMode DraggingMode = Interactor->GetDraggingMode(); if (DraggingMode == EViewportInteractionDraggingMode::TransformablesWithGizmo) { ViewportWorldInteraction->PlaySound(AssetContainer.GizmoHandleSelectedSound, SoundLocation); } else if (DraggingMode == EViewportInteractionDraggingMode::TransformablesFreely || DraggingMode == EViewportInteractionDraggingMode::TransformablesAtLaserImpact) { ViewportWorldInteraction->PlaySound(AssetContainer.SelectionStartDragSound, SoundLocation); } } void UActorTransformer::OnStopDragging(class UViewportInteractor* Interactor) { const UViewportInteractionAssetContainer& AssetContainer = ViewportWorldInteraction->GetAssetContainer(); const FVector& SoundLocation = Interactor->GetInteractorData().GizmoLastTransform.GetLocation(); const EViewportInteractionDraggingMode DraggingMode = Interactor->GetDraggingMode(); if (DraggingMode == EViewportInteractionDraggingMode::TransformablesWithGizmo) { ViewportWorldInteraction->PlaySound(AssetContainer.GizmoHandleDropSound, SoundLocation); } else if (DraggingMode == EViewportInteractionDraggingMode::TransformablesFreely || DraggingMode == EViewportInteractionDraggingMode::TransformablesAtLaserImpact) { ViewportWorldInteraction->PlaySound(AssetContainer.SelectionDropSound, SoundLocation); } } void UActorTransformer::OnActorSelectionChanged( UObject* ChangedObject ) { TArray> NewTransformables; USelection* ActorSelectionSet = GEditor->GetSelectedActors(); static TArray SelectedActorObjects; SelectedActorObjects.Reset(); ActorSelectionSet->GetSelectedObjects( AActor::StaticClass(), /* Out */ SelectedActorObjects ); for( UObject* SelectedActorObject : SelectedActorObjects ) { AActor* SelectedActor = Cast( SelectedActorObject ); if( SelectedActor != nullptr ) { // We only are able to move objects that have a root scene component if( SelectedActor->GetRootComponent() != nullptr ) { FActorViewportTransformable* Transformable = new FActorViewportTransformable(); NewTransformables.Add( TUniquePtr( Transformable ) ); Transformable->ActorWeakPtr = SelectedActor; Transformable->StartTransform = SelectedActor->GetTransform(); } } } const bool bNewObjectsSelected = true; ViewportWorldInteraction->SetTransformables( MoveTemp( NewTransformables ), bNewObjectsSelected ); }