Code Style - UltraStar-Deluxe/Play GitHub Wiki
-
Indent using 4 spaces
-
All curly braces get their own line
-
Use explicitly typed variables (no
var
keyword) -
Skip the constructor name when it is equal to the expected type name. For example, use
Bla bla = new()
, don't useBla bla = new Bla()
. -
PascalCase: NameSpace, Class, IInterface, EEnum, Method, Property, Constant, Event
-
camelCase: parameters, all fields
-
Prefixes: E for enums, I for interfaces, but none for private or static fields
-
Suffixes:
-
Scene
: scenes files -
Ui
: UXML files -
Manager
: singleton classes -
Control
: often used as suffix for a code counterpart of something. - Examples:
-
MainScene.unity
has a correspondingMainSceneUi.uxml
andMainSceneControl.cs
. - There is a single
SettingsManager
instance available in all scenes.
-
-
-
No acronyms, except for the above mentioned prefixes and common abbreviations, such as
Http
orXml
-
In code, acronyms should be treated as words, for example:
XmlHttpRequest
-
Use
private
where possible -
Avoid
static
where possible- static fields have to be reset explicitly because Domain Reload is disabled for UltraStar Play.
Example:
public class MySceneControl
{
public int publicField;
int packagePrivate;
private int myPrivate;
protected int myProtected;
public string MyProperty { get; private set; }
public event Action<int> ValueChanged;
public MySceneControl()
{
List<string> stringList = new();
}
}
public enum EDay
{
Today, Tomorrow
}
public interface IXmlReader {
void ReadXml(string filePath);
}
The code style has been configured in a file .editorconfig
,
which is supported by many IDEs (Visual Studio Code, Visual Studio, Rider, etc.).
Configure your IDE accordingly and follow above conventions.