vault backup: 2025-08-29 17:08:18
This commit is contained in:
@@ -1 +1 @@
|
|||||||
{"配置IA中的UserSetting选项。":{"配置IA中的UserSetting选项。":{"currentFile":{"count":1,"lastUpdated":1756439877872}}}}
|
{"配置IA中的UserSetting选项。":{"配置IA中的UserSetting选项。":{"currentFile":{"count":1,"lastUpdated":1756439877872}}},"AddInputMappings":{"AddInputMappings":{"currentFile":{"count":1,"lastUpdated":1756453435438}}},"AddMappingContext":{"AddMappingContext":{"currentFile":{"count":1,"lastUpdated":1756453441609}}}}
|
@@ -150,11 +150,11 @@ void ULyraHeroComponent::InitializePlayerInput(UInputComponent* PlayerInputCompo
|
|||||||
{
|
{
|
||||||
for (const FInputMappingContextAndPriority& Mapping : DefaultInputMappings)
|
for (const FInputMappingContextAndPriority& Mapping : DefaultInputMappings)
|
||||||
{
|
{
|
||||||
//获取UInputMappingContext并进行注册。
|
|
||||||
if (UInputMappingContext* IMC = Mapping.InputMapping.Get())
|
if (UInputMappingContext* IMC = Mapping.InputMapping.Get())
|
||||||
{
|
{
|
||||||
if (Mapping.bRegisterWithSettings)
|
if (Mapping.bRegisterWithSettings)
|
||||||
{
|
{
|
||||||
|
//将IMC注册给UEnhancedInputUserSettings
|
||||||
if (UEnhancedInputUserSettings* Settings = Subsystem->GetUserSettings())
|
if (UEnhancedInputUserSettings* Settings = Subsystem->GetUserSettings())
|
||||||
{
|
{
|
||||||
Settings->RegisterInputMappingContext(IMC);
|
Settings->RegisterInputMappingContext(IMC);
|
||||||
@@ -163,6 +163,7 @@ void ULyraHeroComponent::InitializePlayerInput(UInputComponent* PlayerInputCompo
|
|||||||
FModifyContextOptions Options = {};
|
FModifyContextOptions Options = {};
|
||||||
Options.bIgnoreAllPressedKeysUntilRelease = false;
|
Options.bIgnoreAllPressedKeysUntilRelease = false;
|
||||||
// Actually add the config to the local player
|
// Actually add the config to the local player
|
||||||
|
//实际添加IMC给LocalPlayer
|
||||||
Subsystem->AddMappingContext(IMC, Mapping.Priority, Options);
|
Subsystem->AddMappingContext(IMC, Mapping.Priority, Options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +212,68 @@ void ULyraHeroComponent::InitializePlayerInput(UInputComponent* PlayerInputCompo
|
|||||||
|
|
||||||
## 步骤
|
## 步骤
|
||||||
1. 假设已经配置好了IMC以及IA。
|
1. 假设已经配置好了IMC以及IA。
|
||||||
1. 在Controller中注册IMC与IA?
|
1. 在Controller/Character中注册IMC与IA?
|
||||||
|
2. AddMappingContext()的选项OptionsNotifyUserSettings设置为true,会调用UEnhancedInputUserSettings::RegisterInputMappingContext()
|
||||||
2. ProjectSettings - Engine - EnhancedInput - UserSettings中的Enable User Settings
|
2. ProjectSettings - Engine - EnhancedInput - UserSettings中的Enable User Settings
|
||||||
3. 配置IA中的UserSetting选项。
|
3. 配置IA中的UserSetting选项。
|
||||||
1.
|
1. 1
|
||||||
|
|
||||||
|
## 加载按键设置逻辑
|
||||||
|
默认自动加载,载入逻辑位于UEnhancedInputUserSettings::LoadOrCreateSettings(),调用顺序是:
|
||||||
|
UEnhancedInputLocalPlayerSubsystem::Initialize
|
||||||
|
->
|
||||||
|
UEnhancedInputLocalPlayerSubsystem::InitalizeUserSettings()
|
||||||
|
->
|
||||||
|
UEnhancedInputUserSettings::LoadOrCreateSettings()
|
||||||
|
|
||||||
|
```c++
|
||||||
|
UEnhancedInputUserSettings* UEnhancedInputUserSettings::LoadOrCreateSettings(ULocalPlayer* LocalPlayer)
|
||||||
|
{
|
||||||
|
UEnhancedInputUserSettings* Settings = nullptr;
|
||||||
|
|
||||||
|
if (!LocalPlayer)
|
||||||
|
{
|
||||||
|
UE_LOG(LogEnhancedInput, Log, TEXT("Unable to determine an owning Local Player for the given Enhanced Player Input object"));
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the save game exists, load it.
|
||||||
|
if (UGameplayStatics::DoesSaveGameExist(UE::EnhancedInput::SETTINGS_SLOT_NAME, LocalPlayer->GetLocalPlayerIndex()))
|
||||||
|
{
|
||||||
|
USaveGame* Slot = UGameplayStatics::LoadGameFromSlot(UE::EnhancedInput::SETTINGS_SLOT_NAME, LocalPlayer->GetLocalPlayerIndex());
|
||||||
|
Settings = Cast<UEnhancedInputUserSettings>(Slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is no settings save game object, then we can create on
|
||||||
|
// based on the class type set in the developer settings
|
||||||
|
const UEnhancedInputDeveloperSettings* DevSettings = GetDefault<UEnhancedInputDeveloperSettings>();
|
||||||
|
UClass* SettingsClass = DevSettings->UserSettingsClass ? DevSettings->UserSettingsClass.Get() : UEnhancedInputUserSettings::StaticClass();
|
||||||
|
|
||||||
|
// This property is marked as "NoClear", so this should be impossible.
|
||||||
|
if (!ensureMsgf(SettingsClass, TEXT("Invalid Enhanced Input User settings class!")))
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_CLOG((Settings && (Settings->GetClass() != SettingsClass)),
|
||||||
|
LogEnhancedInput,
|
||||||
|
Log,
|
||||||
|
TEXT("[%hs] Enhanced Input User Settings class has been changed from '%s' to '%s'. A new settings save object will be created (your saved settings will be reset)"),
|
||||||
|
__func__, *GetNameSafe(Settings->GetClass()), *GetNameSafe(SettingsClass));
|
||||||
|
|
||||||
|
// If the settings are null (they dont exist yet) or the class has changed, we need to create a new object.
|
||||||
|
// The class can change if you modify it in the editor to be something else
|
||||||
|
if (Settings == nullptr || (Settings->GetClass() != SettingsClass))
|
||||||
|
{
|
||||||
|
Settings = Cast<UEnhancedInputUserSettings>(UGameplayStatics::CreateSaveGameObject(SettingsClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ensure(Settings))
|
||||||
|
{
|
||||||
|
Settings->Initialize(LocalPlayer);
|
||||||
|
Settings->ApplySettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Settings;
|
||||||
|
}
|
||||||
|
```
|
Reference in New Issue
Block a user