Skip to content

Instantly share code, notes, and snippets.

@integraldx
Last active October 20, 2024 05:20
Show Gist options
  • Select an option

  • Save integraldx/3a1bc48e8e6ad1ff44e7b315b6c3b0d9 to your computer and use it in GitHub Desktop.

Select an option

Save integraldx/3a1bc48e8e6ad1ff44e7b315b6c3b0d9 to your computer and use it in GitHub Desktop.
Convention guideline for unity3d project

Convention guideline for unity3d project

Script (C#)

Naming

identifier rule
Namespace PascalCase
Class PascalCase
Interface IPascalCase
Type Variable TPascalCase
Enum PascalCase
Struct PascalCase
Public Const PascalCase
Private Const PascalCase
Public Static Property PascalCase
Private Static Property PascalCase
Public Static Field PascalCase
Private Static Field s_camelCase
Public Property PascalCase
Private Property PascalCase
Public Field PascalCase
Private Field _camelCase
Method PascalCase
Event PascalCase
Parameter camelCase
Local Const PascalCase
Local Variable camelCase
Local Method PascalCase

Line Break & Wrapping

Every Line Break is Allman Style

namespace FooNamespace
{
    class BarClass<T> : ExtensionClass where T : new()
    {
        public int SomeSimpleProperty { get; set; }

        public int SomeOtherSimpleProperty => _valueField;

        public int SomeComplexProperty
        {
            get
            {
                // Some body...
            }
        }

        private void SomeMethod()
        {
            if (someCondition)
            {
                _someValue =
                    anyCondition
                        ? option1
                        : option2;
                
                _someCalculation =
                    operand1
                    + operand2
                    + operand3;
            }
        }
    }
}

use of #region keyword

If there is too many methods in component so distinguishing Unity Event methods from other methods, consider using #region Unity Events #endregion Unity Events to mark them.

Under Assets/ directory

Often, third party packages or plugins place their required assets under very top level of Assets/ directory. (e.g. Assets/TextMeshPro/)
So to place Project's own files under Assets/<project name>/ directory is recommended. (e.g. Assets/MySampleProject/Scripts/)

Assets/
├ MyProject/
│ ├ Scripts/
│ ├ Textures/
│ ├ Atlases/
│ ├ Sounds/
│ ...
│
├ SomeCommonToolkit/
├ AddressableAssetSettings/
├ TextMeshPro/
├ Plugins/
└ other-sdk-generated-things-gibberish/ 

General Rule for Directory and Assets

Both PascalCase, without space. Underbar is ok if needed. (e.g. UI_DefaultButton.asset)

Note for "given" assets

In most of the cases, assets that are made outside of unity has their own naming scheme depending of their authors.

If project is already on track and normalizing requires significant changes, follow existing rule for that particular type of assets.

Image files

Original files must be in png format, or equivalent lossless format. If another compression format is needed due to file size, use atlas settings or image import settings instead.

Sound files

Original files must be in .wav format, or equivalent lossless format. But if original sound is too long, (typically bgms over 1 minute) ask sound person for compressed file with acceptable sound quality.
Actual encoding format can vary depending on target platform. Discuss with team for this.

Components, Settings

TextMeshPro

Turn off 'Raycast Target' from TMP default. In the most of the cases, text mesh just doesn't need to be clicked by itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment