UE4 轴映射和操作映射的区别|随笔

UE

APlayerController :: class UPlayerInput   PlayerInput 变量中有

一个 AxisMapping变量  里面便是存储  该PlayerController中的轴映射集合

轴映射:

在struct FInputAxisKeyMapping 有

FName AxisName;     //轴映射名
float Scale;                //按键轴值
FKey Key;                //按键按钮

轴映射

每帧运行 ,按键按下时会发送 Scale 值  不按按键时发送的Scale值为0;

我们打开UE编辑器  编辑 》项目设置 》输入

现在我们来看轴映射  那个缩放值  便是 FInputAxisKeyMapping::Scale 值

另外两个也是在此设置的   FName AxisName;     //轴映射名   FKey Key;                //按键按钮

行了   我们在角色蓝图里添加

现在运行游戏

注意画线红框里的值

我们先按 M 键

看 -5 吧  在上面设置轴映射时 Scale 为-5.0 

现在按 N 键 看看  记得N键的轴映射 Scale值 为 9.0

看看没有按这两个按键时

值是 0.0  记住轴映射是每帧执行的

现在我们去VS中 打断点 PlayerTick函数

来看看this指针里的PlayerInput -> AxisMapping中存储的是啥

这可能有点不好分析  我们就只看  映射名为 Tel 的两个按键  M N

看 Scale值  是不是就是我们在编辑器里面设置的?

我们来看看角色蓝图里存储这个Tel映射时的位置

在AActor::class UInputComponent  InputComponent 变量中 

FInputAxisBinding 集合 、AxisBindings的变量中  

 

看存储在此  注意这个角色类中的 AActor::InputComponent中

也就是 我们如果要使用代码的添加 轴映射的话  

先需要 在PlayerController中的 APlayerController :: class UPlayerInput   PlayerInput 

 TArray<struct FInputAxisKeyMapping> AxisMappings 里添加一个FInputAxisKeyMapping元素

然后再在需要使用按键轴的 AActor类或子类 中的

AActor::class UInputComponent InputComponent

TArray<FInputAxisBinding> AxisBindings; 中添加一个 FInputAxisBinding 元素

注意轴映射名要一致

既然都说到

AActor::class UInputComponent InputComponent;

那我们来说说 

/** The collection of key bindings. */
TArray<FInputKeyBinding> KeyBindings;

//存使用的操作单按键,按键事件( 按下 抬起 )与调用函数的地方 这个是直接使用按键事件 不需要映射

/** The collection of axis bindings. */
TArray<FInputAxisBinding> AxisBindings; 

//存使用的轴映射名与调用函数的地方  这个需要在玩家控制器中的PlayerInput -> AxisMappings 有对应映射

/** The collection of axis key bindings. */
TArray<FInputAxisKeyBinding> AxisKeyBindings;

//存使用的轴单按键与调用函数的地方 这个是直接使用按键 不需要映射

/** Holds the collection of action bindings. */
TArray<TSharedPtr<FInputActionBinding>> ActionBindings;

//存使用的操作映射名,按键事件(按下 抬起)与调用函数的地方 这个需要在玩家控制器中的PlayerInput ->  ActionMappings; 有对应映射

/** The collection of vector axis bindings. */
TArray<FInputVectorAxisBinding> VectorAxisBindings;

//存使用的轴单按键与调用函数的地方 这个是直接使用按键 不需要映射  不过这个绑定的函数参数是 一个FVector类型  不过这里好像只有鼠标2D轴

首先 AxisBindings;  我们已经在上述说过了

就是存使用的轴映射名与调用函数的地方

我们现在来看看

TArray<FInputKeyBinding> KeyBindings;存的究竟是啥

我们去角色蓝图里面直接使用一个操作按键

然后进入VS去看看我们所使用的角色类中 AActor::class UInputComponent InputComponent;

TArray<FInputKeyBinding> KeyBindings;

注意打断点  在Tick函数里面打

图中 1便是 按键事件的按下  2便是 按键事件的抬起  横线便是 按键按钮

右边的选项在 FInputKeyBinding 里也是有对应项的

现在来说说 TArray<FInputAxisKeyBinding> AxisKeyBindings;

这个也是每帧调用的  注意鼠标2D轴的那个 他是存在中的

/** The collection of vector axis bindings. */
TArray<FInputVectorAxisBinding> VectorAxisBindings;

记住  轴   每帧运行

操作映射:

有按下和抬起 等按键事件的概念  按键事件发生时  才开始运行绑定的函数

如 按下触发  抬起触发

TArray<TSharedPtr<FInputActionBinding>> ActionBindings;

在编辑器中

我们先去PlayerController里看看 PlayerController :: class UPlayerInput* PlayerInput;

   /** This player's version of the Action Mappings */
TArray<struct FInputActionKeyMapping> ActionMappings; 中

看刚刚在编辑器里  UE编辑器  编辑 》项目设置 》输入 中添加的操作映射 14723 就被添加到此

按键是U bShift是 true 但是 这里并储存没有按键事件 

再去看看 角色类里的 AActor:: class UInputComponent* InputComponent;

TArray<TSharedPtr<FInputActionBinding>> ActionBindings;

这个位置 并没有保存 具体键钮  而是只有  映射名 与调用函数 按键事件  同一个14723映射存有两个  一个按键事件是按下  一个按键事件是抬起

行了 说完了

总结

轴映射  是每帧运行绑定函数 

操作映射 是按键事件触发时才运行绑定函数

  • 12
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值