0. 개요

이전 포스트에서 입력 액션에 입력 태그를 연결했다.

이제 입력 액션에 어빌리티를 연결한다.

 

 

1. 액션에 어빌리티 연결하기

(1) 커스텀 입력 컴포넌트 생성(AuraInputComponent)

Enhanced Input Component를 상속받는 C++ 클래스인 AuraInputComponent를 생성한다.

 

 

(2) 입력 액션에 함수를 바인딩하는 템플릿 함수 - BindAbilityActions 함수

누름, 뗌, 누르고 있음의 세 가지 상태에 따라 각각의 함수를 실행할 수 있게 하는 템플릿 함수를 생성한다.

#include "CoreMinimal.h"
#include "EnhancedInputComponent.h"
#include "AuraInputConfig.h"
#include "AuraInputComponent.generated.h"

/**
 * 
 */
UCLASS()
class AURA_API UAuraInputComponent : public UEnhancedInputComponent
{
	GENERATED_BODY()

public:
	template<class UserClass, typename PressedFuncType, typename ReleasedFuncType, typename HeldFuncType>
	void BindAbiltyActions(const UAuraInputConfig* InputConfig, UserClass* Object, PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc, HeldFuncType HeldFunc);
	
};

template<class UserClass, typename PressedFuncType, typename ReleasedFuncType, typename HeldFuncType>
inline void UAuraInputComponent::BindAbiltyActions(const UAuraInputConfig* InputConfig, UserClass* Object, PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc, HeldFuncType HeldFunc)
{
	check(InputConfig);

	for (const FAuraInputAction& Action : InputConfig->AbilityInputActions)
	{
		if (Action.InputAction && Action.InputTag.IsValid())
		{
			if (PressedFunc)
			{
				BindAction(Action.InputAction, ETriggerEvent::Started, Object, PressedFunc, Action.InputTag);
			}

			if (ReleasedFunc)
			{
				BindAction(Action.InputAction, ETriggerEvent::Completed, Object, ReleasedFunc, Action.InputTag);
			}

			if (HeldFunc)
			{
				BindAction(Action.InputAction, ETriggerEvent::Triggered, Object, HeldFunc, Action.InputTag);
			}
		}
	}
}

BindAction의 마지막 인수로 태그를 전달하여 어떤 키가 눌리고 있는지 확인할 수 있게 된다.


- 해당 함수는 템플릿 함수이기 때문에 전방 선언이 아니라 헤더 파일을 포함시키는 방법을 사용해야 한다.