File layout and namespaces
Forms that compile (18)
Section titled “Forms that compile (18)”| Syntax | Description | Note |
|---|---|---|
struct NsHelper { ... } | Helper types in the same file | The only thing that can’t share the file is a second concrete Behaviour. |
namespace Sample { ... } | Namespace declaration | |
namespace Sample.Inner | Nested namespaces | |
using V = UnityEngine.Vector3; | Alias (using alias) | |
using static UnityEngine.Mathf; | using for static members | |
UnityEngine.Debug.Log(...) | Fully qualified name | |
public int V; | Visible from anywhere | |
private int V; | Visible only inside the declaring type | |
protected int V; | The type itself and derived types | |
internal int V; | Within the same program | |
protected internal int V; | The same program, or a derived type | |
private protected int V; | The same program, and a derived type | |
int a = 1; | Hiding by an inner name | |
int V = 1; | Hiding through nesting | |
for (int i = …) { } | Scope of the for-loop variable | |
global::System.Int32.MaxValue | Alias for the global namespace | |
nameof(value) | Stringifying a parameter name | |
public static void Main() | Writing Main | A program’s entry points are the events the base declares. |
Forms that don’t compile (3)
Section titled “Forms that don’t compile (3)”| Syntax | Description | Error | Reason | Alternative |
|---|---|---|---|---|
| Two concrete Behaviours in one file | One file is one program | TUKI0109 | by design | Split the file |
Both using Tsukimi; and using UdonSharp; | A type with the same name is visible from two namespaces | CS0104 | by design | Remove one of the usings |
Take(int v) and Take(ref int v) | An overload that differs only in how the argument is passed | TUKI0001 | not yet | Rename it (Variables and argument passing) |
| Two concrete Behaviours in one file | A TUKI0109 error (helper types can share the file) |
| Access modifier | All 6 can be written |
| LINQ | The error isn’t about iterators or delegates but about the namespace being absent. The single line using System.Linq; produces CS0234, and the compiler says it can’t find System.Linq |
Main | It can be written but is never called. Entry points are the events the base declares (Events), and the runtime calls those |
Inside a file
Section titled “Inside a file”Helper types in the same file
Section titled “Helper types in the same file”struct, record, enum, interfaces, and static classes can share the same file.
using UnityEngine;using Tsukimi;
public struct NsHelper{ public int V;}
public class NsWithHelper : TsukimiBehaviour{ void Start() { NsHelper h = new NsHelper(); Debug.Log(h.V); // => 0 }}Namespaces
Section titled “Namespaces”Namespace declaration
Section titled “Namespace declaration”using UnityEngine;using Tsukimi;
namespace Sample{ public class NsBlock : TsukimiBehaviour { void Start() { Debug.Log(1); // => 1 } }}Nested namespaces
Section titled “Nested namespaces”using UnityEngine;using Tsukimi;
namespace Sample.Inner{ public class NsNested : TsukimiBehaviour { void Start() { Debug.Log(1); // => 1 } }}Referencing other namespaces
Section titled “Referencing other namespaces”Alias (using alias)
Section titled “Alias (using alias)”using UnityEngine;using Tsukimi;using V = UnityEngine.Vector3;
public class NsAlias : TsukimiBehaviour{ void Start() { V v = new V(1f, 2f, 3f); Debug.Log(v); // => value from the runtime }}using for static members
Section titled “using for static members”using UnityEngine;using Tsukimi;using static UnityEngine.Mathf;
public class NsUsingStatic : TsukimiBehaviour{ void Start() { Debug.Log(Abs(-1f)); // => 1 }}Fully qualified name
Section titled “Fully qualified name”using Tsukimi;
public class NsQualified : TsukimiBehaviour{ void Start() { UnityEngine.Debug.Log(UnityEngine.Mathf.Abs(-1f)); // => 1 }}Access range
Section titled “Access range”Visible from anywhere
Section titled “Visible from anywhere”A field marked public appears in the Inspector (Attributes).
using UnityEngine;using Tsukimi;
public class BcPublic : TsukimiBehaviour{ void Start() { Debug.Log(V); // => 0 }
public int V;}Visible only inside the declaring type
Section titled “Visible only inside the declaring type”using UnityEngine;using Tsukimi;
public class BcPrivate : TsukimiBehaviour{ void Start() { Debug.Log(V); // => 0 }
private int V;}The type itself and derived types
Section titled “The type itself and derived types”using UnityEngine;using Tsukimi;
public class BcProtected : TsukimiBehaviour{ void Start() { Debug.Log(1); // => 1 }
protected int V;}Within the same program
Section titled “Within the same program”using UnityEngine;using Tsukimi;
public class BcInternal : TsukimiBehaviour{ void Start() { Debug.Log(V); // => 0 }
internal int V;}The same program, or a derived type
Section titled “The same program, or a derived type”using UnityEngine;using Tsukimi;
public class BcProtInt : TsukimiBehaviour{ void Start() { Debug.Log(V); // => 0 }
protected internal int V;}The same program, and a derived type
Section titled “The same program, and a derived type”using UnityEngine;using Tsukimi;
public class BcPrivProt : TsukimiBehaviour{ void Start() { Debug.Log(V); // => 0 }
private protected int V;}Name resolution
Section titled “Name resolution”Hiding by an inner name
Section titled “Hiding by an inner name”using UnityEngine;using Tsukimi;
public class BcSimpleName : TsukimiBehaviour{ void Start() { int a = 1; Debug.Log(a); // => 1 }
private int a = 2;}Hiding through nesting
Section titled “Hiding through nesting”using UnityEngine;using Tsukimi;
public class BcHideNesting : TsukimiBehaviour{ void Start() { int V = 1; Debug.Log(V); // => 1 }
private int V = 2;}Scope of the for-loop variable
Section titled “Scope of the for-loop variable”using UnityEngine;using Tsukimi;
public class BcForScope : TsukimiBehaviour{ void Start() { for (int i = 0; i < 2; i++) { Debug.Log(i); } for (int i = 0; i < 2; i++) { Debug.Log(i); } }}
// Output// 0// 1// 0// 1Alias for the global namespace
Section titled “Alias for the global namespace”using UnityEngine;using Tsukimi;
public class BcGlobalQual : TsukimiBehaviour{ void Start() { Debug.Log(global::System.Int32.MaxValue); // => 2147483647 }}Stringifying a parameter name
Section titled “Stringifying a parameter name”using UnityEngine;using Tsukimi;
public class BcNameofParam : TsukimiBehaviour{ void Start() { Debug.Log(Take(1)); // => "value" }
private string Take(int value) { return nameof(value); }}Event entry point
Section titled “Event entry point”Writing Main
Section titled “Writing Main”Main can be written, but the runtime doesn’t call it.
using UnityEngine;using Tsukimi;
public class BcMain : TsukimiBehaviour{ void Start() { Debug.Log(1); // => 1 }
public static void Main() { }}