虚幻引擎-如何通过C++;代码 我对虚幻的引擎和C++……p>
我正在尝试获取轴的指定关键点。我发现信息存储在DefaultInput.ini文件中,但如何以编程方式访问这些数据 有一个GetAxisValue(const FName)方法,但它不返回任何内容虚幻引擎-如何通过C++;代码 我对虚幻的引擎和C++……p>,c++,unreal-engine4,C++,Unreal Engine4,我正在尝试获取轴的指定关键点。我发现信息存储在DefaultInput.ini文件中,但如何以编程方式访问这些数据 有一个GetAxisValue(const FName)方法,但它不返回任何内容 FString AxisName = "MoveForward"; auto value = PlayerInputComponent->GetAxisValue(FName(*AxisName)); 我做错了什么?我真的很感谢你的帮助。我不确定,因为我大部分时间都使用蓝图,但是获取值的一种方
FString AxisName = "MoveForward";
auto value = PlayerInputComponent->GetAxisValue(FName(*AxisName));
我做错了什么?我真的很感谢你的帮助。我不确定,因为我大部分时间都使用蓝图,但是获取值的一种方法是将它绑定到一个方法 (AFPSCharacter模板示例) 然后在方法中使用它
void AFPSCharacter::MoveForward(float Value){
//for example print the val
UE_LOG(LogTemp, Warning, TEXT("%f"), Value);
}
这也是我的第一个想法,但不幸的是,您无法获得键,您只需将该方法绑定到一个axis名称。向前移动的“值”参数保留比例值,但不保留键值。1.0f,例如按“W”时,或按“S”时-1.0f 我已经找到了解决问题的办法。GetAxisValue(FName)是用于此目的的错误方法 相反,我找到了包含名为GetAxisMappingByName(FName,TArray)的方法的UInputSettings类 下面是它的工作原理代码片段:
// Get the instance of the InputSettings
UInputSettings* InputSettings = UInputSettings::GetInputSettings();
// AxisMappings with all the information will be stored here
TArray<FInputAxisKeyMapping> VerticalKeys;
TArray<FInputAxisKeyMapping> HorizontalKeys;
// Load the AxisMappings
InputSettings->GetAxisMappingByName(FName("MoveForward"), VerticalKeys);
InputSettings->GetAxisMappingByName(FName("MoveRight"), HorizontalKeys);
// Each MovementKey gets its own variable
FKey ForwardKey;
FKey BackKey;
FKey LeftKey;
FKey RightKey;
// Assign each key to the correct direction
for (FInputAxisKeyMapping verticalKey : VerticalKeys)
{
if (verticalKey.Scale == 1.0f)
ForwardKey = verticalKey.Key;
else if (verticalKey.Scale == -1.0f)
BackKey = verticalKey.Key;
}
for (FInputAxisKeyMapping horizontalKey : HorizontalKeys)
{
if (horizontalKey.Scale == 1.0f)
RightKey = horizontalKey.Key;
else if (horizontalKey.Scale == -1.0f)
LeftKey = horizontalKey.Key;
}
//获取InputSettings的实例
UIInputSettings*InputSettings=UIInputSettings::GetInputSettings();
//包含所有信息的AxisMappings将存储在此处
跗骨垂直键;
柏油树;
//加载AxisMappings
InputSettings->GetAxisMappingByName(FName(“前进”),垂直键);
InputSettings->GetAxisMappingByName(FName(“MoveRight”)、HorizontalKeys;
//每个MovementKey都有自己的变量
FKey-ForwardKey;
FKey BackKey;
FKey LeftKey;
FKey RightKey;
//将每个键分配到正确的方向
用于(FInputAxisKeyMapping verticalKey:VerticalKeys)
{
如果(verticalKey.Scale==1.0f)
ForwardKey=垂直键。键;
否则如果(verticalKey.Scale==-1.0f)
BackKey=verticalKey.Key;
}
用于(FInputAxisKeyMapping horizontalKey:HorizontalKeys)
{
如果(horizontalKey.Scale==1.0f)
RightKey=horizontalKey.Key;
否则如果(horizontalKey.Scale==-1.0f)
LeftKey=horizontalKey.Key;
}
有没有比使用for循环更好的方法来分配关键点?请随意修改我的代码,因为我不是C++的专家。p>
// Get the instance of the InputSettings
UInputSettings* InputSettings = UInputSettings::GetInputSettings();
// AxisMappings with all the information will be stored here
TArray<FInputAxisKeyMapping> VerticalKeys;
TArray<FInputAxisKeyMapping> HorizontalKeys;
// Load the AxisMappings
InputSettings->GetAxisMappingByName(FName("MoveForward"), VerticalKeys);
InputSettings->GetAxisMappingByName(FName("MoveRight"), HorizontalKeys);
// Each MovementKey gets its own variable
FKey ForwardKey;
FKey BackKey;
FKey LeftKey;
FKey RightKey;
// Assign each key to the correct direction
for (FInputAxisKeyMapping verticalKey : VerticalKeys)
{
if (verticalKey.Scale == 1.0f)
ForwardKey = verticalKey.Key;
else if (verticalKey.Scale == -1.0f)
BackKey = verticalKey.Key;
}
for (FInputAxisKeyMapping horizontalKey : HorizontalKeys)
{
if (horizontalKey.Scale == 1.0f)
RightKey = horizontalKey.Key;
else if (horizontalKey.Scale == -1.0f)
LeftKey = horizontalKey.Key;
}