Excluding parts of C# code from compilation process

Motivation

Sometimes the logic within existing C# files is crucial for the game to work, but at the same time is heavily interweaved with logic related to things that are unsupported in Luna. This can range from a missing API to (much more likely) third-party libraries' integration. For instance, a C# script responsible for core game logic might contain invokations of an Analytics service.

For this particular matter, Luna provides a C# define helping to guard blocks of code when those are compiled by Luna.

How to configure code block excludes

Similarly to UNITY_EDITOR define and the like, Luna sets up it's own define, UNITY_LUNA. This way, a developer can wrap a block of code using a conditional preprocessor directive to avoid some path of the code from being compiled:

troubleshooting-luna-ui-code-blocks

This define is also enabled in Luna's VS solution, thus hinting the developer that particular blocks of code will (or will not) take part in compilation process.

The UNITY_LUNA define can also be used to invoke bits of code only in Luna, shall this neccessity appear. Although in most cases it is considered a better practice to drive such things using settings of game objects / store flags in a scriptable object / configure via an external file, it might become handy to quickly adjust some parts for Luna only (i.e. load level number 5 instead of 1 if the game is built with Luna).