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
Andrew A.'s picture

Steve,

Thank you for the time you put into making this example! I have a question about testing in the Unity Editor. I'm able to get everything working properly using the .dll, and creating a build from Unity. I'd like though, to quickly test and make changes in the editor. I've been unable to get the .dll to recognize any of the names I've been passing it. I've used "Unity", "Unity Editor", "Unity Editor (32 bit)", even the full name of the window at the top of the editor that is an amalgamation of the project name, the scene name, the build name, and the build target.  

Can you provide any insight into how to find the name of a program running in windows? Do you know if this something we can find in the properties of the program or in the task manager?

Andy

马晨's picture

Hi Steve,
I build the unity project and it works on my Intel Ultrabook. However, after a short time all the gameobjects in the unity application will stoping moving,all the animations stop too. I don't know that just exist on my Ultrabook or any other people have this question too.
Oh,Sorry,I find the reason,I have made a silly mistake...when I edit the check1.cs, I added a wrong sentence.
Thank you for your supporting!

Chris C.'s picture

Ah, you're right. I was just making it overly complicated for myself. Thanks for all the help!

steve-hughes (Intel)'s picture

Chris

If you have the dll I built (it's in touchtest.zip) you probably dont need to recompile the dll unless you want to add more functionallity. Just copy the dll to the plugins directory, copy the c# script to your project and attach it to something, and you're all set. Just remember to make sure the window name passed to the dll is right.

Steve

Chris C.'s picture

Hey Steve,
It's definitely copying the DLL to my Unity plugins folder - I wouldn't be able to build my Unity project without it. I'm just not sure where it could be going wrong. The only settings I'm changing is the Name, Output Directory, and the Character Set (Not Set). I am using Visual Studio Express 2013 though, which I'm starting to think may be the issue.
Is the Visual Studio step necessary? Could a pre-compiled TouchOverlay plugin just be copied into the Unity plugins folder?

Thanks for the reply!

steve-hughes (Intel)'s picture

Hi Chris
I think there is a custom build step or a post build step in the project properties in the Visual Studio project. Currently it copies the dll to the plugins folder in the example project. Change the target path in the copy command in there to point to the plugins folder in your project and you're all set.

Hope that helps.

Steve

Chris C.'s picture

Hi Steve,
I've managed to get touch controls working on a Surface Pro by using your guide. However, every time I make a new build I have to copy the contents of the plugins folder of your example project to get it working properly. It's a minor inconvenience, but it'd be nice to have the builds working straight away. Do you have any suggestions on what I could try? I'm assuming I must be doing something wrong when exporting the plugin from Visual Studio. Thanks for setting this guide up, by the way! It's been a huge help so far.

steve-hughes (Intel)'s picture

Hi 张 淼.

Glad you got it working. I remember setting the wrong name a couple of times while I was writing it so I recognised your issue right away :)

Steve

张 淼.'s picture

Hi steve
It works well now!!Thanks very much!!

steve-hughes (Intel)'s picture

Hi 张 淼.
I would check that you have the name of the main window correct when you set up the interface.

Pages

Add a Comment

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