add a temporary workaround for the android crashes and the hidden if glove not found functionality
This commit is contained in:
@@ -41,8 +41,11 @@
|
||||
#include "UObject/ConstructorHelpers.h"
|
||||
|
||||
#include "SenseGlove/Animation/SGVirtualHandAnimInstance.h"
|
||||
#include "SGConnect/SGConnect.h"
|
||||
#include "SGCore/SGDeviceList.h"
|
||||
#include "SGCore/SGHandPose.h"
|
||||
#include "SGCore/SGHapticGlove.h"
|
||||
#include "SGCore/SGHapticGloveHandProfiles.h"
|
||||
#include "SGLog/SGLog.h"
|
||||
|
||||
struct USGVirtualHandComponent::FImpl
|
||||
@@ -115,6 +118,8 @@ struct USGVirtualHandComponent::FImpl
|
||||
const FReferenceSkeleton& GetRefSkeleton() const;
|
||||
|
||||
bool CheckGlove() const;
|
||||
|
||||
void SetVisibility(bool bVisible) const;
|
||||
};
|
||||
|
||||
const TArray<TArray<FName>>& USGVirtualHandComponent::GetLeftHandFingerBoneNames()
|
||||
@@ -203,6 +208,7 @@ USGVirtualHandComponent::USGVirtualHandComponent(const FObjectInitializer& Objec
|
||||
TEXT("Failed to load the skeletal mesh: '%s'"), *SkeletalMeshPath);
|
||||
Super::SetSkeletalMesh(SkeletalMesh.Object, true);
|
||||
|
||||
bSGConnectInitialized = false;
|
||||
Glove = nullptr;
|
||||
}
|
||||
|
||||
@@ -252,6 +258,8 @@ void USGVirtualHandComponent::InitializeComponent()
|
||||
{
|
||||
Pimpl->SetDefaultMesh();
|
||||
}
|
||||
|
||||
(void) Pimpl->CheckGlove();
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::TickComponent(
|
||||
@@ -270,6 +278,13 @@ void USGVirtualHandComponent::TickComponent(
|
||||
(void) Pimpl->CheckGlove();
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
(void) Pimpl->CheckGlove();
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::SetSkeletalMesh(USkeletalMesh* NewMesh, const bool bReinitPose)
|
||||
{
|
||||
if (IsValid(NewMesh))
|
||||
@@ -481,6 +496,24 @@ const FReferenceSkeleton& USGVirtualHandComponent::FImpl::GetRefSkeleton() const
|
||||
|
||||
bool USGVirtualHandComponent::FImpl::CheckGlove() const
|
||||
{
|
||||
if (!Owner->bSGConnectInitialized)
|
||||
{
|
||||
// Ensure the device list is empty before doing anything.
|
||||
FSGDeviceList::Dispose();
|
||||
FSGDeviceList::Reinitialize();
|
||||
|
||||
// Load the latest hand profiles.
|
||||
FSGHapticGloveHandProfiles::TryLoadingFromDisk();
|
||||
|
||||
const int32_t Result = FSGConnect::Init();
|
||||
if (Result != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Owner->bSGConnectInitialized = true;
|
||||
}
|
||||
|
||||
const bool bGloveWasPresent = IsValid(Owner->Glove);
|
||||
const bool bFoundGlove = USGHapticGlove::GetGlove(Owner, Owner->IsRight(), Owner->Glove);
|
||||
|
||||
@@ -490,9 +523,20 @@ bool USGVirtualHandComponent::FImpl::CheckGlove() const
|
||||
(Owner->bRight ? TEXT("right-handed") : TEXT("left-handed"))));
|
||||
}
|
||||
|
||||
if (!IsEditor() && Owner->IsVisible() != bFoundGlove)
|
||||
{
|
||||
SetVisibility(bFoundGlove);
|
||||
}
|
||||
|
||||
return bFoundGlove;
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImpl::SetVisibility(const bool bVisible) const
|
||||
{
|
||||
Owner->SetVisibility(bVisible, true);
|
||||
Owner->SetHiddenInGame(!bVisible, false);
|
||||
}
|
||||
|
||||
void USGVirtualHandComponent::FImplDeleter::operator()(const FImpl* P) const
|
||||
{
|
||||
delete P;
|
||||
|
||||
@@ -86,6 +86,9 @@ private:
|
||||
uint8 bHiddenInGameIfNoGloveDetected : 1;
|
||||
|
||||
private:
|
||||
UPROPERTY(Transient)
|
||||
uint8 bSGConnectInitialized : 1;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
USGHapticGlove* Glove;
|
||||
|
||||
@@ -125,6 +128,8 @@ public:
|
||||
enum ELevelTick TickType,
|
||||
FActorComponentTickFunction* ThisTickFunction) override;
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void SetSkeletalMesh(USkeletalMesh* NewMesh, bool bReinitPose = true) override;
|
||||
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user