Preprocessor
Forms that compile (4)
Section titled “Forms that compile (4)”| Syntax | Description |
|---|---|
#nullable enable | Enabling null safety |
#if FLAG / #else / #endif | Conditional compilation |
#if UNITY_EDITOR | Editor-only code |
#region / #endregion | Foldable regions |
Which symbols are defined depends on whoever compiles the source. Defined symbols, including UNITY_EDITOR, aren’t fixed to one set.
Directives
Section titled “Directives”Enabling null safety
Section titled “Enabling null safety”Null safety checks apply from the line you write it onward (Null and references).
#nullable enableusing UnityEngine;using Tsukimi;
public class PreNullableEnable : TsukimiBehaviour{ void Start() { string s = "a"; Debug.Log(s.Length); // => 1 }}Conditional compilation
Section titled “Conditional compilation”#define FLAGusing UnityEngine;using Tsukimi;
public class PreConditional : TsukimiBehaviour{ void Start() {#if FLAG Debug.Log(1);#else Debug.Log(2);#endif }}
// Output// 1Editor-only code
Section titled “Editor-only code”UNITY_EDITOR is a symbol for the Unity Editor. It isn’t defined on the path this example takes, so the enclosed code doesn’t compile.
using UnityEngine;using Tsukimi;
public class PreEditorOnly : TsukimiBehaviour{ void Start() {#if UNITY_EDITOR Debug.Log(1);#endif Debug.Log(2); }}
// Output// 2Foldable regions
Section titled “Foldable regions”It becomes a foldable region in the code editor. The compiled result doesn’t change.
using UnityEngine;using Tsukimi;
public class PreRegion : TsukimiBehaviour{#region Body void Start() { Debug.Log(1); // => 1 }#endregion}