-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c56082d
commit de49245
Showing
2 changed files
with
124 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
--- | ||
title: c4.3Subsystem|EnhancedInput优先级 | ||
order : 403 | ||
category: | ||
- u++ | ||
--- | ||
### 导读 | ||
|
||
<chatmessage avatar="../../assets/emoji/bqb (2).png" :avatarWidth="40" alignLeft> | ||
|
||
食用本文建议先了解什么是增强输入系统![直通车](4.2-EnhancedInput) | ||
|
||
</chatmessage> | ||
|
||
## EnhancedInput|Action绑定 | ||
|
||
<chatmessage avatar="../../assets/emoji/hx.png" :avatarWidth="40"> | ||
前文已经对增强输入系统有了个初步的理解。也知道上下文以及Action如何相辅相成。 | ||
</chatmessage> | ||
|
||
```cpp | ||
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解绑 | ||
<chatmessage avatar="../../assets/emoji/hx.png" :avatarWidth="40"> | ||
现在我们知道怎么绑定Action,怎么解绑Action? | ||
</chatmessage> | ||
<chatmessage avatar="../../assets/emoji/dsyj.png" :avatarWidth="40" alignLeft> | ||
问得好!目前来看根据句柄解绑的方法比较靠谱。但需要手动获取句柄ID | ||
</chatmessage> | ||
```cpp | ||
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); | ||
} | ||
} | ||
``` | ||
|
||
<chatmessage avatar="../../assets/emoji/hx.png" :avatarWidth="40"> | ||
可是我实际运行后发现解绑后依然起作用啊! | ||
</chatmessage> | ||
|
||
## EnhancedInput|切换IMC优先级 | ||
|
||
<chatmessage avatar="../../assets/emoji/dsyj.png" :avatarWidth="40" alignLeft> | ||
你这种情况极大概率是因为IMC的优先级导致的,你是不是之前的IMC配置过相同的按键? | ||
</chatmessage> | ||
|
||
<chatmessage avatar="../../assets/emoji/hx.png" :avatarWidth="40"> | ||
没错!我在默认的IMC中配置过相同的按键给Action! | ||
</chatmessage> | ||
|
||
<chatmessage avatar="../../assets/emoji/dsyj.png" :avatarWidth="40" alignLeft> | ||
那就没错了,如果多个IMC配置了同个Action到相同的按键时,IMC Priority优先级高的生效,这种情况只需要 Priority降级就行了。 | ||
</chatmessage> | ||
|
||
|
||
|
||
```cpp | ||
Subsystem->AddMappingContext(InputMappingContext, 1); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters