Platform Dependent Compilation (562198)

When I wrap a class MyClass with #if#endif in a C# script and build it in MonoDevelop, I get the message that the type or namespace MyClass could not be found. Where can platform dependent compilation be used: wrap classes, methods, code within methods, etc? Are there any alternatives for conditionally including classes?

From the C# perspective they can be used anywhere. For Unity, I would recommend it mostly within functions or groups of functions in a class. You can also use it to affect member variables in a class, but be careful you don’t cause serialization bugs on target. If you want whole files/types to be platform specific, better to use Unity’s magical folders like Editor, Plugins, etc.

If you condition out an entire class then you also have to condition out places you use the class in your other code. This can get messy fast. One way around this is to use a common interface and assign the appropriate class at runtime via a manager script.