Input Component core functionality done

master
MostExcellent 2024-10-21 14:09:34 -07:00
parent 8313c57825
commit 780062a8ed
5 changed files with 51 additions and 6 deletions

View File

@ -3,11 +3,13 @@
#include "Input/VRInputConfig.h" #include "Input/VRInputConfig.h"
#include "Logging.h"
UInputAction* UVRInputConfig::FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound) const UInputAction* UVRInputConfig::FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound) const
{ {
if (!InTag.IsValid()) return nullptr; if (!InTag.IsValid()) return nullptr;
for (const FVRTagInputAction& Action : NativeInputActions) for (const FVRTagInputBinding& Action : NativeInputActions)
{ {
if (!Action.IsValid()) continue; if (!Action.IsValid()) continue;
@ -19,7 +21,8 @@ UInputAction* UVRInputConfig::FindNativeInputActionForTag(const FGameplayTag& In
if (bLogNotFound) if (bLogNotFound)
{ {
// TODO: Add logging for VRGAS UE_LOG(VRGAS_Log, Error, TEXT("Could not find Native Action for Tag %s on InputConfig %s"),
*InTag.ToString(), *GetNameSafe(this))
} }
return nullptr; return nullptr;
@ -28,7 +31,7 @@ UInputAction* UVRInputConfig::FindAbilityInputActionForTag(const FGameplayTag& I
{ {
if (!InTag.IsValid()) return nullptr; if (!InTag.IsValid()) return nullptr;
for (const FVRTagInputAction& Action : AbilityInputActions) for (const FVRTagInputBinding& Action : AbilityInputActions)
{ {
if (!Action.IsValid() && Action.InputTag.IsValid()) if (!Action.IsValid() && Action.InputTag.IsValid())
{ {

View File

@ -0,0 +1,3 @@
#include "Logging.h"
DEFINE_LOG_CATEGORY(VRGAS_Log)

View File

@ -0,0 +1,5 @@
#pragma once
#include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(VRGAS_Log, Log, All)

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "EnhancedInputComponent.h" #include "EnhancedInputComponent.h"
#include "VRInputConfig.h"
#include "VRInputComponent.generated.h" #include "VRInputComponent.generated.h"
@ -12,4 +13,36 @@ class VRGAS_API UVRInputComponent : public UEnhancedInputComponent
{ {
GENERATED_BODY() GENERATED_BODY()
template <class UserClass, typename FuncType>
void BindNativeActions(const UVRInputConfig* InputConfig, const FGameplayTag& InputTag, ETriggerEvent TriggerEvent,
UserClass* Object,FuncType Func, bool bLogNotFound = true);
template <class UserClass, typename PressedFuncType, typename ReleasedFuncType>
void BindAbilityActions(const UVRInputConfig* InputConfig, UserClass* Object, PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc);
}; };
template <class UserClass, typename FuncType>
void UVRInputComponent::BindNativeActions(const UVRInputConfig* InputConfig, const FGameplayTag& InputTag, ETriggerEvent TriggerEvent,
UserClass* Object,FuncType Func, const bool bLogNotFound)
{
check(InputConfig)
if (UInputAction* Action = InputConfig->FindNativeInputActionForTag(InputTag, bLogNotFound))
{
BindAction(Action, TriggerEvent, Object, Func);
}
}
template <class UserClass, typename PressedFuncType, typename ReleasedFuncType>
void UVRInputComponent::BindAbilityActions(const UVRInputConfig* InputConfig, UserClass* Object, PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc);
{
check(InputConfig)
for (const FVRTagInputBinding& Binding : InputConfig->AbilityInputActions)
{
if (Binding.IsValid())
{
if (PressedFunc) BindAction(Binding.InputAction, ETriggerEvent::Started, Object, PressedFunc, Binding.InputTag);
if (ReleasedFunc) BindAction(Binding.InputAction, ETriggerEvent::Completed, Object, ReleasedFunc, Binding.InputTag);
}
}
}

View File

@ -11,7 +11,7 @@
class UInputAction; class UInputAction;
USTRUCT(BlueprintType) USTRUCT(BlueprintType)
struct FVRTagInputAction struct FVRTagInputBinding
{ {
GENERATED_BODY() GENERATED_BODY()
@ -26,6 +26,7 @@ struct FVRTagInputAction
return InputTag.IsValid() && InputAction != nullptr; return InputTag.IsValid() && InputAction != nullptr;
} }
}; };
/** /**
* *
*/ */
@ -36,10 +37,10 @@ class VRGAS_API UVRInputConfig : public UDataAsset
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction")) UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction"))
TArray<FVRTagInputAction> NativeInputActions; TArray<FVRTagInputBinding> NativeInputActions;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction")) UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (TitleProperty = "InputAction"))
TArray<FVRTagInputAction> AbilityInputActions; TArray<FVRTagInputBinding> AbilityInputActions;
UFUNCTION(BlueprintCallable, Category = "Input") UFUNCTION(BlueprintCallable, Category = "Input")
UInputAction* FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound = true) const; UInputAction* FindNativeInputActionForTag(const FGameplayTag& InTag, bool bLogNotFound = true) const;