For a long time it has been a lot of hassle to use existing .NET libraries in Unity3D. Unity3D only supported .NET 2.0/3.5, so more recent libraries (4.0 and up) could not be used without recompiling/rewriting for .NET 2.0/3.5.
Also new C# language constructs (C# 6) could not be used by game developers
At the moment Unity3D is upgrading the Mono version to 4.6. The first builds are available for download so let’s take a test drive.
Installation Unity 5.6 with upgraded Mono: https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-and-some-players-on-5-6-0b5.454387/
In the Unity 5.6 editor .NET 4.6 is now the default (Edit –> Project settings –> Player –> Other settings –> Configuration)
For the test I’ve created a sample project (https://github.com/bertt/dotnetstandard_and_unity3d) that does the following:
. get a location (latitude, longitude)
. Download and display the tile on a Unity3D Plane GameObject.
The Tilebelt library is a small library with some utility functions for working with the OpenStreetMap tiling scheme. It is compiled for .NET Standard 1.1 with the following dependencies:
System.Collections (>= 4.3.0)
System.Runtime.Extensions (>= 4.3.0)
System.Resources.ResourceManager (>= 4.3.0)
System.Runtime (>= 4.3.0)
The dependencies we could get from NuGet or they could be found in the folder C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unity_aot\Facades
The Tilebelt.dll assembly and dependencies we have to manually copy to the assets folder, unfortunately the NuGet support is not so great yet.
At the moment, only the following players in the preview build should be working:
- Windows, OSX, Linux standalone
- iOS with IL2CPP
- Android with IL2CPP and Mono
Here a screenshot of the application build for Windows:
This is just a small example of using a .NET Standard library in Unity3D, but it proves we can use other NuGet libraries as well.