Move some utility functions from Blueprint to C++

This commit is contained in:
2024-10-15 16:17:44 -04:00
parent 25dd7cabcb
commit ecbca6e5a2
5 changed files with 57 additions and 7 deletions

Binary file not shown.

View File

@@ -8,7 +8,7 @@ public class Integration : ModuleRules
{ {
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking", "EnhancedInput" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });

View File

@@ -2,6 +2,8 @@
#include "UtilityLibrary.h" #include "UtilityLibrary.h"
#include "GameFramework/PlayerController.h"
#include "EnhancedInputSubsystems.h"
#define LOCTEXT_NAMESPACE "Luprex Utility" #define LOCTEXT_NAMESPACE "Luprex Utility"
@@ -60,3 +62,32 @@ FBox UlxUtilityLibrary::GetActorBounds(const AActor *target, bool bOnlyColliding
return FBox::BuildAABB(ActorOrigin, BoxExtent); return FBox::BuildAABB(ActorOrigin, BoxExtent);
} }
void UlxUtilityLibrary::AddMovementInputRightward(APawn *target, double ScaleValue, bool Force) {
FRotator rotator = target->GetControlRotation();
rotator.Pitch = 0.0;
rotator.Roll = 0.0;
rotator.Yaw += 90.0;
FVector vector = rotator.Vector();
target->AddMovementInput(vector, ScaleValue, Force);
}
void UlxUtilityLibrary::AddMovementInputForward(APawn *target, double ScaleValue, bool Force) {
FRotator rotator = target->GetControlRotation();
rotator.Roll = 0.0;
rotator.Pitch = 0.0;
FVector vector = rotator.Vector();
target->AddMovementInput(vector, ScaleValue, Force);
}
UEnhancedInputLocalPlayerSubsystem *UlxUtilityLibrary::GetEnhancedInputLocalPlayerSubsystem(AController *Controller) {
APlayerController *pc = Cast<APlayerController>(Controller);
if (pc != nullptr) {
UEnhancedInputLocalPlayerSubsystem* subsys =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(pc->GetLocalPlayer());
if (subsys != nullptr) {
return subsys;
}
}
return nullptr;
}

View File

@@ -5,10 +5,13 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "UtilityLibrary.generated.h" #include "UtilityLibrary.generated.h"
class UEnhancedInputLocalPlayerSubsystem;
/** /**
* *
* UlxUtilityLibrary is for functions that are just generally-useful functionality * UlxUtilityLibrary is for functions that are aren't particularly luprex-specific,
* that Unreal includes, but for some reason was not made accessible to Blueprints. * but rather, are just generally-useful functionality that could help in any
* Unreal program.
* *
*/ */
UCLASS() UCLASS()
@@ -33,4 +36,20 @@ public:
// //
UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility")
static FBox GetActorBounds(const AActor *target, bool bOnlyCollidingComponents = false, bool bIncludeFromChildActors = false); 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);
}; };