add static get component methods for quickly accessing grab/touch components

This commit is contained in:
Mamadou Babaei
2023-05-19 18:14:38 +02:00
parent 776fe784b0
commit 326dabab5c
8 changed files with 44 additions and 0 deletions
@@ -66,6 +66,18 @@ struct USGGrabComponent::FImpl
************************/
};
USGGrabComponent* USGGrabComponent::GetGrabComponent(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return nullptr;
}
USGGrabComponent* GrabComponent = Cast<USGGrabComponent>(
Actor->GetComponentByClass(USGGrabComponent::StaticClass()));
return GrabComponent;
}
bool USGGrabComponent::IsGrabbable(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
@@ -66,6 +66,18 @@ struct USGTouchComponent::FImpl
************************/
};
USGTouchComponent* USGTouchComponent::GetTouchComponent(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{
return nullptr;
}
USGTouchComponent* TouchComponent = Cast<USGTouchComponent>(
Actor->GetComponentByClass(USGTouchComponent::StaticClass()));
return TouchComponent;
}
bool USGTouchComponent::IsTouchable(const AActor* Actor)
{
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
@@ -50,6 +50,8 @@ class SENSEGLOVE_API USGGrabComponent : public USceneComponent
GENERATED_UCLASS_BODY()
public:
static USGGrabComponent* GetGrabComponent(const AActor* Actor);
static bool IsGrabbable(const AActor* Actor);
private:
@@ -48,6 +48,8 @@ class SENSEGLOVE_API USGTouchComponent : public USceneComponent
GENERATED_UCLASS_BODY()
public:
static USGTouchComponent* GetTouchComponent(const AActor* Actor);
static bool IsTouchable(const AActor* Actor);
private:
@@ -39,6 +39,11 @@
#include "SenseGlove/Components/SGGrabComponent.h"
USGGrabComponent* UGrabComponentKismetLibrary::GetGrabComponent(const AActor* Actor)
{
return USGGrabComponent::GetGrabComponent(Actor);
}
bool UGrabComponentKismetLibrary::IsGrabbable(const AActor* Actor)
{
return USGGrabComponent::IsGrabbable(Actor);
@@ -40,6 +40,11 @@
#include "SenseGlove/Components/SGTouchComponent.h"
USGTouchComponent* UTouchComponentKismetLibrary::GetTouchComponent(const AActor* Actor)
{
return USGTouchComponent::GetTouchComponent(Actor);
}
bool UTouchComponentKismetLibrary::IsTouchable(const AActor* Actor)
{
return USGTouchComponent::IsTouchable(Actor);
@@ -50,6 +50,9 @@ class SENSEGLOVEKISMET_API UGrabComponentKismetLibrary final : public USGBluepri
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static USGGrabComponent* GetGrabComponent(const AActor* Actor);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static bool IsGrabbable(const AActor* Actor);
@@ -50,6 +50,9 @@ class SENSEGLOVEKISMET_API UTouchComponentKismetLibrary final : public USGBluepr
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Touch Component")
static USGTouchComponent* GetTouchComponent(const AActor* Actor);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Touch Component")
static bool IsTouchable(const AActor* Actor);