The standard-license, free version of Unity does not support plug-ins. Thanks to our community of Leap developers, we have determined that it is possible to use the Leap libraries with the free version of Unity. It does require some manual steps, however.
Note: if you have the Pro-license for Unity, see Setting up a Unity Project. Using the plug-in mechanism supported by Unity Pro is typically more convenient.
To get a Unity project to work with the Leap libraries, you must put the libraries in a location where they can be found at runtime. This location is different depending on whether you are running the project within the Unity editor or running the exported executable. Since the standard version of Unity doesn't support plug-ins, the key is to put the libraries in a place where the operating system's dynamic library loader can find them.
Placing the Leap libraries during development
During development, you can put the .NET3.5 dll in the Assets folder of your Unity project and the LeapCSharp and Leap libraries in the root of your project folder. For example, if your Unity project is called UnicornSlam, then you could use the following structure for your project
Windows:
UnicornSlam/
Assets/
LeapCSharp.NET3.5.dll
OneMillionUnicorns.unity
Scripts/
LeapControl.cs
Library/
ProjectSettings/
Leap.dll
LeapCSharp.dll
msvcp100.dll
msvcr100.dll
On Windows, use only the 32-bit libraries in the x86 folder with the editor.
OS X:
UnicornSlam/
Assets/
LeapCSharp.NET3.5.dll
OneMillionUnicorns.unity
Scripts/
LeapControl.cs
Library/
ProjectSettings/
libLeap.dylib
libLeapCSharp.dylib
On Mac, do not use the LeapCSharp.bundle file from the Leap SDK. The libraries must be copied separately.
Placing the Leap libraries after exporting
After you export your Unity project, you also have to copy the Leap libraries and dependencies to the export folder along side the application. For example, if you export your project to a folder called UnicornSlamExport, the final folder contents would look like this:
Windows:
UnicornSlamExport/
Leap.dll
LeapCSharp.dll
msvcp100.dll
msvcr100.dll
Unicorn_Slam_Data/
UnicornSlam.exe
Make sure that you use the libraries in the x86 folder in the SDK for 32-bit Windows builds and the libraries in the x64 folder for 64-bit Windows builds.
OS X:
UnicornSlamExport/
libLeap.dylib
libLeapCSharp.dylib
UnicornSlam.app
You can now make an installer to deploy your application in the same way that you would for a non-Leap enabled program.
Placing the Leap libraries inside the application package on Mac
It is often convenient to place all the dependencies within the application package on the Mac. To do so, you must identify the path where the libraries can be found. You can use the install_name_tool utility to add the path to your application binary and copy the libraries into the Frameworks folder within the application package. For example, the .app package for the hypothetical UnicornSlam application looks like the following after exporting from Unity:
UnicornSlam.app/
Data/
Frameworks/
MonoEmbedRuntime/
Info.plist
MacOS/
UnicornSlam
PkgInfo
Resources/
First, add a relative path to the application binary using install_name_tool. From the export folder, run the following command in a Terminal window:
install_name_tool -add_rpath @executable_path/../Frameworks UnicornSlam.app/Contents/MacOS/UnicornSlam
Next, copy libLeap.dylib and libLeapCSharp.dylib to the Frameworks folder inside the app package. When finished, the app package should look like the following:
UnicornSlam.app/
Data/
Frameworks/
libLeap.dylib
libLeapCSharp.dylib
MonoEmbedRuntime/
Info.plist
MacOS/
UnicornSlam
PkgInfo
Resources/
Acknowledgements
I would like to acknowledge and thank the many Leap community developers such as pixelplacement and BirnamWoodGames, who helped us discover the information provided in this article. In particular, Pierre Semaan wrote a tutorial for Windows, Getting the Leap to work with Unity (Free Version not Pro), that presented a more reasonable workflow for using the Leap with the standard version of Unity than we were previously aware of.