// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Kismet/KismetSystemLibrary.h" #include "UtilityLibrary.generated.h" class UEnhancedInputLocalPlayerSubsystem; /** * * UlxUtilityLibrary is for functions that are aren't particularly luprex-specific, * but rather, are just generally-useful functionality that could help in any * Unreal program. * */ UCLASS() class INTEGRATION_API UlxUtilityLibrary : public UObject { GENERATED_BODY() public: // Call a function by name, on any UObject. If the function doesn't exist, calls // the fallback function instead. If that isn't found either, returns false. // UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") static void CallFunctionByName(UObject *target, const FString &NamePart1, const FString &NamePart2, const FString &fallback, bool bFailIfNotFound = true); // Get the axis-aligned bounding box of an actor. // UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") static FBox GetActorBounds(const AActor *target, bool bOnlyCollidingComponents = false, bool bIncludeFromChildActors = false); // Add movement input, using the yaw of the control rotation to find a rightward vector. // UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Pawn|Input") static void AddMovementInputRightward(APawn *target, double ScaleValue=1.0, bool Force=false); // Add movement input, using the yaw of the control rotation to find a forward vector. // UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Pawn|Input") static void AddMovementInputForward(APawn *target, double ScaleValue=1.0, bool Force=false); // Get the enhanced input local player subsystem from a controller. If the controller // is not a player controller, or if it is a player controller but it doesn't have an // enhanced input subsystem, return nullptr. UFUNCTION(BlueprintPure, Category="Player Controller|Local Player Subsystems") static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller); // Given a Pixel XY coordinate, convert it to a viewport position. // // The input should be in the range (0.0, 0.0) to (ViewportX, ViewportY). // The output XY will be in the range 0.0 to 1.0. The input // may specify a fraction of a pixel. So the input (0.0, 0.0) // represents the upper-left corner of the upper-left pixel, whereas the // input (0.5, 0.5) represents the center of the upper-left pixel. UFUNCTION(BlueprintPure, meta = (ReturnDisplayName = "Percent XY"), Category="Luprex|Utility") static FVector2D PixelToViewportPosition(FVector2D PixelXY); // Given a viewport position, convert it to a Pixel XY coordinate. // // The input X and Y coordinates should be in the range 0 to 1. The output // will be in the range (0,0) to (ViewportX, ViewportY). The output may // specify a fraction of a pixel. If SnapToCenter is true, the output is // rounded to the center of the nearest pixel. UFUNCTION(BlueprintPure, meta = (ReturnDisplayName = "Pixel XY"), Category="Luprex|Utility") static FVector2D ViewportPositionToPixel(FVector2D PercentXY, bool SnapToCenter); // Do a Line Trace from the camera through a specified pixel. // // This can be used when you have a crosshair on the screen and you want to // determine the object that the crosshairs are pointing at. It can also // be used to do a line trace through the mouse. Fractional pixels are allowed. // Be aware that (0.0, 0.0) is the upper-left corner of the upper-left pixel, // whereas (0.5, 0.5) is the center of the upper-left pixel. // // The resulting TraceStart and TraceEnd fields of the HitResult will not // contain world positions, instead, they will contain the PixelXY. // UFUNCTION(BlueprintCallable, Category="Collision", meta=(AutoCreateRefTerm="ActorsToIgnore", Keywords="raycast")) static bool LineTraceThroughPixel(const APlayerController* PlayerController, FVector2D PixelXY, double MaxDistanceFromCamera, ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn, const TArray& ActorsToIgnore, FHitResult& HitResult); };