예제 #1
0
bool FPhysicsManipulationEdMode::StartTracking( FEditorViewportClient* InViewportClient, FViewport* InViewport )
{
	//UE_LOG(LogEditorPhysMode, Warning, TEXT("Start Tracking"));

	FVector GrabLocation(0,0,0);
	UPrimitiveComponent* ComponentToGrab = NULL;
	
	USelection* Selection = GEditor->GetSelectedActors();

	for (int32 i=0; i<Selection->Num(); ++i)
	{
		AActor* SelectedActor = Cast<AActor>(Selection->GetSelectedObject(i));

		if (SelectedActor != NULL)
		{
			UPrimitiveComponent* PC = Cast<UPrimitiveComponent>(SelectedActor->GetRootComponent());

			if (PC != NULL && PC->BodyInstance.bSimulatePhysics)
			{
				ComponentToGrab = PC;
				
				HandleTargetLocation = SelectedActor->GetActorLocation();
				HandleTargetRotation = SelectedActor->GetActorRotation();
				break;
			}

			if (ComponentToGrab != NULL) { break; }
		}
	}

	if (ComponentToGrab != NULL)
	{
		HandleComp->GrabComponent(ComponentToGrab, NAME_None, ComponentToGrab->GetOwner()->GetActorLocation(), true);
	}

	return FEdMode::StartTracking(InViewportClient, InViewport);
}
void FCreateBlueprintFromActorDialog::OnCreateBlueprint(const FString& InAssetPath, bool bInHarvest)
{
	UBlueprint* Blueprint = NULL;

	if(bInHarvest)
	{
		TArray<AActor*> Actors;

		USelection* SelectedActors = GEditor->GetSelectedActors();
		for(FSelectionIterator Iter(*SelectedActors); Iter; ++Iter)
		{
			// We only care about actors that are referenced in the world for literals, and also in the same level as this blueprint
			AActor* Actor = Cast<AActor>(*Iter);
			if(Actor)
			{
				Actors.Add(Actor);
			}
		}
		Blueprint = FKismetEditorUtilities::HarvestBlueprintFromActors(InAssetPath, Actors, true);
	}
	else
	{
		AActor* ActorToUse = ActorOverride.Get();

		if( !ActorToUse )
		{
			TArray< UObject* > SelectedActors;
			GEditor->GetSelectedActors()->GetSelectedObjects(AActor::StaticClass(), SelectedActors);
			check(SelectedActors.Num());
			ActorToUse =  Cast<AActor>(SelectedActors[0]);
		}

		const bool bReplaceActor = true;
		Blueprint = FKismetEditorUtilities::CreateBlueprintFromActor(InAssetPath, ActorToUse, bReplaceActor);
	}

	if(Blueprint)
	{
		// Rename new instance based on the original actor label rather than the asset name
		USelection* SelectedActors = GEditor->GetSelectedActors();
		if( SelectedActors && SelectedActors->Num() == 1 )
		{
			AActor* Actor = Cast<AActor>(SelectedActors->GetSelectedObject(0));
			if(Actor)
			{
				FActorLabelUtilities::SetActorLabelUnique(Actor, FPackageName::GetShortName(InAssetPath));
			}
		}

		// Select the newly created blueprint in the content browser, but don't activate the browser
		TArray<UObject*> Objects;
		Objects.Add(Blueprint);
		GEditor->SyncBrowserToObjects( Objects, false );
	}
	else
	{
		FNotificationInfo Info( LOCTEXT("CreateBlueprintFromActorFailed", "Unable to create a blueprint from actor.") );
		Info.ExpireDuration = 3.0f;
		Info.bUseLargeFont = false;
		TSharedPtr<SNotificationItem> Notification = FSlateNotificationManager::Get().AddNotification(Info);
		if ( Notification.IsValid() )
		{
			Notification->SetCompletionState( SNotificationItem::CS_Fail );
		}
	}
}
	// FNodeSpawnInfo interface
	virtual void GetActions(UEdGraph* InDestGraph, FVector2D& InOutDestPosition, TArray<UEdGraphNode*>& OutNodes) override
	{
		const UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForGraph(InDestGraph);
		USelection* SelectedLvlActors = GEditor->GetSelectedActors();

		if ((Blueprint != nullptr) && Blueprint->ParentClass->IsChildOf<ALevelScriptActor>() && (SelectedLvlActors->Num() > 0))
		{
			for (FSelectionIterator LvlActorIt(*SelectedLvlActors); LvlActorIt; ++LvlActorIt)
			{
				IBlueprintNodeBinder::FBindingSet Bindings;
				UK2Node_Literal* TemplateRefNode = Cast<UK2Node_Literal>(UBlueprintNodeSpawner::Create(UK2Node_Literal::StaticClass())->Invoke(InDestGraph, Bindings, InOutDestPosition));
				TemplateRefNode->SetObjectRef(*LvlActorIt);

				OutNodes.Add(TemplateRefNode);
			}
		}
	}
FReply SCreateBlueprintFromActorDialog::OnCreateBlueprintFromActorClicked( bool bInHarvest)
{
	ParentWindow->RequestDestroyWindow();

	UBlueprint* Blueprint = NULL;

	if(bInHarvest)
	{
		TArray<AActor*> Actors;

		USelection* SelectedActors = GEditor->GetSelectedActors();
		for(FSelectionIterator Iter(*SelectedActors); Iter; ++Iter)
		{
			// We only care about actors that are referenced in the world for literals, and also in the same level as this blueprint
			AActor* Actor = Cast<AActor>(*Iter);
			if(Actor)
			{
				Actors.Add(Actor);
			}
		}
		Blueprint = FKismetEditorUtilities::HarvestBlueprintFromActors(PathForActorBlueprint + TEXT("/") + FileNameWidget.Pin()->GetText().ToString(), Actors, true);
	}
	else
	{
		TArray< UObject* > SelectedActors;
		GEditor->GetSelectedActors()->GetSelectedObjects(AActor::StaticClass(), SelectedActors);
		check(SelectedActors.Num());
		Blueprint = FKismetEditorUtilities::CreateBlueprintFromActor(PathForActorBlueprint + TEXT("/") + FileNameWidget.Pin()->GetText().ToString(), (AActor*)SelectedActors[0], true);
	}

	if(Blueprint)
	{
		// Rename new instance based on the original actor label rather than the asset name
		USelection* SelectedActors = GEditor->GetSelectedActors();
		if( SelectedActors && SelectedActors->Num() == 1 )
		{
			AActor* Actor = Cast<AActor>(SelectedActors->GetSelectedObject(0));
			if(Actor)
			{
				GEditor->SetActorLabelUnique(Actor, ActorInstanceLabel);
			}
		}

		TArray<UObject*> Objects;
		Objects.Add(Blueprint);
		GEditor->SyncBrowserToObjects( Objects );
	}
	else
	{
		FNotificationInfo Info( LOCTEXT("CreateBlueprintFromActorFailed", "Unable to create a blueprint from actor.") );
		Info.ExpireDuration = 3.0f;
		Info.bUseLargeFont = false;
		TSharedPtr<SNotificationItem> Notification = FSlateNotificationManager::Get().AddNotification(Info);
		if ( Notification.IsValid() )
		{
			Notification->SetCompletionState( SNotificationItem::CS_Fail );
		}
	}

	return FReply::Handled();
}