c4.3Subsystem|EnhancedInput优先级
大约 1 分钟
导读
EnhancedInput|Action绑定
if (const APlayerController* PC = GetOwningPlayer())
{
LocalPlayer = PC->GetLocalPlayer();
if (LocalPlayer)
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
{
// 检查是否已经添加了输入映射上下文
if (!Subsystem->HasMappingContext(InputMappingContext))
{
Subsystem->AddMappingContext(InputMappingContext, 2);
}
}
}
}
// 绑定聊天切换动作
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(GetOwningPlayer()->InputComponent))
{
if (InputAction_ChatToggle)
{
EnhancedInputComponent->BindAction(InputAction_ChatToggle, ETriggerEvent::Triggered, this, &UChatWidgetBase::HandleChatAction);
}
}
EnhancedInput|Action解绑
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(GetOwningPlayer()->InputComponent))
{
if (InputAction_ChatTab)
{
int32 PreviousAction = -1;
for (int i = 0; i < EnhancedInputComponent->GetNumActionBindings(); i++) {
if (EnhancedInputComponent->GetActionBinding(i).ActionDelegate.IsBoundToObject(InputAction_ChatTab)) {
PreviousAction = EnhancedInputComponent->GetActionBinding(i).GetHandle();
break;
}
}
EnhancedInputComponent->RemoveActionBindingForHandle(PreviousAction);
}
}
EnhancedInput|切换IMC优先级
Subsystem->AddMappingContext(InputMappingContext, 1);