Skip to content

Code Conventions

MitchelMA edited this page Mar 6, 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 int MyInt;

public int OtherInt;
  • non serialisefield = camelCase

non serialisefield name in camel-case

[HideInInspector]
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. Events
  3. Properties
  4. Non serialised fields
  5. Private variables
  6. functions
  • Example:
[SerialisedField]
private int SerialisedFieldInt;

public UnityEvent onUnityEvent;

public int PropertyInt=> 1;

[HideInInspector]
public int nonSerialisedFieldInt;

private int _myPrivateInt

private void MyFunction()
{
}

Clone this wiki locally