- Home /
Can I use my own input device?
Hi,
My problem seems fairly simple. I am a research student at a Lab, and this lab has developed a haptic 3d input device. Naturally I am to do something with this device and Unity. I have DLLs to use in C# (using PInvoke).
So would it be possible to use both the device as a pointing device (like a 3D mouse) and an haptic device (force feedback) if I was to buy the Pro version of Unity? Can you add your own input device into unity?
Answer by Cyclops · May 21, 2010 at 01:45 PM
Yes you can, provided A) you have Pro (which can use Plugins, and B) the project is a stand-alone executable (browsers have security limitations).
Here's a similar Question where I listed some sample code that might make it more clear: How to import Neurosky Mindset data into Unity
On second thought, that code might be misleading - Neurosky provides some boilerplate code in a C# file, that is required to call the .dll. If you are starting from scratch, you would have to write code to use the Plugin that looks something like this:
// This tells unity to look up the function FooPluginFunction inside the plugin named "PluginName"
[DllImport ("PluginName")]
private static extern float FooPluginFunction ();
And you can download Unity Pro Trial. The trial version is only valid for 30 days, but if this is a short, one-time project, that might be enough to complete it.
Answer by Greg 4 · Dec 16, 2010 at 03:10 PM
... A follow on...
I also am trying to link in a haptic device... I have it running on Android through bluetooth and windows through c/c++/and c# dlls
I understand that I should be able to get this running no problem with windows, but what about android or iphone?
Will Unity allow my code to connect to a bluetooth device and send and recieve packets?
If not could I do it if the device has an IP address with udp/tcp?
Answer by Texhas · Jan 20, 2011 at 09:39 PM
I have been able to call a objective-c dll from C# scripts thanks to the info you provided. However, I wish to receive callbacks from my C++ dll. I thought of using a delegate to catch the callbacks as I have done before, but I get errors saying I'm trying to JIT compile my delegate. Is there a way to get callbacks from a dll in unity?
Answer by ferraribeng · Jul 14, 2011 at 06:22 AM
Hi, sorry to budge in with another question relating to "using my own input device". I am using a 3D input device, which I believe is similar to haptic, posted by simaldeff. I have the DDL in the plugin folder. I was able to read the data from the input device using the DLL API.
I am now experiencing this problem. When I move the device, the data I read and displayed using Debug.Log, lagged by about 1 second. This is not good because whatever I want to animate in Unity cannot respond to me instantanteously. I have no idea what causes the lagging.
I wrote another program in C++ to read the data from the same DLL and display it. Interestingly, there is no lagging at all. Seem like the problem is interaction between Unity and the DLL.
I have been looking through the forum for anyone with similar problem and any advice and pointers will be deeply appreciated. Thanks.
I resolve the problem by editing the DLL (in c++) to have a thread that read the data from the device continuously and process it to the format I want to use in Unity. I have another method to allow Unity to call and read the processed data. In this way, I don't get the lagging anymore.
Your answer
Follow this Question
Related Questions
XInputDotNetPure plugin: Namespace could not be found. 1 Answer
How to call a custom object from a C# dll 1 Answer
Why does my 32-bit dll plugin(c++) work in Unity 4 and not in Unity 5 indy (Windows 32-bit editor) 0 Answers
Cant link PLUGIN.DLL with PLUGIN-EDITOR.DLL 1 Answer
Unity plugins 0 Answers