RobW81
1
I have been looking around trying to find any info on making a plugin or a .Net library that will allow me to use a custom piece of hardware through the input manager. What I want to do is take, say a head tracker and write some code to make it compatible with the input manager.
The goal is write one line of code to control the camera rotations based on the input manager. This will allow me setup the input manager so I can use the mouse, the arrows or the head tracker to rotate the camera. The benefit to this is if someone doesn’t have a head tracker they can use the mouse to rotate the camera and I don’t have to write special conditions to check if the hardware is present.
Is there way to write a plugin or library that follows some set of rules to be compatible with the input manager? All of the tracking devices out there have APIs to make it easy to use in a library or a plugin but I can’t find anything about making it usable through the input manager. I would really like find out if this is possible because it can save time prototyping new hardware and eliminate special hardware logic.
Unity does not currently provide a way to create a custom input device. I’ve added a feature request in the Wishlist/Feedback, but it doesn’t have very many votes. I think this feature is a huge weak spot that reduces Unity’s candidacy as a development platform in markets that don’t exactly fit into the same mold as commercial video games.
Here’s a link to the Wishlist. Please upvote!
Expose Input system for custom devices
Hardware that the OS does not see as a game input device (joystick/gamepad), a keyboard, or a mouse will not be “seen” by the Unity Input Manager and will require a plugin. My suggestion would be to create an event system that will send out input changes from all relevant devices and have your object subscribe to that event. Or, you could wrap all valid input devices with a single class which would do its own polling, and then have your object poll that class.
Depending on how much time you have for development, a custom driver could probably be created to make your input device look like a game controller at the OS level. Unity would then likely treat it as any other joystick device.
If it’s a HID device you can use GitHub - mikeobrien/HidLibrary: This library enables you to enumerate and communicate with Hid compatible USB devices in .NET. . I tried this for GriffinPowermatUsb and found it works, but locks up the Unity3D editor. It may work fine for builds.
I ended up using AutoHotKey with this script AHKHID - An AHK implementation of the HID functions - Scripts and Functions - AutoHotkey Community It requires installing additional software on the machine.