Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add Unity support to a NuGet package?

Tags:

c#

nuget

unity3d

How do I publish a package to NuGet that supports Unity (the game engine)?

Also, do I need to have Unity installed to compile it, or is targeting a specific framework version enough?

like image 324
BlueRaja - Danny Pflughoeft Avatar asked Apr 04 '17 00:04

BlueRaja - Danny Pflughoeft


People also ask

How do I add a Unity package to a project?

To add a Unity package to your project, follow these steps: In your Unity development environment, open the Project tab. In the left pane of the Project tab, right click the Assets folder, then select Import Package → Custom Package… in the context menu. An Import package…

Where is the Unity package manager?

Accessing the Package Manager window. To open the Package Manager window, navigate to Unity's main menu and go to Window > Package Manager.


1 Answers

How do I publish a package to NuGet that supports Unity (the game engine)?

Just follow the instructions in the doc. Class library for Unity3D is nothing different from regular .NET Class library. It just uses a different runtime comes from Unity3D's fork of mono.

Also, do I need to have Unity installed to compile it, or is targeting a specific framework version enough?

Yes. If your library uses Unity3D types, the project needs to reference assemblies, such as UnityEngine.dll and UnityEditor.dll, from Unity3D. If your library doesn't use Unity3D types, you still need to test it with Unity3D. Because older Unity3D targets .NET 2.0 and a subset of .NET 3.5. So if your library uses features only available in .NET 4+, it won't work with Unity3D. See also Using dll.

It's better to install Visual Studio Tools for Unity3D for VS2015 (for VS2017, install VSTU in the VS installer instead) and then you can target one of the Unity3D targets:

Unity3D .NET targets

As for the publishment of your package, I think you'd better publish your package on Unity3D asset store since it is officially supported. You may want to try this improved version of Unity3D asset store tools when publishing your package to the asset store.

like image 66
zwcloud Avatar answered Oct 19 '22 19:10

zwcloud