The Unity Multi Touch Source (finally)

Hey Everybody

Here is the source for the CPP and C# files needed to implement the Multi Touch Plugin DLL referred to in the previous post. Sorry it took so long to publish. Just download the zip and they're both there. I've also uploaded Touchtest.zip which is a very bad Unity app which uses the plugin - seriously - it’s just an empty app which talks to the plugin and displays the touch info on screen. Tested on win7 and win8 desktop, although there are a million combinations of touch screen and OS / Driver etc & so I haven’t tried them all, so its uploaded as-is;and I make no guarentees about running correctly. I also make no guarantees about the exe itself - I scanned it before uploading but - as always - scan before you run!

DLLMain.cpp is the complete source for the plugin.dll. There have been a couple of small changes since the original blog, including changing it to receive a WCHAR array from unity instead of a char * for the name of the window. This seems to be something that’s changed in Unity 4.x - haven't investigated why exactly. This took a bit of finding, and probably explains why some people had problems making it work at the final hurdle.

Check1.cs is the Unity script which you will attach to either your landscape or camera - whatever - to call the plugin.  Beyond that its fairly easy to build and use.

Here is what I did to build and debug it.

  1. Create a new VisualStudio 2008 project (I think it works on 2010 too).  You want a DLL.
  2. Add the DLLMain.cpp file as the only source file.  No additional includes, no extra libs.
  3. Change the Output Directory in Configuration Properties/General in the Properties dialog for the DLL project to point to  the Assets/plugins folder in your Unity project.
  4. Build the project.  If you have Unity loaded and it was successful you should see the plugin appear in your assets/plugins folder on the project page.
  5. Copy Check1.cs to the assets folder of your Unity project and attach the script to an object in your scene.  I added it to my landscape.
  6. Build the Unity project.

If all is successful then the dll should get loaded when you run your Unity app. 

If you want to debug, you can rather neatly run the DLL project in VisualStudio and when prompted point at the the Unity exe for your app. VS will load the app and breakpoints in the DLL source in VS should hit appropriately when your app calls the plugin.

I think thats all you need.  Let me know how you get on.

Happy coding

Steve

AttachmentSize
Package icon pluginsource.zip3.59 KB
Package icon touchtest.zip8.05 MB
For more complete information about compiler optimizations, see our Optimization Notice.

25 comments

Top
张 淼.'s picture

The unity application works very well.But in my project(or build), GetTouchPointCount() return 128 and all touch_id is 0.Why??

Patrick H.'s picture

A friend helped fix the problem, he pointed out that the "character set" option should not be set to "use unicode character set" but to "not set".
https://dl.dropboxusercontent.com/u/1418898/WM_TOUCH/WM_TOUCH%20fix.PNG

Patrick H.'s picture

Hmm, that's the way I created the project.
Unfortunately that results in a stream of errors when I try to build the dll.
Here's a screenshot
https://dl.dropboxusercontent.com/u/1418898/WM_TOUCH/WM_TOUCH.PNG
and here is a link to the project
https://dl.dropboxusercontent.com/u/1418898/WM_TOUCH/WM_TOUCH%20VS%202008.zip

steve-hughes (Intel)'s picture

Hi Patrick
What I did was (in Visual Studio 2008 or 2010) click File->new->project->Win32Project. Then set the name and hit "OK" then "next" then click the "Dll" radio box and the "empty project" check box then click finish. You should then have an empty dll project which you can add DLLMain.cpp to as the only source file.
There will be a list of libs in the linker options but they're just normal so you can ignore them.

Did you try "touchtest" to see if that worked?

Steve

Patrick H.'s picture

Hi Steve, thanks very much for the source!
However I must admit that I've been unsuccessful in compiling your code.
Can you tell me exactly what type of project you create at the start ?
There's more ways than one to create a dll and it looks like they all come with some set of libraries included.

Thanks in advance, Patrick

Pages

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.