Unity3D 컨벤션
네이밍 컨벤션
이 답변과 이 글에 따르면,
- C# 네이밍 컨벤션과는 약간의 차이가 있다.
- 모든 내용에 기본적으로 파스칼 케이스(PascalCase)를 이용한다.
- 타입(클래스, 구조체, Enum)과 메소드(및 함수)는 대문자로 시작한다. (
ClassName
, MethodName
, MyEnum.CaseA
)
- 네임스페이스, static 필드, 속성은 파스칼 케이스를 이용한다. (
Game.Namespace
, public static int StaticValue
, MyProperty { get; set; }
,)
- 속성을 Visual studio 자동 생성을 할 때 대문자로 바뀌는 것으로 보아 이 쪽이 맞는 것 같다.
- 필드와 인스턴스는 카멜 케이스(camelCase)를 이용하므로 소문자로 시작한다. (
myField
, ClassName instance
)
- 파라미터는 카멜 케이스를 이용한다. (
f(bool someCondition)
)
- 대리자에는
Callback
접미사를, 이벤트에는 On
접두사를 붙인다 (public delegate void ProcessUserCallback(User u);
, public UnityAction OnDeath;
)
- 인터페이스에는
I
접두사를 붙인다.
- public field를 그대로 이용하기보다 속성 기능을 활용하고, 만약 인스펙터에 보이는 것만 원한다면
[SerializeField]
속성을 붙이는 방법을 이용한다.
코딩 Best Practice
- 코드를 네임스페이스 내에 넣어서 중복과 오류를 줄이기
Unity.Assertions.Assert()
로 테스트하기
- Invoke, Sendmessage, 기타 String으로 함수 호출하는 함수들 쓰지 않거나 지양하기 (대신 코루틴 이용)
GameObject.Find();
쓰지 말기, GetComponent()
캐싱하기
- index로 접근하는 array/list를 여러 개 쓰기보다, 하나의 array가 클래스들을 담고 있게 만들기
- 커스텀 클래스들을 만들고,
[Serializable]
속성을 이용해 유니티 인스펙터에서 보이게 하기
[Serializable]
public class Weapon
{
public GameObject prefab;
public ParticleSystem particles;
public Bullet bullet;
}
[Serializable]
public class Bullets
{
public Bullet fireBullet;
public Bullet iceBullet;
public Bullet windBullet;
}
*****
긍정적인 영향을 주는 사람이 됩시다
Served using home raspberry pi 3 B+
☕ Pudhina theme by Knhash 🛠️