- Home /
importing c# classes and packages into unity
hi everyone, I want to import some of the classes made in c# in unity project. I have imported all of them into Asset folder and they are working like a charm. The issues is that I dont want to import every classe. There are more than 10 classes and its not possible to import all of them in every script. Is there anyway put, so that I have to just import only one file/folder and all the classes in it gets imported by itself ?
@devnewbie This is bad for code management, project scalability and against general program$$anonymous$$g good practice.
Answer by Mike 3 · Dec 08, 2010 at 06:28 PM
Compile all of your code into a .NET library, then it'll just be one .dll file
In MonoDevelop (which comes with unity 3) it's pretty simple - File > New > Solution, then select c# library
Add in your c# files after creating the solution, hit build, then you should have your dll to put in any project you want
Note - you don't need unity pro to use .NET dlls, in case you're worried about the plugin issue, and also, don't put the file into the Plugins directory, it'll get compiled into built projects twice otherwise
Answer by Zib Redlektab · Dec 08, 2010 at 05:37 PM
Can you have one script that just imports everything, and then import that script instead of the big list of everything you need?
Answer by Alekh · Dec 09, 2010 at 05:48 AM
I can always develop dll for my project but as I am developing game for iphone, it wont work there. Importing all the classes in one script seems to be good solution but instead I found better solution . I can drop all of my classes in one particular directory and then it can be copied to /Assets/Plugin folder. Now I can easily import that namespace into any c# script. But make sure that all the classes are declared in same namespace otherwise it wont work. But as you said would that make c# files compile twice?