Preprocessor
Forms that compile (4)
Section titled “Forms that compile (4)”| Syntax | Description | Note |
|---|---|---|
#nullable enable | Enabling null safety | |
#if FLAG / #else / #endif | Conditional compilation | |
#if UNITY_EDITOR | Editor-only code | It isn’t defined on the path this example was compiled through, so what it encloses wasn’t compiled. |
#region / #endregion | Folding with #region | The compiled result doesn’t change. |
| Predefined symbols | Decided by whatever compiles the source. Including UNITY_EDITOR, they aren’t fixed to one set |
Directives
Section titled “Directives”Enabling null safety
Section titled “Enabling null safety”From the line you write it on, the null-safety checks are enabled (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); // => 1#else Debug.Log(2);#endif }}Editor-only code
Section titled “Editor-only code”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 }}Folding with #region
Section titled “Folding with #region”It becomes foldable in a code editor.
using UnityEngine;using Tsukimi;
public class PreRegion : TsukimiBehaviour{#region Body void Start() { Debug.Log(1); // => 1 }#endregion}