Skip to content

A small script to detect runtime input device change for Unity Input System.

License

Notifications You must be signed in to change notification settings

RYanXuDev/InputDeviceDetector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

InputDeviceDetector

This small script is design for multiple input devices supporting, use it to detect the runtime switch between input devices for Unity Input System.

How To Use

  1. Import the package to your project.
  2. Simply drag the "Input Device Detector" prefab in the Prefab folder into your scene.
  3. Use the event triggers to register device switch functions.
  4. For adding listener for the input device switch event in your script, first using the namespace InputDeviceDetection, then call AddListener() of the event.
  5. If you only need to detect the UI input devices, check the "Detect UI Input Only";
  6. There are two convenient static method (InputDeviceDetector.ShowCursor()/HideCursor()) for showing/hiding the cursor.

Currently this script support mouse, keyboard and gamepad detection. You may add any other devices that Unity Input System supported in the InputDeviceDetector.cs script.


You are free to credit me or not. If you wish to do this, use this link below,thanks:

RyanIndieDev - YouTube channel: https://www.youtube.com/channel/UCSRCf2y6LV8vpKSoXDoU2VQ

===========================================================================

输入设备检测器

本脚本为支持多种输入设备而设计,当使用Unity的Input System时,可使用本脚本来检测游戏运行时不同输入设备之间的实时切换。

如何使用

  1. 将安装包导入到项目中。
  2. 将Prefab文件夹中的 Input Device Detector 预制体拖到场景中。
  3. 使用脚本的事件触发器来登记设备切换时所需要触发的功能。
  4. 如果需要在脚本中为输入设备切换事件添加监听函数,请先添加InputDeviceDetection命名空间,然后调用设备切换事件的AddListener()函数来登记功能。
  5. 如果您只需要检测UI输入设备的切换,请勾选"Detect UI Input Only"选项。
  6. 脚本中有两个方便的静态函数(InputDeviceDetector.ShowCursor()/HideCursor())用来切换光标的显示/隐藏。

本脚本目前支持鼠标、键盘和游戏手柄检测。 您可以在InputDeviceDetector.cs脚本中添加Unity输入系统支持的任何其他设备。


欢迎使用本脚本,如果您想在您的作品中提到我,请使用下面的链接,感谢您:

RyanIndieDev-YouTube频道: https://www.youtube.com/channel/UCSRCf2y6LV8vpKSoXDoU2VQ

阿严_独立游戏开发-B站: https://space.bilibili.com/27164588/

About

A small script to detect runtime input device change for Unity Input System.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages