The Unity Multi Touch Source (finally)

By Stephen Hughes,

Published:05/01/2013   Last Updated:05/01/2013

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 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


Attachment Size 3.6 KB 8.1 MB

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804