Skip to content

Preprocessor

SyntaxDescriptionNote
#nullable enableEnabling null safety
#if FLAG / #else / #endifConditional compilation
#if UNITY_EDITOREditor-only codeIt isn’t defined on the path this example was compiled through, so what it encloses wasn’t compiled.
#region / #endregionFolding with #regionThe compiled result doesn’t change.
Predefined symbolsDecided by whatever compiles the source. Including UNITY_EDITOR, they aren’t fixed to one set

From the line you write it on, the null-safety checks are enabled (null and references).

#nullable enable
using UnityEngine;
using Tsukimi;
public class PreNullableEnable : TsukimiBehaviour
{
void Start()
{
string s = "a";
Debug.Log(s.Length); // => 1
}
}
#define FLAG
using UnityEngine;
using Tsukimi;
public class PreConditional : TsukimiBehaviour
{
void Start()
{
#if FLAG
Debug.Log(1); // => 1
#else
Debug.Log(2);
#endif
}
}

UNITY_EDITOR is a symbol for the Unity editor.

using UnityEngine;
using Tsukimi;
public class PreEditorOnly : TsukimiBehaviour
{
void Start()
{
#if UNITY_EDITOR
Debug.Log(1);
#endif
Debug.Log(2); // => 2
}
}

It becomes foldable in a code editor.

using UnityEngine;
using Tsukimi;
public class PreRegion : TsukimiBehaviour
{
#region Body
void Start()
{
Debug.Log(1); // => 1
}
#endregion
}