Advertisement
Guest User

Untitled

a guest
May 5th, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. void UKismetSystemLibrary::PrintString(UObject* WorldContextObject, const FString& InString, bool bPrintToScreen, bool bPrintToLog, FLinearColor TextColor)
  2. {
  3. #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) // Do not Print in Shipping or Test
  4.  
  5.     WorldContextObject = GEngine->GetWorldFromContextObject(WorldContextObject, false);
  6.     FString Prefix;
  7.     if (WorldContextObject)
  8.     {
  9.         UWorld *World = WorldContextObject->GetWorld();
  10.         if (World->WorldType == EWorldType::PIE)
  11.         {
  12.             switch(World->GetNetMode())
  13.             {
  14.                 case NM_Client:
  15.                     Prefix = FString::Printf(TEXT("Client %d: "), GPlayInEditorID - 1);
  16.                     break;
  17.                 case NM_DedicatedServer:
  18.                 case NM_ListenServer:
  19.                     Prefix = FString::Printf(TEXT("Server: "));
  20.                     break;
  21.             }
  22.         }
  23.     }
  24.    
  25.     const FString FinalString = Prefix + InString;
  26.  
  27.     if (bPrintToLog)
  28.     {
  29.         UE_LOG(LogBlueprintUserMessages, Log, TEXT("%s"), *FinalString);
  30.        
  31.         APlayerController* PC = (WorldContextObject ? UGameplayStatics::GetPlayerController(WorldContextObject, 0) : NULL);
  32.         ULocalPlayer* LocalPlayer = (PC ? Cast<ULocalPlayer>(PC->Player) : NULL);
  33.         if (LocalPlayer && LocalPlayer->ViewportClient && LocalPlayer->ViewportClient->ViewportConsole)
  34.         {
  35.             LocalPlayer->ViewportClient->ViewportConsole->OutputText(FinalString);
  36.         }
  37.     }
  38.     else
  39.     {
  40.         UE_LOG(LogBlueprintUserMessages, Verbose, TEXT("%s"), *FinalString);
  41.     }
  42.  
  43.     // Also output to the screen, if possible
  44.     if (bPrintToScreen)
  45.     {
  46.         if (GAreScreenMessagesEnabled)
  47.         {
  48.             float Duration = 2.0f;
  49.             if ( GConfig )
  50.             {
  51.                 GConfig->GetFloat( TEXT("Kismet"), TEXT("PrintStringDuration"), Duration, GEngineIni );
  52.             }
  53.             GEngine->AddOnScreenDebugMessage((uint64)-1, Duration, TextColor.ToFColor(true), FinalString);
  54.         }
  55.         else
  56.         {
  57.             UE_LOG(LogBlueprint, VeryVerbose, TEXT("Screen messages disabled (!GAreScreenMessagesEnabled).  Cannot print to screen."));
  58.         }
  59.     }
  60. #endif
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement