当前位置: 首页 > news >正文

虚幻引擎5:增强输入的使用方法

一、基本配置 

1.创建一个输入映射上下文(映射表)

2.创建自己需要的操作映射或者轴映射

3.创建完成之后进入这个映射,来设置类型,共有4个类型 

1.Digital:是旧版操作映射类型,一般是按下抬起来使用,像跳跃,之类的

2.剩余三个都是轴映射类型,Axis1D:单向轴,一般是油门按键,摇杆之类的

3.Axis2D:有x,y两个方向,2D轴,一般是移动之类的

4.Axis3D:有x,y,z三个方向

4.将设置的映射添加至上下文中

1.操作映射的配置就添加个按键直接使用就好了

2.轴映射的配置

5.然后设置对应的按键。基本设置就完成了

二、使用方法 

然后我这边选择使用C++来使用

1.在使用此配置的角色类中引入按键映射mapping

//头文件代码
UPROPERTY(EditAnywhere)//此标记可以在蓝图中导入映射资产
class UInputMappingContext*MappingContext;
UPROPERTY(EditAnywhere)
class UInputAction * JumpAction;//跳跃事件的action
UPROPERTY(EditAnywhere)
UInputAction * MoveAction;//移动事件的action
virtual void BeginPlay() override;
virtual void ALGPlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
//轴映射移动绑定的函数,必须带有一下参数格式必须一致
void Move(const FInputActionValue& Value);//cpp文件代码
//按键操作一般在beginplay中执行
void ALGPlayerCharacter::BeginPlay()
{Super::BeginPlay();//判断一下资产是否添加,否则UE会崩溃if(MappingContext){//因为按键是在角色身上执行的,所以需要找到角色控制器if (APlayerController* PC = Cast<APlayerController>(GetController())){//通过角色控制找到增强输入子系统
UEnhancedInputLocalPlayerSubsystem*Subsystem=ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer());//将映射表添加至系统中Subsystem->AddMappingContext(MappingContext,0);}}
}void ALGPlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);
//使用了增强输入后,旧的输入控件就无法使用,必须使用新的if(UEnhancedInputComponent*EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent)){//跳跃事件的绑定EnhancedInputComponent->BindAction(JumpAction,ETriggerEvent::Started,this,&ALGPlayerCharacter::DoJump);//移动事件的绑定EnhancedInputComponent->BindAction(MoveAction,ETriggerEvent::Triggered,this,&ALGPlayerCharacter::Move);}
}//绑定的移动事件
void ALGPlayerCharacter::Move(const FInputActionValue& Value)
{获取绑定事件给出的轴值FVector2D InputValue = Value.Get<FVector2D>();UE_LOG(LogTemp, Log, TEXT("ok%s"),*InputValue.ToString())//前后移动AddMovementInput(GetActorForwardVector(), InputValue.Y);//左右移动AddMovementInput(GetActorRightVector(), InputValue.X);
}

http://www.lryc.cn/news/191665.html

相关文章:

  • buffer overflow detected
  • 【c++源码】老飞飞源码完整v15源码(包含数据库前端后端源文件)
  • MySQL创建数据库、创建表操作和用户权限
  • 时间序列分析基础篇
  • Idea JavaWeb项目,继承自HttpFilter的过滤器,启动Tomcat时部署工件出错
  • 02Maven核心程序的下载与settings.xml文件的配置,环境变量的配置
  • 栈实现深度优先搜索
  • Java 基于SpringBoot的某家乡美食系统
  • splice 和 slice 会改变原数组吗? 怎么删除数组最后一个元素?
  • 解锁互联网安全的新钥匙:JWT(JSON Web Token)
  • alsa音频pcm设备之i2c调试
  • 1. Windows平台下如何编译C++版本的Redis库hiredis
  • Centos中利用自带的定时器Crontab_实现mysql数据库自动备份_linux中mysql自动备份脚本---Linux运维工作笔记056
  • 完美解决Android adb install 安装提示 INSTALL_FAILED_TEST_ONLY
  • [清华大学]漏洞挖掘之状态敏感的模糊测试StateFuzz
  • 嵌入式养成计划-40----C++菱形继承--虚继承--多态--模板--异常
  • C++入门指南:类和对象总结友元类笔记(下)
  • ctfshow web入门 php特性 web136-web140
  • sshpass传输文件提示Host key verification failed.
  • Maven系列第5篇:私服详解
  • 深入解析Spring Cloud Gateway的GlobalFilter
  • ffmpeg的重采样计算
  • Go HTTP 调用(上)
  • STM32Cube高效开发教程<基础篇>(一)----概述
  • 汽车RNC主动降噪算法DSP C程序实现
  • Java21虚拟线程完整用法
  • Vue 中的 nextTick 方法
  • TypeScript React(上)
  • Linux 安全 - LSM源码分析
  • 第一次汇报相关问题