This repository serves as a sample project for demonstrating the integration of managed and native DLLs within a Unity project. It encompasses solutions for both native and managed DLLs developed in Visual Studio, alongside a Unity project that utilizes these DLLs.
The goal is to expand this repository with additional examples and documentation to aid in understanding DLL integration within Unity environments.
Follow these steps to build the DLLs and test them in the Unity Editor.
The process to build DLLs varies between Windows and macOS. Ensure you follow the instructions corresponding to your operating system.
- Open the
*.slnfiles located within the project directory using Visual Studio. - Compile the DLLs by selecting
Build Solutionfrom theBuildmenu.
Execute the following command in the terminal to compile the native DLL:
g++ -dynamiclib UnityDllHandling/NativeDll/NativeDll/dllmain.cpp -o UnityDllHandling/UnityProject/Assets/Plugins/Native/MacOS/NativeDll.dylibEnsure the target directory exists before running the command. If not, create it using:
mkdir -p UnityDllHandling/UnityProject/Assets/Plugins/Native/MacOS/Execute the following command in the terminal to compile the native DLL:
g++ --shared -fPIC UnityDllHandling/NativeDll/NativeDll/dllmain.cpp -o UnityDllHandling/UnityProject/Assets/Plugins/Native/Linux/NativeDll.soEnsure the target directory exists before running the command. If not, create it using:
mkdir -p UnityDllHandling/UnityProject/Assets/Plugins/Native/Linux/To verify the DLLs are working correctly within Unity, perform the following steps:
- Navigate to
Assets/Scenes/and openRunThisScene.unity. - Enter play mode by clicking the play button.
- Observe the output on the screen.
- The console should print information directly from the plugins.
Is the managed DLL working? True
Is the Native DLL working? True
This confirms that both the managed and the native DLLs are correctly integrated and functioning within your Unity project.