Unity新(Input System)老(Input Manager)输入系统代码对比

这篇具有很好参考价值的文章主要介绍了Unity新(Input System)老(Input Manager)输入系统代码对比。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

以下介绍都是基于Unity2022版本

一、键盘操作

当w键按下时

//Old
        if (Input.GetKeyDown(KeyCode.W)) DoSomething();
//New
        if(Keyboard.current.wKey.wasPressedThisFrame) DoSomething();

当w键抬起时

//Old
        if (Input.GetKeyUp(KeyCode.W)) DoSomething();
//New  
        if (Keyboard.current.wKey.wasReleasedThisFrame) DoSomething();

当w键按着时

//Old
        if (Input.GetKey(KeyCode.W)) DoSomething();
//New
        if (Keyboard.current.wKey.ReadValue() > 0.5f) DoSomething();

二、鼠标操作

获取鼠标位置

//Old
        Vector3 mousePos = Input.mousePosition;
//New
        mousePos = Mouse.current.position.ReadValue();

获取鼠标滚轮

//Old
        float scroll = Input.GetAxis("Scroll Wheel");
//New
        scroll = Mouse.current.scroll.ReadValue().y;

获取鼠标左键按下

//Old
        if (Input.GetMouseButtonDown(0)) DoSomething();
//New
        if (Mouse.current.leftButton.wasPressedThisFrame) DoSomething();

获取鼠标右键抬起

//Old
        if (Input.GetMouseButtonUp(1)) DoSomething();
//New
        if (Mouse.current.rightButton.wasReleasedThisFrame) DoSomething();

获取鼠标中间按着文章来源地址https://www.toymoban.com/news/detail-597312.html

//Old
        if (Input.GetMouseButton(2)) DoSomething();
//New
        if (Mouse.current.middleButton.ReadValue() > 0.5f) DoSomething();

到了这里,关于Unity新(Input System)老(Input Manager)输入系统代码对比的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • 【Unity_Input System】Input System新输入系统(二)

    【Unity_Input System】Input System新输入系统(二)

    目录 六、Action Phase 七、Input Action Asset文件 1.Bindings Mode  1Binding 2PositiveNegative Binding 3UpDownLeftRight Composite 4UpDownLeftRightForwardBackward Composite 5Binding with one modifier 6Binding with two modifier 2.Binding Path 3.Action Type 4.Initial State Check 5.Interaction 1Default Interaction 2Press Interaction 3Hold Inter

    2024年02月03日
    浏览(18)
  • 第五十二章 Unity Input System 新输入系统

    第五十二章 Unity Input System 新输入系统

    新输入系统InputSystem是2019年Unity新推出的插件。请注意,Unity默认使用旧的Input Manager,新的Input System处于未启用状态。当你安装Input System组件时,Unity会询问你是否启用新的输入系统。如果你选择Yes,Unity会启用新的并禁用旧的,之后编辑器将重新启动。具体的操作是,打开包

    2024年02月07日
    浏览(12)
  • 【Unity_Input System】Input System新输入系统(三)——在游戏中更换按键绑定

    【Unity_Input System】Input System新输入系统(三)——在游戏中更换按键绑定

    Binding只由一个部分组成,一般绑定单个按键或者摇杆 CompositeBinding由两个以上部分组成,一般是用于将多个按键组成虚拟轴 更换按键绑定时,Binding和Composite Binding需要分别处理,对Composite Binding需要循环各个部分进行修改。 可以用InputBinding.isComposite来判断是否是Composite Bind

    2024年02月04日
    浏览(17)
  • Unity VR:XR Interaction Toolkit 输入系统(Input System):获取手柄的输入

    Unity VR:XR Interaction Toolkit 输入系统(Input System):获取手柄的输入

    输入系统是 VR 应用中非常重要的一部分。我们通常需要获取 VR 手柄上某个按键的输入,然后将其作用到应用中,比如按下手柄的 Grip 键进行抓取。在我的其他 Unity XR Interaction Toolkit 的开发教程里,已经有介绍如何去获取手柄的输入。那么这篇教程我将做一个总结,将相关的

    2024年02月12日
    浏览(13)
  • Unity New Input System 及其系统结构和源码浅析【Unity学习笔记·第十二】

    Unity New Input System 及其系统结构和源码浅析【Unity学习笔记·第十二】

    转载请注明出处:🔗https://blog.csdn.net/weixin_44013533/article/details/132534422 作者:CSDN@|Ringleader| 主要参考: 官方文档:Unity官方Input System手册与API 官方测试用例:Unity-Technologies/InputSystem 如果c#的委托和事件不了解,参考我这篇:【C#学习笔记】委托与事件 (从观察者模式看C#的委

    2024年01月25日
    浏览(12)
  • 【Unity入门计划】基本概念(7)-Input Manager&Input类

    【Unity入门计划】基本概念(7)-Input Manager&Input类

    目录 1 Input Manager-Controls 控件 1.1 Key 键 1.2 Button 按钮 1.3 Virtual Axis 虚拟轴(复数:Axels) Name 名称 Ngative Button, Positive Button 负/正值键(按钮) 2 C#中的Input类 2.1 键盘的输入(获取键盘事件) Input.GetKey(string KeyName) Input.GetKeyDown(string KeyName) Input.GetKeyUp(string KeyName) 2.2 鼠标的输入(获取

    2024年02月08日
    浏览(34)
  • Unity SteamVR 开发教程:SteamVR Input 输入系统(2.x 以上版本)

    Unity SteamVR 开发教程:SteamVR Input 输入系统(2.x 以上版本)

    输入系统是 VR 开发中非常重要的一部分。我们通常需要获取 VR 手柄上某个按键的输入,然后将其作用到应用中,比如按下手柄的 Grip 键进行抓取,就需要在检测到“按下手柄 Grip 键”的输入操作时,执行抓取的行为。 SteamVR 插件是 Valve 提供给 Unity 开发者的用于开发 PCVR (头

    2024年02月08日
    浏览(12)
  • Unity 3D Input System的使用

    Unity 3D Input System的使用

    Input System是Unity新推出的输入系统,可以用作以前Input Manager的更具扩展性和可自定义性的替代方案。这里我将使用Unity 3D的Input System来实现一个FPS第一人称的游戏场景。 演示效果如下: 新建一个Unity 3D项目,在Asset Store里面下载StarterAssets - FirstPerson,然后在Package Manager里面导

    2024年02月20日
    浏览(12)
  • 【Unity学习笔记】New Input System 部分源码和测试用例补充

    【Unity学习笔记】New Input System 部分源码和测试用例补充

    转载请注明出处:🔗https://blog.csdn.net/weixin_44013533/article/details/135630016 作者:CSDN@|Ringleader| 主要参考: Unity官方Input System手册与API 【Unity学习笔记】Unity TestRunner使用 NewIputSystem主体内容请参见:【Unity学习笔记】第十二 · New Input System 及其系统结构 和 源码浅析 注:本文使用的

    2024年01月22日
    浏览(25)
  • Unity基础篇-----Input输入

    此篇为个人对此部分所掌握知识的理解,如有错误的地方请谅解!,后续会对此部分知识进行进一步完善。 在程序中输入系统是必不可缺的,这部分知识也是我们必须需要掌握的,在Unity使用Input类来读取传统游戏中输入的轴,下面我们对Unity Input类中会常用到的函数及变量进

    2024年04月25日
    浏览(6)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包