Move some utility functions from Blueprint to C++
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
|
||||
#include "UtilityLibrary.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Luprex Utility"
|
||||
|
||||
@@ -60,3 +62,32 @@ FBox UlxUtilityLibrary::GetActorBounds(const AActor *target, bool bOnlyColliding
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user