I was wondering if someone could help me with a fairly thorough answer to the following:
If I’m making a Unity game, and I want it to be Cross-platform compatible, (e.g. Windows/Mac/Linux), can I use “using statements” to import additional C# libraries, while maintaining cross-platform compatibility?
For instance, I recently imported a very common .NET library, (using System.Collections.Generic;), for very basic use. However, this library is not directly supported by Unity right off the bat. (Where it has to be resolved and added in with a “using statement”.)
Now, I now it works for Windows just fine, because am a .NET shop.
But… I guess I’m not sure how “Mono” and the .Net libraries interact.
To my understanding, Mono is what allows .NET to work cross-platform.
So is Unity setup to only allow certain .NET libraries?
Or can/does Mono convert any libraries? (including external DLLs?)
I know you can’t download .NET for MAC/Linux, so do extended libraries “break” cross-platform?
Are they included in a Unity build to make it run?
You’re using some terminology incorrectly, and not quite understanding how Unity or .NET works. “Using” statements do not import libraries, they merely import a namespace. All that does is save you having to type out the entire thing every time, e.g. var foo = new List<int>(); rather than var foo = new System.Collections.Generic.List<int>();. However the compiled code is 100% identical either way. It’s simply there for convenience, nothing else. So, this statement is entirely incorrect:
For instance, I recently imported a
very common .NET library, (using
System.Collections.Generic;), for very
basic use. However, this library is
not directly supported by Unity right
off the bat. (Where it has to be
resolved and added in with a “using
statement”.)
You didn’t import a library when doing that, and Unity does support it right off the bat. It’s part of .NET core and you can’t avoid having it available in Unity. It’s not relevant as far as cross-platform concerns go.
Unity on Windows uses Mono, same as other platforms, so almost everything is automatically cross-platform. One exception is Windows Store apps, which are different from normal Windows apps, and actually use “real” .NET, not Mono. However the Windows Store version of .NET is missing some functionality that’s in Mono (oddly enough, considering how old Unity’s version of Mono is), so there might be some difficulty porting to that platform, depending on which functions you use exactly. However the “porting” process in this case does not involve libraries or anything, but simply trying to find alternative functions that are common to the Windows Store .NET and Unity’s Mono.
Porting when using native code libraries is another matter, however nothing in your question is about such a thing, so you can ignore that.
Unity can be compiled in Mono 2.0 subset (default) and Mono 2.0… though I think the subset is gone in Unity 5.5
The subset is the most broad one, that is supported pretty much in every platform (windows, mac, linux, android, ios, etc). Mono 2.0 has more classes, but the support is a bit more restrained.
These libraries are packed with your project so they work no matter which platform you’re running it on.
It depends entirely on what dependencies you are using, and which .net features those dependencies are in turn using. Unity runs on a fairly old version of mono, so some features might not be implemented. Additionally, you may have problems with certain frameworks as packaging them with your game might not even be legal. With that being said, if you import only libraries that you have the license to, that use only Mono 2.0 features, they should work. DLLs are different, and you will have to make platform-specific fixes for this. For Android, you can use Android NDK | Android Developers, which allows you to make native plugins, letting you use DLLs. I’m not sure how it works on the iphone, but what I do know is that it’s not fun at all.