There’s a section in assembly definition file’s inspector called “Define Constraints”.
By default all of those define constraints must be true for that assembly to get compiled.
Is it possible to have OR instead of AND between them? I want to compile an assembly if one of (or both) DEBUG and SERVER is defined.
I’d like the same. Did you find a way of doing this?
This is documented at Assembly Definition properties :
Specify the compiler #define directives that must be defined for Unity to compile or reference an assembly.
Unity only compiles and references a Project assembly if all of the Define Constraints are satisfied. Constraints work like the #if preprocessor directive in C#, but on the assembly level instead of the script level. You must define all the symbols in the Define Constraints setting for the constraints to be satisfied.
To specify that a symbol must be undefined, prefix it with a negating ! (bang) symbol. For example, if you specify the following symbols as the Define Constraints:
!ENABLE_IL2CPP
UNITY_2018_3_OR_NEWER
The constraints are satisfied when the symbol ENABLE_IL2CPP is not defined and the symbol UNITY_2018_3_OR_NEWER is defined. In other words, Unity only compiles and references this assembly on non-IL2CPP scripting runtimes for Unity 2018.3 or newer.
You can use the || (OR) operator to specify that at least one of the constraints must be present in order for the constraints to be satisfied. For example:
UNITY_IOS || UNITY_EDITOR_OSX
UNITY_2019_3_OR_NEWER
!UNITY_ANDROID
The constraints are satisfied when either UNITY_IOS or UNITY_EDITOR_OSX and UNITY_2019_3_OR_NEWER are defined and UNITY_ANDROID is not defined. Individual lines are analogous to performing a logical AND between the constraints in them. The above example is eequivalent to (UNITY_IOS OR UNITY_EDITOR_OSX) AND (UNITY_2019_3_OR_NEWER) AND (NOT UNITY_ANDROID).
You can use any of Unity’s built-in #define directives or any symbols defined in the Project’s Scripting Define Symbols Player setting. See Platform dependent compilation for more information, including a list of the built-in symbols. Note" The Scripting Define Symbols settings are platform-specific. If you use this setting to define whether Unity should use an assembly, make sure that you define the necessary symbols on all of the relevant platforms.
2 Likes