Files
integration/Source/Integration/UtilityLibrary.h

97 lines
4.2 KiB
C++

// 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;
USTRUCT(BlueprintType)
struct INTEGRATION_API FlxTraceStartTraceEnd
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
FVector TraceStart;
UPROPERTY(EditAnywhere)
FVector TraceEnd;
};
UENUM(BlueprintType)
enum class EMouseSpecificationType : uint8
{
// Automatically get the mouse position from the player controller. ManualMouseXY should be left blank.
GetMouseAutomatically,
// Specify the mouse position in pixels.
SpecifyMouseInPixels,
// Specify the mouse position as float from zero to one.
SpecifyMouseAsZeroToOne,
};
/**
*
* 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(BlueprintCallable, BlueprintPure, Category="Player Controller|Local Player Subsystems")
static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller);
// // Do a Line Trace by Channel for each start-and-end pair, then return the closest hit result of all.
// UFUNCTION(BlueprintCallable, Category="Collision", meta=(bIgnoreReferenceActor="true", AutoCreateRefTerm="ActorsToIgnore,Offset", DisplayName="Line Trace Multiple Lines by Channel", AdvancedDisplay="TraceColor,TraceHitColor,DrawTime", Keywords="raycast"))
// static bool LineTraceMultipleLines(const AActor* ReferenceActor, const FVector &Offset,
// const TArray<FlxTraceStartTraceEnd> &TraceStartAndTraceEnd, ETraceTypeQuery TraceChannel,
// bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreReferenceActor,
// FLinearColor TraceColor = FLinearColor::Red, FLinearColor TraceHitColor = FLinearColor::Green, float DrawTime = 5.0f);
// Do a Line Trace to find the actor that the mouse is pointing at.
//
// If you have some crosshairs in the viewport, then you can find the
// object under the crosshairs by specifying the crosshairs XY as the
// ManualMouseXY.
//
UFUNCTION(BlueprintCallable, Category="Collision", meta=(AutoCreateRefTerm="ActorsToIgnore", Keywords="raycast"))
static bool LineTraceThroughMousePointer(const APlayerController* PlayerController,
EMouseSpecificationType MouseSpecification, FVector2D ManualMouseXY, double MaxDistanceFromCamera,
ETraceTypeQuery TraceChannel, bool bTraceComplex, EDrawDebugTrace::Type DrawDebugType, bool bIgnorePlayerPawn,
const TArray<AActor*>& ActorsToIgnore, AActor *& Actor, FHitResult& HitResult);
};