플레이어 캐릭터의 행동을 제약하는 방법
- 플레이어가 특정 조건 및 상황에 따라 어떤 행동을 하지 못하게 해야하는 경우가 있다
- 마을에서 공격하지 못한다거나
- 빈사 상태인 경우에는 이동 이외에는 아무 것도 못한다거나
- 이런 경우 캐릭터의 행동이 어떻게 관리되는지에 따라 제어하는 방법이 다를 수 있다
- 단순히 boolean 토글을 체크해서 막을 수도 있다
- Gameplay Ability인 경우에는 Gameplay Tag로 제어할 수도 있다
- 행동 제어 조건을 boolean이 아닌 Gameplay Tag로 할 수도 있다
Input Mapping Context
- 플레이어 캐릭터를 조작하기 위해 매핑된 키의 집합
- 여러 개의 IMC가 동시에 활성화되어 있을 수 있으며, 동일 Input Key는 Priority에 의해 실행된다
- 조건 설정에 따라 하위 Priority의 동일 Input Key를 함께 실행시킬 수도 있다
- IMC 단위로 특정 행동이 카테고리로 묶여있다면, 이 IMC를 InputSubsystem으로부터 제외
void AddInputMappingContext(const UObject* WorldContext, class UInputMappingContext* IMC, int32 Priority)
{
if (APlayerController* PlayerController = GetLocalPlayerController(WorldContext))
{
if (UEnhancedInputLocalPlayerSubsystem* InputerSubsystem = GetLocalSubsystem<UEnhancedInputLocalPlayerSubsystem> (PlayerController))
{
InputSubsystem->AddMappingContext(IMC, Priority);
FModifyContextOption Options;
Options.bForceImmediately = true;
InputSubsystem->RequestRebuildControlMapping(Options, EInputMappingRebuildType::RebuildWithFlush);
}
}
}
void RemoveInputMappingContext(const UObject* WorldContext, class UInputMappingContext* IMC)
{
if (APlayerController* PlayerController = GetLocalPlayerController(WorldContext))
{
if (UEnhancedInputLocalPlayerSubsystem* InputerSubsystem = GetLocalSubsystem<UEnhancedInputLocalPlayerSubsystem> (PlayerController))
{
InputSubsystem->RemoveMappingContext(IMC);
}
}
}
주의할 점
- CommonInput을 통해 Input의 KeyGuide 아이콘 UI를 표기하는 경우, Activated된 Input Key들만 보여준다
- 이 때 표기해야 할 Input Key가 활성화된 IMC 중에 없다면, 해당 KeyGuide 아이콘 UI는 노출되지 않는다