コード例 #1
0
void FWidgetBlueprintEditor::UpdatePreview(UBlueprint* InBlueprint, bool bInForceFullUpdate)
{
	UUserWidget* PreviewActor = GetPreview();

	// Signal that we're going to be constructing editor components
	if ( InBlueprint != nullptr && InBlueprint->SimpleConstructionScript != nullptr )
	{
		InBlueprint->SimpleConstructionScript->BeginEditorComponentConstruction();
	}

	// If the Blueprint is changing
	if ( InBlueprint != PreviewBlueprint || bInForceFullUpdate )
	{
		// Destroy the previous actor instance
		DestroyPreview();

		// Save the Blueprint we're creating a preview for
		PreviewBlueprint = Cast<UWidgetBlueprint>(InBlueprint);

		// Update the generated class'es widget tree to match the blueprint tree.  That way the preview can update
		// without needing to do a full recompile.
		Cast<UWidgetBlueprintGeneratedClass>(PreviewBlueprint->GeneratedClass)->DesignerWidgetTree = DuplicateObject<UWidgetTree>(PreviewBlueprint->WidgetTree, PreviewBlueprint->GeneratedClass);

		PreviewActor = CreateWidget<UUserWidget>(PreviewScene.GetWorld(), PreviewBlueprint->GeneratedClass);
		PreviewActor->SetFlags(RF_Transactional);
		
		// Configure all the widgets to be set to design time.
		PreviewActor->SetDesignerFlags(GetCurrentDesignerFlags());

		// Store a reference to the preview actor.
		PreviewWidgetPtr = PreviewActor;
	}

	OnWidgetPreviewUpdated.Broadcast();
}
コード例 #2
0
UUserWidget* UWidgetBlueprintLibrary::Create(UObject* WorldContextObject, TSubclassOf<UUserWidget> WidgetType, APlayerController* OwningPlayer)
{
	if ( WidgetType == nullptr || WidgetType->HasAnyClassFlags(CLASS_Abstract) )
	{
		return nullptr;
	}

	UUserWidget* UserWidget = nullptr;
	if ( OwningPlayer == nullptr )
	{
		UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject);
		UserWidget = CreateWidget<UUserWidget>(World, WidgetType);
	}
	else
	{
		UserWidget = CreateWidget<UUserWidget>(OwningPlayer, WidgetType);
	}

	if (UserWidget)
	{
		UserWidget->SetFlags(RF_StrongRefOnFrame);
	}
	return UserWidget;
}