Using .NET 4.5 code in Unity 5

2019-01-22 13:25发布

问题:

I am working on a game using Unity3D version 5. The game should use strict business rules already programmed in a C# .NET4.5 engine. Using Xamarin/Mono, we hope to make this usable on windows, android, others...

I tried building the engine into a dll and use it as a managed plugin in Unity. But Unity uses an old version of Mono to compile the whole game and refuses to use .NET 4.5 dlls.

I really need to use this code, I looked into downgrading it to .NET 3.5 but it is not an acceptable solution given the work already done on the engine.

Concerning android, I think to use Xamarin to get native android code and use it as a native plugin in Unity. Now I need a solution for Windows. I am looking into ways to use the C# code in C++ to make an unmanaged dll but I am struggling understanding which way is applicable here between COM interop, C++/CLI or other methods.

Does any one knows a way to include code from .NET 4.5 in Unity with no/little effort ?

回答1:

Looks like Unity is upgrading to 4.6+ and is available in beta now

https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-on-5-5-0b4.433541/



回答2:

Using a visual studio plugin: unmanaged exports, I have been able to export the C# .NET 4.5 to an unmanaged/native dll which I can use in Unity Engine. This forces to call only simple functions, but with little work, it was possible for me to wrap the core of my engine.



回答3:

Short answer is no.

Unity has ".NET 2.0/3.5 era functionality," according to an official blog post.

According to the same post, a future version of Unity will be upgraded to "a modern version of .NET," with no timeline given for this major undertaking.

NOTE: This answer was written in response to the original version of the question, which was simply whether the .NET 4.5 library could be used directly in Unity.