Rearrange all Blueprint functions into better categories
This commit is contained in:
59
Source/Integration/UtilityLibrary.cpp
Normal file
59
Source/Integration/UtilityLibrary.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "UtilityLibrary.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Luprex Utility"
|
||||
|
||||
void UlxUtilityLibrary::Assert(bool condition, const FString &message) {
|
||||
if (!condition) {
|
||||
FBlueprintExceptionInfo ExceptionInfo(EBlueprintExceptionType::FatalError, FText::FromString(message));
|
||||
FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void UlxUtilityLibrary::CallFunctionByName(UObject *object, const FString &namepart1, const FString &namepart2, const FString &fallback) {
|
||||
FString fullname = namepart1 + namepart2;
|
||||
if (!IsValid(object)) {
|
||||
const FBlueprintExceptionInfo ExceptionInfo(
|
||||
EBlueprintExceptionType::FatalError,
|
||||
LOCTEXT("CallFunctionByName_ObjectIsNotValid", "In CallFunctionByName, object passed in is not valid.")
|
||||
);
|
||||
FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo);
|
||||
return;
|
||||
}
|
||||
UFunction* function = object->FindFunction(FName(*fullname));
|
||||
if (function == nullptr) {
|
||||
function = object->FindFunction(FName(*fallback));
|
||||
if (function == nullptr) {
|
||||
const FBlueprintExceptionInfo ExceptionInfo(
|
||||
EBlueprintExceptionType::FatalError,
|
||||
LOCTEXT("CallFunctionByName_NoSuchFunction", "In CallFunctionByName, cannot find the named function or the fallback function.")
|
||||
);
|
||||
FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (function->ParmsSize != 0) {
|
||||
const FBlueprintExceptionInfo ExceptionInfo(
|
||||
EBlueprintExceptionType::FatalError,
|
||||
LOCTEXT("CallFunctionByName_FunctionHasParameters", "CallFunctionByName can only call functions that have no parameters and no return values.")
|
||||
);
|
||||
FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo);
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user