Skip to content

Code Conventions

WizelfMike edited this page Feb 27, 2025 · 8 revisions

Variables:

  • Local variables must be a specific defined data type. The use of "var" is strictly prohibited

Don't do:

private void Funtion()
{
   var myInt= 1;
}

Do:

private void Funtion()
{
   int myInt= 1;
}

Classes

  • Class name = PascalCase

Class name in pascal-case

public class MyClass
{
}
  • Property name = Pascalcase

Property name in pascal-case

public int MyInt => 1;
  • Serialisefield = Pascalcase

Serialisefield name in pascal-case

[SerialialiseField]
private in MyInt;
  • non serialisefield = camelCase

non serialisefield name in camel-case

public int myInt;
  • private function names must have an underscore in front of it

private name with underscore

private int _myInt;

Functions

  • Function names = PascalCase

Function name with pascal-case

private void MyFunction()
{
}

scoped parameters = camelCase

Scoped parameter with camel-case

{
   int myInt = 1;
}
  • function parameters = camelCase

function parameter with camel-case

private void MyFunction(int myInt)
{
}

Class structure:

  1. Serialised fields
  2. Non serialised fields
  3. Properties
  4. Events
  5. functions
  • Example:
[SerialisedField]
private int SerialisedFieldInt;

private int nonSerialisedFieldInt;

public int  PropertyInt=> 1;

public UnityEvent onUnityEvent;

private void MyFunction()
{
}

Clone this wiki locally