A simple demonstration of using C++ library (DLL) in Unity. This repo describes how to build a C++ library in the form of dynamic linked library (DLL), encapsulate C++ classes and export functions. On the other hand, this repo also shows how to import and use the library (DLL) in Unity via c# script.
This repo contains two folders:
-
SampleCppDll - A Visual Studio Community 2017 project and C++ files.
-
UnitySampleDll - An Unity project that make uses of the DLL built by SampleCppDll. Unity version 5.6.2f1 is used here.
-
Use Visual Studio Community 2017 to open the SampleCppDll solution file
SampleCppDll/SampleCppDll.sln -
Use the menu
Build > Build Solutionto build (Remember to set the architecture x64 and it's assumed 64bits environment here) -
Copy the output file
SampleCppDll.dllunderSampleCppDll/x64/Debug/toUnitySampleDll/Assets/Plugins/(If release build is used then it's underSampleCppDll/x64/Release/) -
Use Unity 5.6+ to open folder
UnitySampleDll -
Open
UnitySampleDll/Assets/Scene/Main.unity -
Run it in the editor. Output from DLL will be printed in the Unity console tab.
-
More functions can be added to the C++ projects or even linking other library (Note that all linked dynamic linking library has to be copied to the
UnitySampleDll/Assets/Pluginsfolder). Enjoy the boilerplate ~