【Unity】新InputSystem中点按UI组件模拟键盘输入

项目中用空格作为对话的交互键,想要实现对话时点按UI中的panel和空格有一样的效果。

文档中创建event并传入的方法:

原文地址:Input events | Input System | 1.3.0 

第二个方法第二个参数搞不懂应该传入什么,第一个成功。

using (StateEvent.From(Keyboard.current, out var eventPtr))
            {
                (Keyboard.current.spaceKey).WriteValueIntoEvent(1f, eventPtr);
                InputSystem.QueueEvent(eventPtr);
            }

 上段实现了按下,实测后发现会一直保持值不变,所以需要再恢复,这里其实我没找到value的范围和实际的含义,我自己的理解是1按下0抬起。结合IPointerDownHandler和 IPointerUpHandler两个接口,在按下和抬起时传入相应的事件;

public void OnPointerDown(PointerEventData eventData)
        {
            using (StateEvent.From(Keyboard.current, out var eventPtr))
            {
                (Keyboard.current.spaceKey).WriteValueIntoEvent(1f, eventPtr);
                InputSystem.QueueEvent(eventPtr);
            }
        }

        public void OnPointerUp(PointerEventData eventData)
        {
            using (StateEvent.From(Keyboard.current, out var eventPtr))
            {
                (Keyboard.current.spaceKey).WriteValueIntoEvent(0f, eventPtr);
                InputSystem.QueueEvent(eventPtr);
            }
        }

 可以完美模拟按下空格的效果,按住不放可以保持按下状态。

关于value的实际定义和第二个方法的实现,希望有大佬能教教ヾ(✿゚▽゚)ノ。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Overview NGUI is a powerful UI system and event notification framework for Unity (both Pro and Free) written in C# that closely follows the KISS principle. It features clean code and simple, minimalistic approach to everything. Many behaviour classes are kept under 200 lines of code. For a programmer this means a much easier time when it comes to working with the kit — from extending its functionality to tweaking the existing one. For everyone else this means better performance, less frustration, and more fun. Features Full Inspector integration No need to hit Play to see the results What you see in the Scene view is what you get in the Game view (fully WYSIWYG) Component-based, modular nature: attach the behaviours you want to make your widgets do what you want without having to code. Full support for iOS/Android, Blackberry, Win8, WP8, Flash Flexible event system Make complex UIs that take only 1 draw call Create your atlases right in the editor, update/modify them at will, or import an atlas from the Texture Packer. Support for lighting, normal mapping, refraction, and more — unleash your creativity! Support for clipped panels with hard or soft edges. Support for a flexible size table, letting your widgets automatically push others out of the way. Support for eastern languages with IME input Built-in Localization system Built-in keyboard and controller support An assortment of useful scripts to help you — from changing a button color to dragging an object Simple built-in tweening system. Clean, short, simple and extensively optimized C# code No DLLs or external resources
The powerful, top-rated dialogue system used in Disco Elysium, Crossing Souls, Jenny LeClue, Last Epoch, The Last Door, and many many more, the Dialogue System for Unity makes it easy to add interactive dialogue and quests to your game. It’s a complete, robust solution including a visual node-based editor, dialogue UIs, cutscenes, quest logs, save/load, and more. The core is a lean, efficient conversation system. A large collection of included, optional add-ons make it quick and easy to drop conversations into your project and integrate them with other assets. No scripting required. Complete C# source included. Demo | Docs | Tutorials | Forum Free Extras | Free Trial Cinemachine & Timeline Integration! Editor: Visual, node-based dialogue editor Importers for Chat Mapper, articy:draft 1/2/3, Twine, Ink, Neverwinter Nights, Talkit, and CSV Export screenplay format, voiceover asset list, CSV, Chat Mapper, and more I2 Localization support Engine: Dynamic, branching conversation trees Barks and alerts Cutscenes (audio, animation, etc.) Quick Time Events (QTEs) Quest system NPC status & relationship system Easy language localization Save/load without scripting Optional Lua scripting and variable system Comprehensive documentation and tutorials Runtime UIs: GUI-independent; works with all GUI systems, including Unity UI & NGUI Built-in support for Unity UI, NGUI, TextMesh Pro, legacy Unity GUI, & more Input system-independent; works with Unity Input, Rewired, New Input System, etc Modular interfaces: swap in your own UI or cutscene system Several beautiful, fully-customizable UI skins Detailed sci-fi environment & animated model Works in 2D and 3D Works in VR (Oculus Rift, Vive, GVR, etc.) Integration: Components for drop-in integration into existing frameworks Cinemachine & Timeline Action-RPG Starter Kit Adventure Creator Animator Timeline Editor articy:draft Behavior Designer Bolt Visual Scripting

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值