code-conventions-unity
Code Conventions — Unity / C#
Section titled “Code Conventions — Unity / C#”Extends core code-conventions.md. The1Studio-specific patterns.
Naming (Deviates from Microsoft C# Standard)
Section titled “Naming (Deviates from Microsoft C# Standard)”- Private fields:
camelCase— NO underscore prefix. Usethis.for disambiguation - DOTS system fields:
m_prefix forComponentLookup<T>fields (Unity convention) - Public fields / Properties / Methods:
PascalCase - Constants:
UPPER_SNAKE_CASE - Enums:
PascalCasevalues - Namespaces:
ProjectName.Feature.Component— max 3-4 levels this.prefix: ALWAYS use for member access (mandatory, not optional)
DI & Architecture
Section titled “DI & Architecture”- VContainer ONLY — do NOT use Zenject (legacy, conditional
#if GDK_ZENJECTonly) - Events: VContainer
SignalBus— type-safe, decoupled - Subscribe/Unsubscribe: use named methods, NOT lambdas (reference equality)
- Resolve:
this.GetCurrentContainer().Resolve<T>()or constructor injection
Async & Reactive
Section titled “Async & Reactive”- UniTask preferred over coroutines for all new async code
- R3 for reactive data binding and subscriptions
- Dispose subscriptions in
OnDestroy()— trackIDisposable
Serialization
Section titled “Serialization”[SerializeField] private— always private, no underscore prefix- Attribute order:
[Tooltip]→[Range]→[SerializeField] - Default values inline:
[SerializeField] private float speed = 5f;
DOTS / ECS
Section titled “DOTS / ECS”- Attribute order:
[BurstCompile]→[RequireMatchingQueriesForUpdate]→[UpdateInGroup] - Job struct fields:
publicwith[ReadOnly]/[WriteOnly]annotations - Update lookups in
OnUpdate:m_Lookup.Update(ref state);
MonoBehaviour
Section titled “MonoBehaviour”- Lifecycle methods (
Awake,Start,OnEnable,OnDestroy):privatevisibility - Null safety: use
#nullable enablein new files - Lazy init:
this.field ??= new();
File Organization
Section titled “File Organization”- UPM packages:
Runtime/,Editor/,Samples~/ - One
.asmdefper module — no global assembly definitions
Living Document
Section titled “Living Document”If unsure about a convention not covered here, ask the user for their preference and update this file with the answer. Conventions grow from real decisions.