简体   繁体   中英

Compiling a C# project as DLL for Unity3d

As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project.

What are the pros and cons of both? Will they work cross platform (Android/iOS/WinPhone)?

To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?

How do you add a uncompiled project to Unity3d?

Will they work Cross platform(Android/iOS/WinPhone)?

Yes. You can create a library project in Xamarin Studio/MonoDevelop/or Visual Studio. If you do not include platform-specific functions, it will be then cross platform.

To compile as DLL - Do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?

See this tutorial .

When you open your Unity project in an IDE (for example Visual Studio), it is a solution with two projects, one for game scripts and one for editor scripts. You can add more projects to the solution through your IDE of choice. In order for this to work, you need to set projects target framework to one that is compatible with Unity (which uses a subset of Mono ), for example Unity 3.5 .net full Base Class Libraries. Unfortunately .NET PCL is not supported.

You can reference your (or third party) library in any of the projects as usual, just remember it also has to be compatible with Unity.

Wether your code will work on all the platforms actually depends on what you use. On platform specific limitations refer to http://docs.unity3d.com/Manual/PlatformSpecific.html .

Well Well Well too many question in a single post. Try to answer one by one: Unity Offical Docs provide much help:

Question

As far as I know a C# project can be added to Unity3d in 2 forms. As DLL or uncompiled project. To compile as DLL - do I just use MonoDevelop or Visual Studio to new class library project and select .NET 3.5 and compile?

Usually, scripts are kept in a project as source files and compiled by Unity whenever the source changes. However, it is also possible to compile a script to a dynamically linked library (DLL) using an external compiler. The resulting DLL can then be added to the project and the classes it contains can be attached to objects just like normal scripts.

It is generally much easier to work with scripts than DLLs in Unity. However, you may have access to third party Mono code which is supplied in the form of a DLL. When developing your own code, you may be able to use compilers not supported by Unity (F#, for example) by compiling the code to a DLL and adding it to your Unity project. Also, you may want to supply Unity code without the source (for an Asset Store product, say) and a DLL is an easy way to do this. More

What are the pros and cons

About dll:

Pros

  • You can build DLLs separately.
  • It could be faster to re-build one DLL

Cons

  • Calling code from DLL is slower
  • It would be slower to re-build hole project with all DLLs
  • Function names are visible. It is easier to reverse code that uses dynamic DLLs You can find more on here , here and specially on Google, our best friend:)

How do you add a uncompiled project to Unity3d? Ans: What do you mean by uncompiled project? You mean scripts? then it is usually Copy\\Paste inside asset folder simply.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM