Files
Table-UE/Table/Source/Table/Public/GestureManagerComponent.h
T

92 lines
2.6 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "GestureData.h"
#include "GestureManagerComponent.generated.h"
class AHandManager;
UCLASS(ClassGroup = "Gesture", BlueprintType, Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class TABLE_API UGestureManagerComponent : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UGestureManagerComponent();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Scale")
float UEUnitsPerUnit = 100.f; // set via calibration rectangle
UPROPERTY(BlueprintReadOnly)
AHandManager* HandManager;
UFUNCTION(BlueprintCallable, Category = "Gesture")
void EvaluateHands();
UFUNCTION()
void OnHandAdded(AHandActor* Hand);
UFUNCTION()
void OnHandRemoved(AHandActor* Hand);
UPROPERTY(EditDefaultsOnly, Category = "Gesture")
FString BindingConfigPath; // path to the per-game JSON
// Loaded from JSON — gesture name -> definition object
UPROPERTY(BlueprintReadOnly, Category = "Gesture")
TArray<UGestureDefinition*> GestureDefinitions;
UPROPERTY(BlueprintReadOnly, Category = "Gesture")
TArray<AGestureAction*> ActiveGestureActions;
// Populated on BeginPlay from JSON
UPROPERTY(BlueprintReadOnly, Category = "Gesture")
TArray<FGestureBinding> GestureBindings;
void LoadBindings(const FString& FilePath);
void Initialize(UDataTable* InGestureTable, UDataTable* InActionTable);
void BuildDefinitionMap();
void BuildActionMap();
// Populated on BeginPlay from the tables
UPROPERTY(BlueprintReadOnly, Category = "Gesture")
TMap<FName, UGestureDefinition*> DefinitionMap;
UPROPERTY(BlueprintReadOnly, Category = "Gesture")
TMap<FName, TSubclassOf<AGestureAction>> ActionClassMap;
private:
//
UPROPERTY(EditDefaultsOnly, Category = "Gesture")
UDataTable* GestureDefinitionTable;
UPROPERTY(EditDefaultsOnly, Category = "Gesture")
UDataTable* GestureActionTable;
void CheckGestureDefinitions(TArray<AHandActor*>& Hands);
void TriggerAction(AHandActor* Hand);
void UpdateOngoingActions();
AGestureAction* SpawnGestureAction(FName ActionName, AHandActor* Hand);
bool TryExtendGestureAction(AHandActor* Hand);
bool TryJoinExistingAction(AHandActor* Hand);
bool TryCreateExtension(AHandActor* Hand);
static constexpr int32 CandidateThreshold = 8;
static constexpr int32 FailThreshold = 5;
};