Пример #1
0
void FBehaviorTreeDebugger::OnInstanceSelectedInDropdown(UBehaviorTreeComponent* SelectedInstance)
{
	if (SelectedInstance)
	{
		ClearDebuggerState();

		AController* OldController = TreeInstance.IsValid() ? Cast<AController>(TreeInstance->GetOwner()) : NULL;
		APawn* OldPawn = OldController != NULL ? OldController->GetPawn() : NULL;
		USelection* SelectedActors = GEditor->GetSelectedActors();
		if (SelectedActors && OldPawn)
		{
			SelectedActors->Deselect(OldPawn);
		}

		TreeInstance = SelectedInstance;

		if (SelectedActors && GEditor && SelectedInstance && SelectedInstance->GetOwner())
		{
			AController* TestController = Cast<AController>(SelectedInstance->GetOwner());
			APawn* Pawn = TestController != NULL ? TestController->GetPawn() : NULL;
			if (Pawn)
			{
				SelectedActors = GEditor->GetSelectedActors();
				SelectedActors->Select(Pawn);
				AGameplayDebuggingReplicator::OnSelectionChangedDelegate.Broadcast(Pawn);
			}
		}

		Refresh();
	}
}
Пример #2
0
/**
* Attempt to lock/unlock the level of this window
*
* @param	bLocked	If true, attempt to lock the level; If false, attempt to unlock the level
*/
void FLevelViewModel::SetLocked(bool bLocked)
{
	if( !Level.IsValid() )
	{
		return;
	}

	// Do nothing if attempting to set the level to the same locked state or if trying to lock/unlock the p-level
	if ( bLocked == IsLocked() || IsPersistent() )
	{
		return;
	}

	// If locking the level, deselect all of its actors and BSP surfaces
	if ( bLocked )
	{
		USelection* SelectedActors = GEditor->GetSelectedActors();
		SelectedActors->Modify();

		// Deselect all level actors 
		for ( TArray<AActor*>::TConstIterator LevelActorIterator( Level->Actors ); LevelActorIterator; ++LevelActorIterator )
		{
			AActor* CurActor = *LevelActorIterator;
			if ( CurActor )
			{
				SelectedActors->Deselect( CurActor );
			}
		}

		// Deselect all level BSP surfaces
		EditorLevelUtils::DeselectAllSurfacesInLevel(Level.Get());

		// Tell the editor selection status was changed.
		GEditor->NoteSelectionChange();

		// If locking the current level, reset the p-level as the current level
		//@todo: fix this!
	}

	// Change the level's locked status
	FLevelUtils::ToggleLevelLock( Level.Get() );
}
Пример #3
0
void FLevelModel::DeselectAllActors()
{
	ULevel* Level = GetLevelObject();

	if (Level == NULL)
	{
		return;
	}

	USelection* SelectedActors = Editor->GetSelectedActors();
	SelectedActors->Modify();

	// Deselect all level actors 
	for (auto It = Level->Actors.CreateIterator(); It; ++It)
	{
		AActor* CurActor = (*It);
		if (CurActor)
		{
			SelectedActors->Deselect(CurActor);
		}
	}
}
Пример #4
-1
void SetLevelVisibility(ULevel* Level, bool bShouldBeVisible, bool bForceLayersVisible)
{
    // Nothing to do
    if ( Level == NULL )
    {
        return;
    }


    // Handle the case of the p-level
    // The p-level can't be unloaded, so its actors/BSP should just be temporarily hidden/unhidden
    // Also, intentionally do not force layers visible for the p-level
    if ( Level->IsPersistentLevel() )
    {
        //create a transaction so we can undo the visibilty toggle
        const FScopedTransaction Transaction( LOCTEXT( "ToggleLevelVisibility", "Toggle Level Visibility" ) );
        if ( Level->bIsVisible != bShouldBeVisible )
        {
            Level->Modify();
        }
        // Set the visibility of each actor in the p-level
        for ( TArray<AActor*>::TIterator PLevelActorIter( Level->Actors ); PLevelActorIter; ++PLevelActorIter )
        {
            AActor* CurActor = *PLevelActorIter;
            if ( CurActor && !FActorEditorUtils::IsABuilderBrush(CurActor) && CurActor->bHiddenEdLevel == bShouldBeVisible )
            {
                CurActor->Modify();
                CurActor->bHiddenEdLevel = !bShouldBeVisible;
                CurActor->RegisterAllComponents();
                CurActor->MarkComponentsRenderStateDirty();
            }
        }

        // Set the visibility of each BSP surface in the p-level
        UModel* CurLevelModel = Level->Model;
        if ( CurLevelModel )
        {
            CurLevelModel->Modify();
            for ( TArray<FBspSurf>::TIterator SurfaceIterator( CurLevelModel->Surfs ); SurfaceIterator; ++SurfaceIterator )
            {
                FBspSurf& CurSurf = *SurfaceIterator;
                CurSurf.bHiddenEdLevel = !bShouldBeVisible;
            }
        }

        // Add/remove model components from the scene
        for(int32 ComponentIndex = 0; ComponentIndex < Level->ModelComponents.Num(); ComponentIndex++)
        {
            UModelComponent* CurLevelModelCmp = Level->ModelComponents[ComponentIndex];
            if(CurLevelModelCmp)
            {
                if (bShouldBeVisible && CurLevelModelCmp)
                {
                    CurLevelModelCmp->RegisterComponentWithWorld(Level->OwningWorld);
                }
                else if (!bShouldBeVisible && CurLevelModelCmp->IsRegistered())
                {
                    CurLevelModelCmp->UnregisterComponent();
                }
            }
        }

        FEditorSupportDelegates::RedrawAllViewports.Broadcast();
    }
    else
    {
        ULevelStreaming* StreamingLevel = NULL;
        if (Level->OwningWorld == NULL || Level->OwningWorld->PersistentLevel != Level )
        {
            StreamingLevel = FLevelUtils::FindStreamingLevel( Level );
        }

        // If were hiding a level, lets make sure to close the level transform mode if its the same level currently selected for edit
        FEdModeLevel* LevelMode = static_cast<FEdModeLevel*>(GEditorModeTools().GetActiveMode( FBuiltinEditorModes::EM_Level ));
        if( LevelMode && LevelMode->IsEditing( StreamingLevel ) )
        {
            GEditorModeTools().DeactivateMode( FBuiltinEditorModes::EM_Level );
        }

        //create a transaction so we can undo the visibilty toggle
        const FScopedTransaction Transaction( LOCTEXT( "ToggleLevelVisibility", "Toggle Level Visibility" ) );

        // Handle the case of a streaming level
        if ( StreamingLevel )
        {
            // We need to set the RF_Transactional to make a streaming level serialize itself. so store the original ones, set the flag, and put the original flags back when done
            EObjectFlags cachedFlags = StreamingLevel->GetFlags();
            StreamingLevel->SetFlags( RF_Transactional );
            StreamingLevel->Modify();
            StreamingLevel->SetFlags( cachedFlags );

            // Set the visibility state for this streaming level.
            StreamingLevel->bShouldBeVisibleInEditor = bShouldBeVisible;
        }

        if( !bShouldBeVisible )
        {
            GEditor->Layers->RemoveLevelLayerInformation( Level );
        }

        // UpdateLevelStreaming sets Level->bIsVisible directly, so we need to make sure it gets saved to the transaction buffer.
        if ( Level->bIsVisible != bShouldBeVisible )
        {
            Level->Modify();
        }

        if ( StreamingLevel )
        {
            Level->OwningWorld->FlushLevelStreaming();

            // In the Editor we expect this operation will complete in a single call
            check(Level->bIsVisible == bShouldBeVisible);
        }
        else if (Level->OwningWorld != NULL)
        {
            // In case we level has no associated StreamingLevel, remove or add to world directly
            if (bShouldBeVisible)
            {
                if (!Level->bIsVisible)
                {
                    Level->OwningWorld->AddToWorld(Level);
                }
            }
            else
            {
                Level->OwningWorld->RemoveFromWorld(Level);
            }

            // In the Editor we expect this operation will complete in a single call
            check(Level->bIsVisible == bShouldBeVisible);
        }

        if( bShouldBeVisible )
        {
            GEditor->Layers->AddLevelLayerInformation( Level );
        }

        // Force the level's layers to be visible, if desired
        FEditorSupportDelegates::RedrawAllViewports.Broadcast();

        // Iterate over the level's actors, making a list of their layers and unhiding the layers.
        TTransArray<AActor*>& Actors = Level->Actors;
        for ( int32 ActorIndex = 0 ; ActorIndex < Actors.Num() ; ++ActorIndex )
        {
            AActor* Actor = Actors[ ActorIndex ];
            if ( Actor )
            {
                bool bModified = false;
                if ( bShouldBeVisible && bForceLayersVisible && GEditor->Layers->IsActorValidForLayer( Actor ) )
                {
                    // Make the actor layer visible, if it's not already.
                    if ( Actor->bHiddenEdLayer )
                    {
                        bModified = Actor->Modify();
                        Actor->bHiddenEdLayer = false;
                    }

                    const bool bIsVisible = true;
                    GEditor->Layers->SetLayersVisibility( Actor->Layers, bIsVisible );
                }

                // Set the visibility of each actor in the streaming level
                if ( !FActorEditorUtils::IsABuilderBrush(Actor) && Actor->bHiddenEdLevel == bShouldBeVisible )
                {
                    if ( !bModified )
                    {
                        bModified = Actor->Modify();
                    }
                    Actor->bHiddenEdLevel = !bShouldBeVisible;

                    if (bShouldBeVisible)
                    {
                        Actor->ReregisterAllComponents();
                    }
                    else
                    {
                        Actor->UnregisterAllComponents();
                    }
                }
            }
        }
    }

    FEditorDelegates::RefreshLayerBrowser.Broadcast();

    // Notify the Scene Outliner, as new Actors may be present in the world.
    GEngine->BroadcastLevelActorsChanged();

    // If the level is being hidden, deselect actors and surfaces that belong to this level.
    if ( !bShouldBeVisible )
    {
        USelection* SelectedActors = GEditor->GetSelectedActors();
        SelectedActors->Modify();
        TTransArray<AActor*>& Actors = Level->Actors;
        for ( int32 ActorIndex = 0 ; ActorIndex < Actors.Num() ; ++ActorIndex )
        {
            AActor* Actor = Actors[ ActorIndex ];
            if ( Actor )
            {
                SelectedActors->Deselect( Actor );
            }
        }

        DeselectAllSurfacesInLevel(Level);

        // Tell the editor selection status was changed.
        GEditor->NoteSelectionChange();
    }

    Level->bIsVisible = bShouldBeVisible;
}