arrow-left

All pages
gitbookPowered by GitBook
1 of 9

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Fields

Private fields have the _ prefix, static, const and public fields are in UpperCamelCase.

For example:

public class MyClass 
{
    public int PublicField;
    private int _packagePrivate;
    private int _myPrivate;
    protected int _myProtected;
}

BAD:

private int myPrivateVariable

GOOD:

private int _myPrivateVariable

hashtag
Field Position

All fields should be at the top of the class, before any methods.

Parameters

Parameters are written in camelCase.

BAD:

void DoSomething(Vector3 Location)

GOOD:

void DoSomething(Vector3 location)

Single character values are to be avoided except for temporary looping variables. You can also use _ for unused variables, m for network messages and e for event bus's events.

Nomenclature

On the whole, naming should follow C# standards.

Methods

Methods are written in PascalCase. For example DoSomething().

chevron-rightMethods that are used as the OnChange callback of a [SyncVar]hashtag

Should have the Sync prefix, as in:

chevron-rightMethods that listen to an eventhashtag

Should have the prefix Handle, as in:

chevron-rightMethods that are preceded by the [Server] attributehashtag

Do not need to have the Server prefix on them. This is still something we are thinking about, both uses are fine for now.

As in:

chevron-rightMethods that are preceded by the [ServerRpc] attributehashtag

Need to have the Cmd prefix on them, as in:

chevron-rightMethods that are preceded by the [ObserversRpc] attributehashtag

Need to have the Rpc prefix on them, as in:

[SyncVar(OnChange = nameof(SyncUsername))] string _username;
private void SyncUsername(string oldUsername, string newUsername, bool asServer) {}
clownBomb.OnExploded += HandleClownBombExploded;
private void HandleClownBombExploded() 
{
    Honk();
}
[Server]
public void ServerKillPlayer() {}
[Server]
public void KillPlayer() {}
[ServerRpc]
public void CmdSpawnItem(GameItems item) 
{
    SpawnItem(item);
}
[ObserversRpc]
private void RpcSpawnVisualProjectives() 
{
   _particleSystem.Play();   
}

Classes & Interfaces

Classes are written in PascalCase. For example RadialSlider.

Interfaces should always have the prefix I, as in IOpenable.

Namespaces

Namespaces are all PascalCase, multiple words concatenated together, without hypens ( - ) or underscores ( _ ):

Namespaces should be used for major systems, such as Atmospherics, or Electrics. Everything else should be without namespace.

BAD:

com.ress3dclient.scripts.structures

GOOD:

SS3D.Systems.Tilemaps.Structures

Delegates

Delegates are written in PascalCase.

When declaring delegates, DO add the suffix EventHandler to names of delegates that are used in events.

BAD:

public delegate void Click()

GOOD:

public delegate void ClickEventHandler()

DO add the suffix Callback to names of delegates other than those used as event handlers.

BAD:

public delegate void Render()

GOOD:

hashtag
⚠️ IMPORTANT!

Using built.in C# features, such as Action, is encouraged in place of delegates.

public delegate void RenderCallback()

Misc

In code, acronyms should be treated as words. For example:

BAD:

XMLHTTPRequest
String URL
findPostByID

GOOD:

XmlHttpRequest
String url
findPostById

Events

Prefix event methods with the prefix On.

BAD:

public static event CloseCallback Close;
public event Action Changed;

GOOD:

public static event CloseCallback OnClose;
publc event Action OnChanged;