add the api for getting/setting grab properties

This commit is contained in:
Mamadou Babaei
2023-05-19 18:11:49 +02:00
parent 708d35fd59
commit 7a83ad5877
4 changed files with 168 additions and 6 deletions
@@ -68,10 +68,10 @@ struct USGGrabComponent::FImpl
bool USGGrabComponent::IsGrabbable(const AActor* Actor) bool USGGrabComponent::IsGrabbable(const AActor* Actor)
{ {
if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!"))) if (ensureAlwaysMsgf(IsValid(Actor), TEXT("%s"), TEXT("ERROR: invalid actor!")))
{ {
return false; return false;
} }
const USGGrabComponent* GrabComponent = Cast<USGGrabComponent>( const USGGrabComponent* GrabComponent = Cast<USGGrabComponent>(
Actor->GetComponentByClass(USGGrabComponent::StaticClass())); Actor->GetComponentByClass(USGGrabComponent::StaticClass()));
@@ -87,6 +87,12 @@ USGGrabComponent::USGGrabComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer), : Super(ObjectInitializer),
Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter)) Pimpl(TUniquePtr<FImpl, FImplDeleter>(new FImpl{this}, PimplDeleter))
{ {
AttachmentLocationRule = EAttachmentRule::KeepRelative;
AttachmentRotationRule = EAttachmentRule::KeepRelative;
AttachmentScaleRule = EAttachmentRule::KeepRelative;
bAttachmentWeldSimulatedBodies = false;
AttachmentSocketName = NAME_None;
} }
USGGrabComponent::FImpl::FImpl(USGGrabComponent* InOwner) USGGrabComponent::FImpl::FImpl(USGGrabComponent* InOwner)
@@ -36,7 +36,9 @@
#pragma once #pragma once
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "Engine/EngineTypes.h"
#include "Templates/UniquePtr.h" #include "Templates/UniquePtr.h"
#include "UObject/NameTypes.h"
#include "SGGrabComponent.generated.h" #include "SGGrabComponent.generated.h"
@@ -50,6 +52,22 @@ class SENSEGLOVE_API USGGrabComponent : public USceneComponent
public: public:
static bool IsGrabbable(const AActor* Actor); static bool IsGrabbable(const AActor* Actor);
private:
UPROPERTY(EditAnywhere, Category="SenseGlove | Attachment Rules", meta=(AllowPrivateAccess="false"))
EAttachmentRule AttachmentLocationRule;
UPROPERTY(EditAnywhere, Category="SenseGlove | Attachment Rules", meta=(AllowPrivateAccess="false"))
EAttachmentRule AttachmentRotationRule;
UPROPERTY(EditAnywhere, Category="SenseGlove | Attachment Rules", meta=(AllowPrivateAccess="false"))
EAttachmentRule AttachmentScaleRule;
UPROPERTY(EditAnywhere, Category="SenseGlove | Attachment Rules", meta=(AllowPrivateAccess="false"))
bool bAttachmentWeldSimulatedBodies;
UPROPERTY(EditAnywhere, Category="SenseGlove", meta=(AllowPrivateAccess="false"))
FName AttachmentSocketName;
private: private:
struct FImpl; struct FImpl;
@@ -62,4 +80,53 @@ private:
FImplDeleter PimplDeleter; FImplDeleter PimplDeleter;
public: public:
FORCEINLINE EAttachmentRule GetAttachmentLocationRule() const
{
return AttachmentLocationRule;
}
FORCEINLINE void SetAttachmentLocationRule(const EAttachmentRule InAttachmentLocationRule)
{
AttachmentLocationRule = InAttachmentLocationRule;
}
FORCEINLINE EAttachmentRule GetAttachmentRotationRule() const
{
return AttachmentRotationRule;
}
FORCEINLINE void SetAttachmentRotationRule(const EAttachmentRule InAttachmentRotationRule)
{
AttachmentRotationRule = InAttachmentRotationRule;
}
FORCEINLINE EAttachmentRule GetAttachmentScaleRule() const
{
return AttachmentScaleRule;
}
FORCEINLINE void SetAttachmentScaleRule(const EAttachmentRule InAttachmentScaleRule)
{
AttachmentScaleRule = InAttachmentScaleRule;
}
FORCEINLINE bool GetAttachmentWeldSimulatedBodies() const
{
return bAttachmentWeldSimulatedBodies;
}
FORCEINLINE void SetAttachmentWeldSimulatedBodies(const bool bInAttachmentWeldSimulatedBodies)
{
bAttachmentWeldSimulatedBodies = bInAttachmentWeldSimulatedBodies;
}
FORCEINLINE const FName& GetAttachmentSocketName() const
{
return AttachmentSocketName;
}
FORCEINLINE void SetAttachmentSocketName(const FName& InAttachmentSocketName)
{
AttachmentSocketName = InAttachmentSocketName;
}
}; };
@@ -1,4 +1,3 @@
/** /**
* @file * @file
* *
@@ -43,4 +42,59 @@
bool UGrabComponentKismetLibrary::IsGrabbable(const AActor* Actor) bool UGrabComponentKismetLibrary::IsGrabbable(const AActor* Actor)
{ {
return USGGrabComponent::IsGrabbable(Actor); return USGGrabComponent::IsGrabbable(Actor);
}
EAttachmentRule UGrabComponentKismetLibrary::GetAttachmentLocationRule(const USGGrabComponent* GrabComponent)
{
return GrabComponent->GetAttachmentLocationRule();
}
void UGrabComponentKismetLibrary::SetAttachmentLocationRule(USGGrabComponent* GrabComponent,
const EAttachmentRule InAttachmentLocationRule)
{
GrabComponent->SetAttachmentLocationRule(InAttachmentLocationRule);
}
EAttachmentRule UGrabComponentKismetLibrary::GetAttachmentRotationRule(const USGGrabComponent* GrabComponent)
{
return GrabComponent->GetAttachmentRotationRule();
}
void UGrabComponentKismetLibrary::SetAttachmentRotationRule(USGGrabComponent* GrabComponent,
const EAttachmentRule InAttachmentRotationRule)
{
GrabComponent->SetAttachmentRotationRule(InAttachmentRotationRule);
}
EAttachmentRule UGrabComponentKismetLibrary::GetAttachmentScaleRule(const USGGrabComponent* GrabComponent)
{
return GrabComponent->GetAttachmentScaleRule();
}
void UGrabComponentKismetLibrary::SetAttachmentScaleRule(USGGrabComponent* GrabComponent,
const EAttachmentRule InAttachmentScaleRule)
{
GrabComponent->SetAttachmentScaleRule(InAttachmentScaleRule);
}
bool UGrabComponentKismetLibrary::GetAttachmentWeldSimulatedBodies(const USGGrabComponent* GrabComponent)
{
return GrabComponent->GetAttachmentWeldSimulatedBodies();
}
void UGrabComponentKismetLibrary::SetAttachmentWeldSimulatedBodies(USGGrabComponent* GrabComponent,
const bool bInAttachmentWeldSimulatedBodies)
{
GrabComponent->SetAttachmentWeldSimulatedBodies(bInAttachmentWeldSimulatedBodies);
}
const FName& UGrabComponentKismetLibrary::GetAttachmentSocketName(const USGGrabComponent* GrabComponent)
{
return GrabComponent->GetAttachmentSocketName();
}
void UGrabComponentKismetLibrary::SetAttachmentSocketName(USGGrabComponent* GrabComponent,
const FName& InAttachmentSocketName)
{
GrabComponent->SetAttachmentSocketName(InAttachmentSocketName);
} }
@@ -42,7 +42,7 @@
#include "SGGrabComponentKismetLibrary.generated.h" #include "SGGrabComponentKismetLibrary.generated.h"
class AActor; class AActor;
class UGrabComponent; class USGGrabComponent;
UCLASS(meta=(ScriptName = "SesneGloveGrabComponentKismetLibrary")) UCLASS(meta=(ScriptName = "SesneGloveGrabComponentKismetLibrary"))
class SENSEGLOVEKISMET_API UGrabComponentKismetLibrary final : public USGBlueprintFunctionLibrary class SENSEGLOVEKISMET_API UGrabComponentKismetLibrary final : public USGBlueprintFunctionLibrary
@@ -52,4 +52,39 @@ class SENSEGLOVEKISMET_API UGrabComponentKismetLibrary final : public USGBluepri
public: public:
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component") UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static bool IsGrabbable(const AActor* Actor); static bool IsGrabbable(const AActor* Actor);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Grab Component")
static EAttachmentRule GetAttachmentLocationRule(const USGGrabComponent* GrabComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static void SetAttachmentLocationRule(UPARAM(ref) USGGrabComponent* GrabComponent,
EAttachmentRule InAttachmentLocationRule);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Grab Component")
static EAttachmentRule GetAttachmentRotationRule(const USGGrabComponent* GrabComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static void SetAttachmentRotationRule(UPARAM(ref) USGGrabComponent* GrabComponent,
EAttachmentRule InAttachmentRotationRule);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Grab Component")
static EAttachmentRule GetAttachmentScaleRule(const USGGrabComponent* GrabComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static void SetAttachmentScaleRule(UPARAM(ref) USGGrabComponent* GrabComponent,
EAttachmentRule InAttachmentScaleRule);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Grab Component")
static bool GetAttachmentWeldSimulatedBodies(const USGGrabComponent* GrabComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static void SetAttachmentWeldSimulatedBodies(UPARAM(ref) USGGrabComponent* GrabComponent,
bool bInAttachmentWeldSimulatedBodies);
UFUNCTION(BlueprintPure, Category="SenseGlove | Components | Grab Component")
static const FName& GetAttachmentSocketName(const USGGrabComponent* GrabComponent);
UFUNCTION(BlueprintCallable, Category="SenseGlove | Components | Grab Component")
static void SetAttachmentSocketName(UPARAM(ref) USGGrabComponent* GrabComponent,
const FName& InAttachmentSocketName);
}; };