Exemplo n.º 1
0
bool UInputBlueprintLibrary::K2_RebindAxisKey(FValorAxisInputBinding OriginalBinding, FValorAxisInputBinding NewBinding)
{
	UInputSettings* Settings = const_cast<UInputSettings*>(GetDefault<UInputSettings>());
	if (!Settings)
	{
		return false;
	}

	TArray<FInputAxisKeyMapping>& AxisMappings = Settings->AxisMappings;

	bool bFound = false;
	for (FInputAxisKeyMapping& AxisKeyMapping : AxisMappings)
	{
		if (AxisKeyMapping.AxisName.ToString() == OriginalBinding.AxisName && AxisKeyMapping.Key == OriginalBinding.Key)
		{
			UpdateAxisMapping(AxisKeyMapping, NewBinding);
			bFound = true;
			break;
		}
	}

	if (bFound)
	{
		const_cast<UInputSettings*>(Settings)->SaveKeyMappings();

		for (TObjectIterator<UPlayerInput> It; It; ++It)
		{
			It->ForceRebuildingKeyMaps(true);
		}
	}
	return bFound;
}
Exemplo n.º 2
0
void UInputBlueprintLibrary::K2_RemoveAxisKeyBinding(FValorAxisInputBinding BindingToRemove)
{
	UInputSettings* Settings = GetMutableDefault<UInputSettings>();
	if (!Settings)
	{
		return;
	}

	TArray<FInputAxisKeyMapping>& AxisMappings = Settings->AxisMappings;

	bool bFound = false;
	for (int32 Index = 0; Index < AxisMappings.Num(); ++Index)
	{
		if (AxisMappings[Index].Key == BindingToRemove.Key)
		{
			bFound = true;
			AxisMappings.RemoveAt(Index);
			Index = 0;
		}
	}

	if (bFound)
	{
		Settings->SaveKeyMappings();

		for (TObjectIterator<UPlayerInput> It; It; ++It)
		{
			It->ForceRebuildingKeyMaps(true);
		}
	}
}