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의 마지막 인수로 태그를 전달하여 어떤 키가 눌리고 있는지 확인할 수 있게 된다.
- 해당 함수는 템플릿 함수이기 때문에 전방 선언이 아니라 헤더 파일을 포함시키는 방법을 사용해야 한다.
'UE 5 스터디 > Gameplay Ability System(GAS)' 카테고리의 다른 글
8-7. 입력 - (4) 입력에 따른 어빌리티 활성화 (0) | 2024.12.03 |
---|---|
8-6. 입력 - (3) 입력 버튼과 버튼 상태에 따른 함수 및 태그 바인딩 (0) | 2024.12.03 |
8-4. 입력 - (1) 입력 설정 데이터 에셋(Input Config Data Asset) (0) | 2024.12.03 |
8-3. 게임플레이 어빌리티 - (2) 어빌리티 설정(Settings on Gameplay Ability) (0) | 2024.12.03 |
8-2. 게임플레이 어빌리티 - (1) 어빌리티 부여(Granting Ability) (0) | 2024.10.31 |