Importing .NET Libraries Into Unity 3D

preview_player
Показать описание
You can import .NET Libraries into Unity in order to expose additional functionality in your game. In this video we're going to build a basic demonstration of this feature by creating a brand new .NET Core library and importing it into Unity.

Once the library is imported we can invoke it and create objects defined by it just like any other code.

To create a new dotnet library with .NET Core you can use:

```csharp
dotnet new classlib --name [your library name]
```

Рекомендации по теме
Комментарии
Автор

If anyone gets "TypeLoadException: Could not resolve type...". Remember to use the right target framework, using the .NET 5+ may be incompatible with Unity. This tutorial didn't work for me (using System.Random/System.Math libraries with .NET 5) until i set the target framework to net standard with:

dotnet new classlib -f netstandard2.0 --name [your library name]

But i had to replace the "dynamic" keyword in my scripts, since it's only supported in .NET framework and not in .NET standard. Then, it worked. Thanks for the tutorial btw!.

dannysebastiandiazpadilla
Автор

This is more simple than I would have imagined. Thanks for sharing this great intro! :)

ewwitsantonio
Автор

Nice little tutorial, I see why the command line is useful. Never got into that though, not since the days of MSDOS haha! But once you know what you are doing with it, it must speed things up a lot.

purerlogic
Автор

i have been looking for this everywhere

patspoutnik
Автор

Today I Learned: Practice my presentation before I try to record it.

paulschrum
Автор

Thanks bro, this was just what i needed.

zebamanu
Автор

Thanks for the great content. I'm curious how to then turn your class library into something that uses Unity's package manager so that you could feasibly have libraries which are shared among multiple Unity projects, easily updated, etc.

vargonian
Автор

Hi! What is the benefit of this when you just put your library in the shared folder? I saw there is an other way so you can create package with your library. What is the better approach and why?

Ferenc-Racz
Автор

Why not use plugin folder? What is advantage of using Resources?

darktip
Автор

I'm brand spanking new to .NET, Unity scripting - any chance for additional details regarding how one adds .NetCore assemblies that have types that are then used by the user DLL that is used by the Unity3d script (ie. Unity script uses class A defined in my DLL, class A uses namespace+type defined in a .NetCore assembly. I'm using csc.rsp response file but Unity/csc.exe is gagging on an embedded space as I'm using


I've tried putting " around the entire line (eg. "-r:.... ") as well as just around the text after -r: but the csc.exe messages displayed in the Unity Console shows the space in "Program Files" is being treated as the end of the /LIB path (ie, warning CS1668: Invalid search path 'C:\Program' specified in '/LIB option'

I'm making a big assumption that Unity transforms the -r to a /reference: csc.exe option.

I've probably gone down the rabbit hole. Is there a 'best practices' mechanism for providing Unity projects the means to load .NETCore assemblies?
I've also made the assumption that I'm dealing with the managed plugin concept as defined by Unity - .NET only dependencies, but isn't System.Text.Json.* assemblies in .NetCore considered .NET code in the .NET 4.x space?
I am using .NET 4.x equivalent as the Scripting Runtime Version, .NET 4.x as the Api Compatibility Level.
Thanks for any insights.

Many thanks for making & posting this video

stevenhespelt
Автор

I followed your video and everything works fine, until I build my game for WEBGL, then through the browser console, I see that it is having some trouble loading the DLL. (I got it from the package manager)

karakaisx
visit shbcf.ru