2024-09-24 18:58:13 -04:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "UtilityLibrary.h"
|
2024-10-15 16:17:44 -04:00
|
|
|
#include "GameFramework/PlayerController.h"
|
|
|
|
|
#include "EnhancedInputSubsystems.h"
|
2024-09-24 18:58:13 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "Luprex Utility"
|
|
|
|
|
|
|
|
|
|
|
2024-09-24 22:13:56 -04:00
|
|
|
void UlxUtilityLibrary::CallFunctionByName(UObject *object, const FString &namepart1, const FString &namepart2, const FString &fallback, bool bFailIfNotFound) {
|
2024-09-24 18:58:13 -04:00
|
|
|
FString fullname = namepart1 + namepart2;
|
|
|
|
|
if (!IsValid(object)) {
|
2024-11-22 23:01:05 -05:00
|
|
|
UE_LOG(LogBlueprint, Error, TEXT("In CallFunctionByName, object passed in is not valid."));
|
2024-09-24 18:58:13 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2024-09-30 13:59:17 -04:00
|
|
|
UFunction* function = object->FindFunction(FName(*fullname));
|
2024-09-24 18:58:13 -04:00
|
|
|
if (function == nullptr) {
|
|
|
|
|
function = object->FindFunction(FName(*fallback));
|
|
|
|
|
if (function == nullptr) {
|
2024-09-24 22:13:56 -04:00
|
|
|
if (!bFailIfNotFound) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-22 23:01:05 -05:00
|
|
|
UE_LOG(LogBlueprint, Error, TEXT("In CallFunctionByName, cannot find the named function or the fallback function"));
|
2024-09-24 18:58:13 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (function->ParmsSize != 0) {
|
2024-11-22 23:01:05 -05:00
|
|
|
UE_LOG(LogBlueprint, Error, TEXT("CallFunctionByName can only call functions that have no parameters and no return values"));
|
2024-09-24 18:58:13 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
object->ProcessEvent(function, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBox UlxUtilityLibrary::GetActorBounds(const AActor *target, bool bOnlyCollidingComponents, bool bIncludeFromChildActors)
|
|
|
|
|
{
|
|
|
|
|
FVector ActorOrigin;
|
|
|
|
|
FVector BoxExtent;
|
|
|
|
|
|
|
|
|
|
// First argument is bOnlyCollidingComponents - if you want to get the bounds for components that don't have collision enabled then set to false
|
|
|
|
|
// Last argument is bIncludeFromChildActors. Usually this won't do anything but if we've child-ed an actor - like a gun child-ed to a character
|
|
|
|
|
// then we wouldn't want the gun to be part of the bounds so set to false
|
|
|
|
|
target->GetActorBounds(bOnlyCollidingComponents, ActorOrigin, BoxExtent, bIncludeFromChildActors);
|
|
|
|
|
|
|
|
|
|
return FBox::BuildAABB(ActorOrigin, BoxExtent);
|
|
|
|
|
}
|
2024-10-15 16:17:44 -04:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|