add the USGVirtualHandComponent::OnHandVisibilityChanged() event

This commit is contained in:
Mamadou Babaei
2024-06-06 17:25:48 +02:00
parent 1114270bb8
commit dfff2f469d
2 changed files with 38 additions and 9 deletions
@@ -99,9 +99,9 @@ struct USGVirtualHandComponent::FImpl
* Member variables * Member variables
************************/ ************************/
FCollisionResponseContainer CachedCollisionResponse;
ECollisionEnabled::Type CachedCollisionEnabled;
bool bCachedGenerateOverlapEvents; bool bCachedGenerateOverlapEvents;
ECollisionEnabled::Type CachedCollisionEnabled;
FCollisionResponseContainer CachedCollisionResponse;
/************************ /************************
* Owner object * Owner object
@@ -146,6 +146,8 @@ struct USGVirtualHandComponent::FImpl
void UpdateVisibility(); void UpdateVisibility();
void DrawDebugVirtualHand() const; void DrawDebugVirtualHand() const;
void TriggerHandVisibilityChangedEvent(bool bNewVisibility) const;
}; };
const TArray<FName>& USGVirtualHandComponent::GetLeftHandBoneNames() const TArray<FName>& USGVirtualHandComponent::GetLeftHandBoneNames()
@@ -240,6 +242,10 @@ USGVirtualHandComponent::USGVirtualHandComponent(const FObjectInitializer& Objec
WristTracker = nullptr; WristTracker = nullptr;
} }
void USGVirtualHandComponent::OnHandVisibilityChanged_Implementation(bool bNewVisibility)
{
}
void USGVirtualHandComponent::SetRight(const bool bInRight) void USGVirtualHandComponent::SetRight(const bool bInRight)
{ {
bRight = bInRight; bRight = bInRight;
@@ -470,8 +476,8 @@ FRotator USGVirtualHandComponent::GetHandBoneRefRotation(const int32 Joint) cons
} }
USGVirtualHandComponent::FImpl::FImpl(USGVirtualHandComponent* InOwner) USGVirtualHandComponent::FImpl::FImpl(USGVirtualHandComponent* InOwner)
: CachedCollisionEnabled(InOwner->GetCollisionEnabled()), : bCachedGenerateOverlapEvents(InOwner->GetGenerateOverlapEvents()),
bCachedGenerateOverlapEvents(InOwner->GetGenerateOverlapEvents()), CachedCollisionEnabled(InOwner->GetCollisionEnabled()),
Owner(InOwner) Owner(InOwner)
{ {
@@ -595,19 +601,19 @@ const FReferenceSkeleton& USGVirtualHandComponent::FImpl::GetRefSkeleton() const
void USGVirtualHandComponent::FImpl::DisableCollisionResponse() void USGVirtualHandComponent::FImpl::DisableCollisionResponse()
{ {
bCachedGenerateOverlapEvents = Owner->GetGenerateOverlapEvents();
CachedCollisionEnabled = Owner->GetCollisionEnabled(); CachedCollisionEnabled = Owner->GetCollisionEnabled();
CachedCollisionResponse = Owner->GetCollisionResponseToChannels(); CachedCollisionResponse = Owner->GetCollisionResponseToChannels();
bCachedGenerateOverlapEvents = Owner->GetGenerateOverlapEvents();
Owner->SetCollisionResponseToAllChannels(ECR_Ignore);
Owner->SetCollisionEnabled(ECollisionEnabled::NoCollision);
Owner->SetGenerateOverlapEvents(false); Owner->SetGenerateOverlapEvents(false);
Owner->SetCollisionEnabled(ECollisionEnabled::NoCollision);
Owner->SetCollisionResponseToAllChannels(ECR_Ignore);
} }
void USGVirtualHandComponent::FImpl::RestoreCollisionResponse() const void USGVirtualHandComponent::FImpl::RestoreCollisionResponse() const
{ {
Owner->SetCollisionResponseToChannels(CachedCollisionResponse);
Owner->SetCollisionEnabled(CachedCollisionEnabled);
Owner->SetGenerateOverlapEvents(bCachedGenerateOverlapEvents); Owner->SetGenerateOverlapEvents(bCachedGenerateOverlapEvents);
Owner->SetCollisionEnabled(CachedCollisionEnabled);
Owner->SetCollisionResponseToChannels(CachedCollisionResponse);
} }
void USGVirtualHandComponent::FImpl::SetVisibility(const bool bInVisible) void USGVirtualHandComponent::FImpl::SetVisibility(const bool bInVisible)
@@ -622,6 +628,8 @@ void USGVirtualHandComponent::FImpl::SetVisibility(const bool bInVisible)
{ {
DisableCollisionResponse(); DisableCollisionResponse();
} }
TriggerHandVisibilityChangedEvent(bInVisible);
} }
void USGVirtualHandComponent::FImpl::UpdateVisibility() void USGVirtualHandComponent::FImpl::UpdateVisibility()
@@ -664,6 +672,12 @@ void USGVirtualHandComponent::FImpl::DrawDebugVirtualHand() const
FSGDebugVirtualHand::Draw(World, MotionControllerData, Owner->DebugVirtualHandSettings); FSGDebugVirtualHand::Draw(World, MotionControllerData, Owner->DebugVirtualHandSettings);
} }
void USGVirtualHandComponent::FImpl::TriggerHandVisibilityChangedEvent(const bool bNewVisibility) const
{
Owner->HandVisibilityChangedEvent.Broadcast(bNewVisibility);
Owner->OnHandVisibilityChanged(bNewVisibility);
}
void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const
{ {
delete P; delete P;
@@ -62,6 +62,17 @@ class SENSEGLOVE_API USGVirtualHandComponent : public USkeletalMeshComponent
{ {
GENERATED_UCLASS_BODY() GENERATED_UCLASS_BODY()
public:
DECLARE_EVENT_OneParam(USGVirtualHandComponent, FHandVisibilityChangedEvent, bool bNewVisibiliy);
FHandVisibilityChangedEvent& OnHandVisibilityChanged()
{
return HandVisibilityChangedEvent;
};
private:
FHandVisibilityChangedEvent HandVisibilityChangedEvent;
public: public:
static const TArray<FName>& GetLeftHandBoneNames(); static const TArray<FName>& GetLeftHandBoneNames();
static const TArray<FName>& GetRightHandBoneNames(); static const TArray<FName>& GetRightHandBoneNames();
@@ -136,6 +147,10 @@ private:
UPROPERTY(Transient) UPROPERTY(Transient)
USGWristTrackerComponent* WristTracker; USGWristTrackerComponent* WristTracker;
protected:
UFUNCTION(BlueprintNativeEvent, Category="SenseGlove | Components | Virtual Hand Component")
void OnHandVisibilityChanged(bool bNewVisibility);
public: public:
FORCEINLINE bool IsLeft() const FORCEINLINE bool IsLeft() const
{ {