FileHelperScreenshotAction.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2023 RLoris
  2. #pragma once
  3. #include "Engine/Texture2D.h"
  4. #include "Engine/World.h"
  5. #include "Kismet/BlueprintAsyncActionBase.h"
  6. #include "FileHelperScreenshotAction.generated.h"
  7. USTRUCT(BlueprintType)
  8. struct FFileHelperScreenshotActionOptions
  9. {
  10. GENERATED_BODY()
  11. /** File name without extension or path information */
  12. UPROPERTY(BlueprintReadWrite, Category = "Screenshot")
  13. FString Filename;
  14. /** Prefix filename with a custom timestamp */
  15. UPROPERTY(BlueprintReadWrite, Category = "Screenshot")
  16. bool bPrefixTimestamp = true;
  17. /** Include the UI in the screenshot */
  18. UPROPERTY(BlueprintReadWrite, Category = "Screenshot")
  19. bool bShowUI = false;
  20. /** Uses this option only if the scene has HDR enabled,
  21. * extension of screenshot file will be exr instead of png */
  22. UPROPERTY(BlueprintReadWrite, Category = "Screenshot")
  23. bool bWithHDR = false;
  24. /* Leave this empty for default screenshot,
  25. * a different type of screenshot will be taken with a render target if set,
  26. * options and settings quality may differ from regular screenshot, no UI shown */
  27. UPROPERTY(BlueprintReadWrite, Category = "Screenshot")
  28. TObjectPtr<ACameraActor> CustomCameraActor = nullptr;
  29. };
  30. UCLASS()
  31. class FILEHELPER_API UFileHelperScreenshotAction : public UBlueprintAsyncActionBase
  32. {
  33. GENERATED_BODY()
  34. public:
  35. DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOutputPin, UTexture2D*, Screenshot, FString, Path);
  36. UPROPERTY(BlueprintAssignable)
  37. FOutputPin Completed;
  38. UPROPERTY(BlueprintAssignable)
  39. FOutputPin Failed;
  40. UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "InWorldContextObject", Keywords = "File plugin screenshot save load texture", ToolTip = "Take a screenshot, save and load it"), Category = "Screenshot")
  41. static UFileHelperScreenshotAction* TakeScreenshot(UObject* InWorldContextObject, const FFileHelperScreenshotActionOptions& InOptions);
  42. UFUNCTION(BlueprintCallable, meta = (Keywords = "screenshot load texture FileHelper", ToolTip = "Load a screenshot into a texture"), Category = "Screenshot")
  43. static UTexture2D* LoadScreenshot(const FString& InFilePath);
  44. virtual void Activate() override;
  45. private:
  46. UFUNCTION()
  47. void OnTaskCompleted();
  48. void OnTaskFailed();
  49. void CreateCustomCameraScreenshot();
  50. void Reset();
  51. UPROPERTY()
  52. TObjectPtr<UObject> WorldContextObject;
  53. UPROPERTY()
  54. TObjectPtr<UTexture2D> ScreenshotTexture;
  55. UPROPERTY()
  56. FFileHelperScreenshotActionOptions Options;
  57. /** The file path of the new screenshot taken */
  58. FString FilePath;
  59. /** Is this node active */
  60. bool bActive = false;
  61. };