Move some utility functions from Blueprint to C++
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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[] { });
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user