While the following standards should be adhered to, should a scenario arise that these standards did not foresee, it is in the judgment of the developer to momentarily ignore them, possibly provide an explanation code comment, and discuss amendments to the standard.
¶ MonoBehaviours
- All MonoBehaviours should have documentation in this confluence space explaining its purpose and the inspector values.
- The root for these documentations is Code Documentation
¶ Inspector
- Components required by a MonoBehaviour that are ensured to be on the same GameObject should be acquired by code, while components required on (grand)child-GameObjects should be assigned through an inspector field, as they may move in the hierarchy during development.
- Keep order of components on a GameObject consistent
- Keep MonoBehaviours at the top of the list, with supporting Components below it. Alternatively, collapse supporting Components.
- Keep in mind that collapsed Components and MonoBehaviours are not displayed in the Scene View.
¶ Scenes
- GameObject names are CamelCase.
- Use empty GameObjects to group level elements.
- Keep parent transforms in mind when moving elements.
- Prevent messes in local positions inside a hierarchy.
¶ Prefabs
- Prefabs have an empty root game object.
- The root of a prefab should have its transform position at
(0,0,0),
a rotation of(0,0,0)
, and a scale of(1,1,1)
. - Do use prefab variants if applicable, but keep a clean and simple structure
- Similar to abstract classes a parent prefab may only exist as a template for more concrete implementations in prefab variants. Such abstract prefabs are prefixed with "A_".
¶ Directory structure
All directory names are CamelCase and contain no spaces.
¶ Project
This chapter contains information about the directory structure of the Unity project in its entirety. The root directory is written as /
in this documentation.
The root contains more directories and files than described here. This section only highlights some and their roles.
- /.idea/ - This folder contains data used by Rider and should be kept in the repository. /.gitignore is properly set up to only commit the necessary files.
- /Assets/ - This folder contains the project assets and is explained in detail further down this page.
- /Packages/ - This folder contains a manifest file of all installed packages but also additional packages developed by the team in tandem with this project.
- /.gitignore - This file specifies which files should not be committed into the repository by git.
- /hats.sln.DotSettings - This file is used by Rider and Resharper to apply most of the code standards in this project. See Code Standards.
- /*.csproj - These files are automatically generated by Unity and contain the different code assemblies used by the project. There may be a substantial amount of these files, increasing with the number of used packages and assemblies defined by the project team.
¶ Assets
This chapter contains information about the directory structure inside the /Assets/
folder.
In general, all files, such as code or sprites are grouped in directories by their type such as:
- Sprites/ - All image files used as sprites inside the game.
- Scripts/ - MonoBehaviour code files
- ScriptableObjects/ - ScriptableObject code files.
Inside these directories, they can be further grouped by functionality or field of responsibility. These subdirectory names should be held consistent across all directories.
Inside /Assets/ there are some fixed directories that are always present:
- _Scenes/ - Containing all scene objects and their generated data.
- Subdirectories are used to group scenes further.
- Editor/ - Editor only code is located in this directory.
- Separate tools have their own subdirectory if they should encompass more than one file.
- Single-file editor code can directly be located in this folder
- Files in this directory may be integrated into the package com.Kataigida.Utility if the author consents.
- Sandbox/ - Experimental code and test scenes
- Each test has it's own subdirectory
- Settings/ - Unity configuration files.
- Ex. URP renderer, quality presets
- Presets/ - Import presets.
- StreamingAssets/ - Streaming assets
- Plugins/ - Third-party tools and assets
- Each tool or asset has its own subdirectory.
- Scripts/Utility - Utility code that is not project-specific but is not "editor-only".
- Files in this directory may be integrated into the package com.Kataigida.Utility if the author consents.
The file /Assets/csc.rsp supresses C# compiler warnings globally and is used to suppress the warning C0649: "The compiler detected an uninitialized private or internal field declaration that is never assigned a value."
This is done to avoid the false-alarm when using private
inspector fields that have no default value. Keep in mind that this will also suppress real warnings about private
fields in the code that have no assigned value my mistake.